Skip to content

Commit 33f8c4d

Browse files
line-oduncdrum
authored andcommitted
fix(connection): misleading warning message
When connecting to a remote DB over an encrypted channel users might be greeted with a warning: "Connecting to remote DB allowing invalid certificate." This is misleading in cases where `rejectUnauthorized` is not explicitly set. The added tests will connect to exist-db.org over https. They only check the connection is established and rejected as unauthorized.
1 parent d6f018a commit 33f8c4d

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

components/connection.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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
}

spec/tests/index.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
74100
test('get collection permissions', function (t) {
75101
const db = connect(envOptions)
76102
db.resources.getPermissions('/db')

spec/tests/rest.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff 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+
})

0 commit comments

Comments
 (0)