v2 auths tests

This commit is contained in:
2023-04-20 11:48:29 +02:00
parent 96dcf2334b
commit 4305eb117a
2 changed files with 42 additions and 4 deletions
+37 -1
View File
@@ -11,7 +11,43 @@ beforeAll(async () => {
})
describe('server', () => {
test('server auth prefetch', async () => {
test('bad auth prefetch', async () => {
const response = await fetch(`http://127.0.0.1:3001/`, {
method: "POST", // *GET, POST, PUT, DELETE, etc.
credentials: "same-origin", // include, *same-origin, omit
headers: {
"Content-Type": "application/json",
'Authorization': `Bearere ${Buffer.from('' + process.env.SERVERAUTH_TOKEN).toString('base64')}`
}
});
expect(response.status).toBe(400)
const response2 = await fetch(`http://127.0.0.1:3001/`, {
method: "POST", // *GET, POST, PUT, DELETE, etc.
credentials: "same-origin", // include, *same-origin, omit
headers: {
"Content-Type": "application/json",
'Authorization': `Bearer ${Buffer.from('badtoken').toString('base64')}`
}
});
expect(response2.status).toBe(403)
})
test('bad kill token', async () => {
const response2 = await fetch(`http://127.0.0.1:3001/kill`, {
method: "POST", // *GET, POST, PUT, DELETE, etc.
credentials: "same-origin", // include, *same-origin, omit
headers: {
"Content-Type": "application/json",
'Authorization': `Bearer ${Buffer.from('badtoken').toString('base64')}`
}
});
expect(response2.status).toBe(403)
})
test('good auth prefetch', async () => {
const response = await fetch(`http://127.0.0.1:3001/`, {
method: "POST", // *GET, POST, PUT, DELETE, etc.
credentials: "same-origin", // include, *same-origin, omit