Skip to content

Commit 0cbcced

Browse files
line-owindauer
authored andcommitted
fix(restClient): protocol in connectionOptions
The protocol _must_ end with a colon. This lead to the prefixUrl to contain a double colon (`::`), also known as Paamayim Nekudotayim. For the tests with the protocol set to `http:` the other port (8080) is now exposed in the container in the CI test setup.
1 parent 70f4ff3 commit 0cbcced

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

.github/workflows/semantic-release.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ jobs:
2020
image: existdb/existdb:${{ matrix.exist-version }}
2121
ports:
2222
- 8443:8443
23+
- 8080:8080
2324
volumes:
2425
- ${{ github.workspace }}/xquery:/exist/autodeploy
2526
options: >-

components/connection.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const defaultRPCoptions = {
3232

3333
const defaultRestOptions = {
3434
host: 'localhost',
35-
protocol: 'https',
35+
protocol: 'https:',
3636
port: '8443',
3737
path: '/exist/rest',
3838
basic_auth: {
@@ -104,7 +104,7 @@ async function restConnection (options) {
104104

105105
const port = _options.port ? ':' + _options.port : ''
106106
const path = _options.path.startsWith('/') ? _options.path : '/' + _options.path
107-
const prefixUrl = `${_options.protocol}://${_options.host}${port}${path}`
107+
const prefixUrl = `${_options.protocol}//${_options.host}${port}${path}`
108108

109109
const client = got.extend(
110110
{

spec/tests/rest.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,3 +382,33 @@ return $r
382382
unlinkSync('stream-test.xml')
383383
})
384384
})
385+
386+
test.only('with rest client over http', async function (t) {
387+
const modifiedOptions = Object.assign({ protocol: 'http:', port: '8080' }, envOptions)
388+
const rc = await getRestClient(modifiedOptions)
389+
390+
t.test('non-existent file returns 404', async function (st) {
391+
try {
392+
const res = await rc.get('db/rest-test/non-existent.file')
393+
st.fail(res)
394+
st.end()
395+
} catch (e) {
396+
st.equal(e.response.statusCode, 404)
397+
st.end()
398+
}
399+
})
400+
401+
t.test('getting a collection will return the file listing as xml', async function (st) {
402+
try {
403+
const res = await rc.get('db')
404+
st.equal(res.statusCode, 200, 'server responded with status ' + res.statusCode)
405+
406+
const lines = res.body.split('\n')
407+
st.equal(lines[0], '<exist:result xmlns:exist="http://exist.sourceforge.net/NS/exist">')
408+
st.end()
409+
} catch (e) {
410+
st.fail(e)
411+
st.end()
412+
}
413+
})
414+
})

0 commit comments

Comments
 (0)