Skip to content

Commit

Permalink
fix(restClient): protocol in connectionOptions
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
line-o authored and windauer committed Oct 17, 2023
1 parent 70f4ff3 commit 0cbcced
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
1 change: 1 addition & 0 deletions .github/workflows/semantic-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
image: existdb/existdb:${{ matrix.exist-version }}
ports:
- 8443:8443
- 8080:8080
volumes:
- ${{ github.workspace }}/xquery:/exist/autodeploy
options: >-
Expand Down
4 changes: 2 additions & 2 deletions components/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const defaultRPCoptions = {

const defaultRestOptions = {
host: 'localhost',
protocol: 'https',
protocol: 'https:',
port: '8443',
path: '/exist/rest',
basic_auth: {
Expand Down Expand Up @@ -104,7 +104,7 @@ async function restConnection (options) {

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

const client = got.extend(
{
Expand Down
30 changes: 30 additions & 0 deletions spec/tests/rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,3 +382,33 @@ return $r
unlinkSync('stream-test.xml')
})
})

test.only('with rest client over http', async function (t) {
const modifiedOptions = Object.assign({ protocol: 'http:', port: '8080' }, envOptions)
const rc = await getRestClient(modifiedOptions)

t.test('non-existent file returns 404', async function (st) {
try {
const res = await rc.get('db/rest-test/non-existent.file')
st.fail(res)
st.end()
} catch (e) {
st.equal(e.response.statusCode, 404)
st.end()
}
})

t.test('getting a collection will return the file listing as xml', async function (st) {
try {
const res = await rc.get('db')
st.equal(res.statusCode, 200, 'server responded with status ' + res.statusCode)

const lines = res.body.split('\n')
st.equal(lines[0], '<exist:result xmlns:exist="http://exist.sourceforge.net/NS/exist">')
st.end()
} catch (e) {
st.fail(e)
st.end()
}
})
})

0 comments on commit 0cbcced

Please sign in to comment.