File tree Expand file tree Collapse file tree 3 files changed +57
-1
lines changed Expand file tree Collapse file tree 3 files changed +57
-1
lines changed Original file line number Diff line number Diff line change @@ -138,7 +138,7 @@ function mergeOptions (path, options) {
138138 if ( ! isSecureClient ) {
139139 console . warn ( 'Connecting to remote DB using an unencrypted channel.' )
140140 }
141- if ( ! mergedOptions . rejectUnauthorized ) {
141+ if ( ( 'rejectUnauthorized' in mergedOptions ) && ! mergedOptions . rejectUnauthorized ) {
142142 console . warn ( 'Connecting to remote DB allowing invalid certificate.' )
143143 }
144144 }
Original file line number Diff line number Diff line change @@ -71,6 +71,32 @@ test('create insecure client using legacy option', function (t) {
7171 t . end ( )
7272} )
7373
74+ test ( 'create secure client to remote db' , function ( t ) {
75+ const host = 'exist-db.org'
76+ const protocol = 'https:'
77+ const remoteDb = port => connect ( { host, protocol, port } )
78+ const check = async function ( db , st ) {
79+ st . equal ( db . client . isSecure , true , 'secure client used' )
80+
81+ try {
82+ const result = await db . resources . describe ( '/db' )
83+ st . fail ( result , result )
84+ } catch ( e ) {
85+ st . equal ( e . message , 'XML-RPC fault: Wrong password for user [guest] ' , e )
86+ }
87+
88+ st . end ( )
89+ }
90+
91+ t . test ( 'using standard port' , async function ( st ) {
92+ await check ( remoteDb ( '443' ) , st )
93+ } )
94+
95+ t . test ( 'using empty port' , async function ( st ) {
96+ await check ( remoteDb ( '' ) , st )
97+ } )
98+ } )
99+
74100test ( 'get collection permissions' , function ( t ) {
75101 const db = connect ( envOptions )
76102 db . resources . getPermissions ( '/db' )
Original file line number Diff line number Diff line change @@ -412,3 +412,33 @@ test('with rest client over http', async function (t) {
412412 }
413413 } )
414414} )
415+
416+ test ( 'with rest client connecting to exist-db.org as guest with standard port' , async function ( t ) {
417+ const rc = await getRestClient ( { host : 'exist-db.org' , port : 443 } )
418+
419+ t . test ( 'getting a collection listing is rejected as unauthorized' , async function ( st ) {
420+ try {
421+ const res = await rc . get ( 'db' )
422+ st . fail ( res )
423+ } catch ( e ) {
424+ st . equal ( e . response . statusCode , 401 )
425+ }
426+ st . end ( )
427+ } )
428+ } )
429+
430+ test ( 'with rest client connecting to exist-db.org from URL' , async function ( t ) {
431+ const { protocol, hostname, port } = new URL ( 'https://exist-db.org/' )
432+ // NOTE: that host is mapped to hostname
433+ const rc = await getRestClient ( { protocol, host : hostname , port } )
434+
435+ t . test ( 'getting a collection listing is rejected as unauthorized' , async function ( st ) {
436+ try {
437+ const res = await rc . get ( 'db' )
438+ st . fail ( res )
439+ } catch ( e ) {
440+ st . equal ( e . response . statusCode , 401 )
441+ }
442+ st . end ( )
443+ } )
444+ } )
You can’t perform that action at this time.
0 commit comments