File tree Expand file tree Collapse file tree 2 files changed +28
-3
lines changed Expand file tree Collapse file tree 2 files changed +28
-3
lines changed Original file line number Diff line number Diff line change @@ -202,9 +202,14 @@ function challengeRequest(operation) {
202
202
operation . logger . debug ( 'response with status %d and %s challenge for %s' ,
203
203
statusCode1 , hasChallenge , challengeOpts . path ) ;
204
204
if ( ( statusCode1 === 401 && hasChallenge ) || ( successStatus && ! isRead ) ) {
205
- operation . authenticator = ( hasChallenge ) ? createAuthenticator (
206
- operation . client , options . user , options . password , challenge
207
- ) : null ;
205
+ try {
206
+ operation . authenticator = ( hasChallenge ) ? createAuthenticator (
207
+ operation . client , options . user , options . password , challenge
208
+ ) : null ;
209
+
210
+ } catch ( error ) {
211
+ request1 . emit ( 'error' , new Error ( 'Authentication failed.' ) ) ;
212
+ }
208
213
authenticatedRequest ( operation ) ;
209
214
// should never happen
210
215
} else if ( successStatus && isRead ) {
Original file line number Diff line number Diff line change @@ -107,4 +107,24 @@ describe('database clients', function() {
107
107
timestamp . value . should . equal ( '123' ) ;
108
108
done ( ) ;
109
109
} ) ;
110
+ it ( 'should throw Error when server expects DIGEST and authType is CERTIFICATE' , function ( done ) {
111
+ const db = marklogic . createDatabaseClient ( {
112
+ host : "localhost" ,
113
+ port : 8015 ,
114
+ authType :'certificate'
115
+ } ) ;
116
+ const query = marklogic . queryBuilder
117
+ . where ( marklogic . ctsQueryBuilder . cts . directoryQuery ( '/optic/test/' ) ) ;
118
+
119
+ db . documents . query ( query )
120
+ . result ( function ( documents ) {
121
+ documents . forEach ( function ( document ) {
122
+ } ) ;
123
+ } )
124
+ . catch ( error => {
125
+ assert ( error . toString ( ) . includes ( 'response with invalid 401 status with path: /v1/search' ) ) ;
126
+ marklogic . releaseClient ( db ) ;
127
+ done ( ) ;
128
+ } ) ;
129
+ } ) ;
110
130
} ) ;
You can’t perform that action at this time.
0 commit comments