Skip to content

Commit a17e79c

Browse files
committed
Add test for malformed URI
1 parent 9d3089a commit a17e79c

3 files changed

Lines changed: 14 additions & 2 deletions

File tree

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ const parseUrl = (req) => {
7979
url = decodeURIComponent(req.url).slice(baseChars)
8080
} catch (ex) {
8181
ex.meta = { url: req.url, baseChars }
82-
return { error }
82+
return { error: ex }
8383
}
8484

8585
const sIdx = url.indexOf('/')

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "scrud",
3-
"version": "10.2.1",
3+
"version": "10.2.2",
44
"description": "SCRUD API server, fast, light, capable",
55
"engines": {
66
"node": ">=8.0.0"

test/index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,18 @@ for (const key of Object.keys(config)) {
231231
}
232232
})
233233

234+
test(`${pre}malformed URI returns error`, async (assert) => {
235+
const { port, jwt } = getConfig(key)
236+
const url = `http://localhost:${port}${basePath}/%`
237+
const headers = { Authorization: `Bearer ${jwt}` }
238+
try {
239+
await axios({ method: 'GET', url, headers })
240+
} catch (ex) {
241+
if (!ex.response) throw ex
242+
assert.is(ex.response.data.error, 'URI malformed')
243+
}
244+
})
245+
234246
test(`${pre}bad JSON body returns error`, async (assert) => {
235247
const { port, jwt } = getConfig(key)
236248
const url = `http://localhost:${port}${basePath}/member/${id}`

0 commit comments

Comments
 (0)