Aktueller Stand
This commit is contained in:
72
backend/node_modules/find-my-way/test/regex.test.js
generated
vendored
72
backend/node_modules/find-my-way/test/regex.test.js
generated
vendored
@@ -1,19 +1,18 @@
|
||||
'use strict'
|
||||
|
||||
const t = require('tap')
|
||||
const test = t.test
|
||||
const { test } = require('node:test')
|
||||
const FindMyWay = require('../')
|
||||
|
||||
test('route with matching regex', t => {
|
||||
t.plan(1)
|
||||
const findMyWay = FindMyWay({
|
||||
defaultRoute: () => {
|
||||
t.fail('route not matched')
|
||||
t.assert.fail('route not matched')
|
||||
}
|
||||
})
|
||||
|
||||
findMyWay.on('GET', '/test/:id(^\\d+$)', () => {
|
||||
t.ok('regex match')
|
||||
t.assert.ok('regex match')
|
||||
})
|
||||
|
||||
findMyWay.lookup({ method: 'GET', url: '/test/12', headers: {} }, null)
|
||||
@@ -23,12 +22,12 @@ test('route without matching regex', t => {
|
||||
t.plan(1)
|
||||
const findMyWay = FindMyWay({
|
||||
defaultRoute: () => {
|
||||
t.ok('route not matched')
|
||||
t.assert.ok('route not matched')
|
||||
}
|
||||
})
|
||||
|
||||
findMyWay.on('GET', '/test/:id(^\\d+$)', () => {
|
||||
t.fail('regex match')
|
||||
t.assert.fail('regex match')
|
||||
})
|
||||
|
||||
findMyWay.lookup({ method: 'GET', url: '/test/test', headers: {} }, null)
|
||||
@@ -38,14 +37,14 @@ test('route with an extension regex 2', t => {
|
||||
t.plan(2)
|
||||
const findMyWay = FindMyWay({
|
||||
defaultRoute: (req) => {
|
||||
t.fail(`route not matched: ${req.url}`)
|
||||
t.assert.fail(`route not matched: ${req.url}`)
|
||||
}
|
||||
})
|
||||
findMyWay.on('GET', '/test/S/:file(^\\S+).png', () => {
|
||||
t.ok('regex match')
|
||||
t.assert.ok('regex match')
|
||||
})
|
||||
findMyWay.on('GET', '/test/D/:file(^\\D+).png', () => {
|
||||
t.ok('regex match')
|
||||
t.assert.ok('regex match')
|
||||
})
|
||||
findMyWay.lookup({ method: 'GET', url: '/test/S/foo.png', headers: {} }, null)
|
||||
findMyWay.lookup({ method: 'GET', url: '/test/D/foo.png', headers: {} }, null)
|
||||
@@ -55,12 +54,12 @@ test('nested route with matching regex', t => {
|
||||
t.plan(1)
|
||||
const findMyWay = FindMyWay({
|
||||
defaultRoute: () => {
|
||||
t.fail('route not matched')
|
||||
t.assert.fail('route not matched')
|
||||
}
|
||||
})
|
||||
|
||||
findMyWay.on('GET', '/test/:id(^\\d+$)/hello', () => {
|
||||
t.ok('regex match')
|
||||
t.assert.ok('regex match')
|
||||
})
|
||||
|
||||
findMyWay.lookup({ method: 'GET', url: '/test/12/hello', headers: {} }, null)
|
||||
@@ -70,13 +69,13 @@ test('mixed nested route with matching regex', t => {
|
||||
t.plan(2)
|
||||
const findMyWay = FindMyWay({
|
||||
defaultRoute: () => {
|
||||
t.fail('route not matched')
|
||||
t.assert.fail('route not matched')
|
||||
}
|
||||
})
|
||||
|
||||
findMyWay.on('GET', '/test/:id(^\\d+$)/hello/:world', (req, res, params) => {
|
||||
t.equal(params.id, '12')
|
||||
t.equal(params.world, 'world')
|
||||
t.assert.equal(params.id, '12')
|
||||
t.assert.equal(params.world, 'world')
|
||||
})
|
||||
|
||||
findMyWay.lookup({ method: 'GET', url: '/test/12/hello/world', headers: {} }, null)
|
||||
@@ -86,13 +85,13 @@ test('mixed nested route with double matching regex', t => {
|
||||
t.plan(2)
|
||||
const findMyWay = FindMyWay({
|
||||
defaultRoute: () => {
|
||||
t.fail('route not matched')
|
||||
t.assert.fail('route not matched')
|
||||
}
|
||||
})
|
||||
|
||||
findMyWay.on('GET', '/test/:id(^\\d+$)/hello/:world(^\\d+$)', (req, res, params) => {
|
||||
t.equal(params.id, '12')
|
||||
t.equal(params.world, '15')
|
||||
t.assert.equal(params.id, '12')
|
||||
t.assert.equal(params.world, '15')
|
||||
})
|
||||
|
||||
findMyWay.lookup({ method: 'GET', url: '/test/12/hello/15', headers: {} }, null)
|
||||
@@ -102,12 +101,12 @@ test('mixed nested route without double matching regex', t => {
|
||||
t.plan(1)
|
||||
const findMyWay = FindMyWay({
|
||||
defaultRoute: () => {
|
||||
t.ok('route not matched')
|
||||
t.assert.ok('route not matched')
|
||||
}
|
||||
})
|
||||
|
||||
findMyWay.on('GET', '/test/:id(^\\d+$)/hello/:world(^\\d+$)', (req, res, params) => {
|
||||
t.fail('route mathed')
|
||||
t.assert.fail('route mathed')
|
||||
})
|
||||
|
||||
findMyWay.lookup({ method: 'GET', url: '/test/12/hello/test', headers: {} }, null)
|
||||
@@ -117,12 +116,12 @@ test('route with an extension regex', t => {
|
||||
t.plan(1)
|
||||
const findMyWay = FindMyWay({
|
||||
defaultRoute: () => {
|
||||
t.fail('route not matched')
|
||||
t.assert.fail('route not matched')
|
||||
}
|
||||
})
|
||||
|
||||
findMyWay.on('GET', '/test/:file(^\\d+).png', () => {
|
||||
t.ok('regex match')
|
||||
t.assert.ok('regex match')
|
||||
})
|
||||
|
||||
findMyWay.lookup({ method: 'GET', url: '/test/12.png', headers: {} }, null)
|
||||
@@ -132,12 +131,12 @@ test('route with an extension regex - no match', t => {
|
||||
t.plan(1)
|
||||
const findMyWay = FindMyWay({
|
||||
defaultRoute: () => {
|
||||
t.ok('route not matched')
|
||||
t.assert.ok('route not matched')
|
||||
}
|
||||
})
|
||||
|
||||
findMyWay.on('GET', '/test/:file(^\\d+).png', () => {
|
||||
t.fail('regex match')
|
||||
t.assert.fail('regex match')
|
||||
})
|
||||
|
||||
findMyWay.lookup({ method: 'GET', url: '/test/aa.png', headers: {} }, null)
|
||||
@@ -147,15 +146,15 @@ test('safe decodeURIComponent', t => {
|
||||
t.plan(1)
|
||||
const findMyWay = FindMyWay({
|
||||
defaultRoute: () => {
|
||||
t.ok('route not matched')
|
||||
t.assert.ok('route not matched')
|
||||
}
|
||||
})
|
||||
|
||||
findMyWay.on('GET', '/test/:id(^\\d+$)', () => {
|
||||
t.fail('we should not be here')
|
||||
t.assert.fail('we should not be here')
|
||||
})
|
||||
|
||||
t.same(
|
||||
t.assert.deepEqual(
|
||||
findMyWay.find('GET', '/test/hel%"Flo', {}),
|
||||
null
|
||||
)
|
||||
@@ -191,19 +190,19 @@ test('Should check if a regex is safe to use', t => {
|
||||
good.forEach(regex => {
|
||||
try {
|
||||
findMyWay.on('GET', `/test/:id(${regex.toString()})`, noop)
|
||||
t.pass('ok')
|
||||
t.assert.ok('ok')
|
||||
findMyWay.off('GET', `/test/:id(${regex.toString()})`)
|
||||
} catch (err) {
|
||||
t.fail(err)
|
||||
t.assert.fail(err)
|
||||
}
|
||||
})
|
||||
|
||||
bad.forEach(regex => {
|
||||
try {
|
||||
findMyWay.on('GET', `/test/:id(${regex.toString()})`, noop)
|
||||
t.fail('should throw')
|
||||
t.assert.fail('should throw')
|
||||
} catch (err) {
|
||||
t.ok(err)
|
||||
t.assert.ok(err)
|
||||
}
|
||||
})
|
||||
})
|
||||
@@ -238,31 +237,30 @@ test('Disable safe regex check', t => {
|
||||
good.forEach(regex => {
|
||||
try {
|
||||
findMyWay.on('GET', `/test/:id(${regex.toString()})`, noop)
|
||||
t.pass('ok')
|
||||
t.assert.ok('ok')
|
||||
findMyWay.off('GET', `/test/:id(${regex.toString()})`)
|
||||
} catch (err) {
|
||||
t.fail(err)
|
||||
t.assert.fail(err)
|
||||
}
|
||||
})
|
||||
|
||||
bad.forEach(regex => {
|
||||
try {
|
||||
findMyWay.on('GET', `/test/:id(${regex.toString()})`, noop)
|
||||
t.pass('ok')
|
||||
t.assert.ok('ok')
|
||||
findMyWay.off('GET', `/test/:id(${regex.toString()})`)
|
||||
} catch (err) {
|
||||
t.fail(err)
|
||||
t.assert.fail(err)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
test('prevent back-tracking', (t) => {
|
||||
test('prevent back-tracking', { timeout: 20 }, (t) => {
|
||||
t.plan(0)
|
||||
t.setTimeout(20)
|
||||
|
||||
const findMyWay = FindMyWay({
|
||||
defaultRoute: () => {
|
||||
t.fail('route not matched')
|
||||
t.assert.fail('route not matched')
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user