Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(connection): misleading warning message #315

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion components/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ function mergeOptions (path, options) {
if (!isSecureClient) {
console.warn('Connecting to remote DB using an unencrypted channel.')
}
if (!mergedOptions.rejectUnauthorized) {
if (('rejectUnauthorized' in mergedOptions) && !mergedOptions.rejectUnauthorized) {
console.warn('Connecting to remote DB allowing invalid certificate.')
}
}
Expand Down
26 changes: 26 additions & 0 deletions spec/tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,32 @@ test('create insecure client using legacy option', function (t) {
t.end()
})

test('create secure client to remote db', function (t) {
const host = 'exist-db.org'
const protocol = 'https:'
const remoteDb = port => connect({ host, protocol, port })
const check = async function (db, st) {
st.equal(db.client.isSecure, true, 'secure client used')

try {
const result = await db.resources.describe('/db')
st.fail(result, result)
} catch (e) {
st.equal(e.message, 'XML-RPC fault: Wrong password for user [guest] ', e)
}

st.end()
}

t.test('using standard port', async function (st) {
await check(remoteDb('443'), st)
})

t.test('using empty port', async function (st) {
await check(remoteDb(''), st)
})
})

test('get collection permissions', function (t) {
const db = connect(envOptions)
db.resources.getPermissions('/db')
Expand Down
30 changes: 30 additions & 0 deletions spec/tests/rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,3 +412,33 @@ test('with rest client over http', async function (t) {
}
})
})

test('with rest client connecting to exist-db.org as guest with standard port', async function (t) {
const rc = await getRestClient({ host: 'exist-db.org', port: 443 })

t.test('getting a collection listing is rejected as unauthorized', async function (st) {
try {
const res = await rc.get('db')
st.fail(res)
} catch (e) {
st.equal(e.response.statusCode, 401)
}
st.end()
})
})

test('with rest client connecting to exist-db.org from URL', async function (t) {
const { protocol, hostname, port } = new URL('https://exist-db.org/')
// NOTE: that host is mapped to hostname
const rc = await getRestClient({ protocol, host: hostname, port })

t.test('getting a collection listing is rejected as unauthorized', async function (st) {
try {
const res = await rc.get('db')
st.fail(res)
} catch (e) {
st.equal(e.response.statusCode, 401)
}
st.end()
})
})
Loading