2022-06-23 22:58:52 +00:00
|
|
|
import fetch from 'node-fetch-native'
|
2019-09-05 15:15:27 +00:00
|
|
|
import { getPort, loadFixture, Nuxt, rp } from '../utils'
|
2019-03-20 16:46:09 +00:00
|
|
|
|
|
|
|
let port
|
2023-10-16 21:23:38 +00:00
|
|
|
const url = route => 'http://127.0.0.1:' + port + encodeURI(route)
|
2019-03-20 16:46:09 +00:00
|
|
|
|
|
|
|
let nuxt = null
|
|
|
|
|
2020-11-30 22:10:02 +00:00
|
|
|
describe('encoding', () => {
|
2019-03-20 16:46:09 +00:00
|
|
|
beforeAll(async () => {
|
2020-11-30 22:10:02 +00:00
|
|
|
const config = await loadFixture('encoding')
|
2019-03-20 16:46:09 +00:00
|
|
|
nuxt = new Nuxt(config)
|
|
|
|
await nuxt.ready()
|
|
|
|
|
|
|
|
port = await getPort()
|
2023-10-16 21:23:38 +00:00
|
|
|
await nuxt.server.listen(port, '127.0.0.1')
|
2019-03-20 16:46:09 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
test('/ö/ (router base)', async () => {
|
2019-12-02 15:23:56 +00:00
|
|
|
const { body: response } = await rp(url('/ö/'))
|
2019-03-20 16:46:09 +00:00
|
|
|
|
2020-11-30 22:10:02 +00:00
|
|
|
expect(response).toContain('Unicode base works!')
|
2019-03-20 16:46:09 +00:00
|
|
|
})
|
|
|
|
|
2020-12-06 17:32:39 +00:00
|
|
|
test('/ö/dynamic?q=food,coffee (encodeURIComponent)', async () => {
|
2021-02-04 18:52:13 +00:00
|
|
|
const { body: response } = await rp(url('/ö/dynamic?q=food,coffee'))
|
2020-12-06 17:32:39 +00:00
|
|
|
|
|
|
|
expect(response).toContain('food,coffee')
|
|
|
|
})
|
|
|
|
|
|
|
|
test('/ö/@about', async () => {
|
|
|
|
const { body: response } = await rp(url('/ö/@about'))
|
|
|
|
|
|
|
|
expect(response).toContain('About')
|
|
|
|
})
|
|
|
|
|
2021-02-04 18:52:13 +00:00
|
|
|
test('query params', async () => {
|
|
|
|
const queryStrings = {
|
|
|
|
'?email=some%20email.com': { email: 'some email.com' },
|
|
|
|
'?str=%26&str2=%2526': { str: '&', str2: '%26' },
|
|
|
|
'?t=coffee%2Cfood%2C': { t: 'coffee,food,' },
|
|
|
|
'?redirect=%2Fhomologation%2Flist': { redirect: '/homologation/list' },
|
|
|
|
'?email=some@email.com&token=DvtiwbIzry319e6KWimopA%3D%3D': {
|
|
|
|
email: 'some@email.com',
|
|
|
|
token: 'DvtiwbIzry319e6KWimopA=='
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (const [param, result] of Object.entries(queryStrings)) {
|
|
|
|
const { body: response } = await rp(url('/ö/dynamic/test') + param)
|
|
|
|
expect(response).toContain(
|
|
|
|
JSON.stringify(result)
|
|
|
|
.replace(/&/g, '&')
|
|
|
|
.replace(/"/g, '"')
|
|
|
|
)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
test('invalidly encoded route params are handled', async () => {
|
|
|
|
const paths = ['%c1%81', '%c1', '%']
|
|
|
|
for (const path of paths) {
|
|
|
|
// We use node-fetch because got uses decodeURI on url and throws its own error
|
|
|
|
const response = await fetch(url('/ö/dynamic/') + path)
|
|
|
|
expect(response.ok).toBeTruthy()
|
|
|
|
expect(await response.text()).toContain(
|
|
|
|
JSON.stringify({ id: path })
|
|
|
|
.replace(/&/g, '&')
|
|
|
|
.replace(/"/g, '"')
|
|
|
|
)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2019-03-20 16:46:09 +00:00
|
|
|
// Close server and ask nuxt to stop listening to file changes
|
|
|
|
afterAll(async () => {
|
|
|
|
await nuxt.close()
|
|
|
|
})
|
|
|
|
})
|