This commit is contained in:
@ -14,27 +14,35 @@ const client = require ('@sapphirecode/auth-client-helper');
|
||||
const consts = require ('@sapphirecode/consts');
|
||||
const fetch = require ('node-fetch');
|
||||
|
||||
let port = 0;
|
||||
|
||||
test.before (async () => {
|
||||
await mock_server.start_server ();
|
||||
port = await mock_server.start_server ();
|
||||
});
|
||||
|
||||
test ('login', async (t) => {
|
||||
test.only ('login', async (t) => {
|
||||
console.log ('logging in');
|
||||
console.log ('port:', port);
|
||||
const session = await client.login (
|
||||
'testuser',
|
||||
'foo',
|
||||
'http://localhost:3000'
|
||||
`http://localhost:${port}`
|
||||
);
|
||||
|
||||
console.log ('server respond');
|
||||
t.is (typeof session, 'string');
|
||||
|
||||
const resp = await fetch ('http://localhost:3000', { headers: { session } });
|
||||
const resp = await fetch (
|
||||
`http://localhost:${port}`,
|
||||
{ headers: { session } }
|
||||
);
|
||||
|
||||
t.is (resp.status, consts.http.status_ok);
|
||||
t.is (await resp.text (), 'foo:69');
|
||||
console.log ('done test');
|
||||
});
|
||||
|
||||
test ('allow access to excluded paths', async (t) => {
|
||||
const resp = await fetch ('http://localhost:3000/noauthreg');
|
||||
const resp = await fetch (`http://localhost:${port}/noauthreg`);
|
||||
|
||||
t.is (resp.status, consts.http.status_ok);
|
||||
t.is (await resp.text (), 'foo:undefined');
|
||||
@ -42,7 +50,7 @@ test ('allow access to excluded paths', async (t) => {
|
||||
|
||||
test ('allow access to excluded paths with correct method', async (t) => {
|
||||
const resp = await fetch (
|
||||
'http://localhost:3000/noauthobj',
|
||||
`http://localhost:${port}/noauthobj`,
|
||||
{ method: 'POST' }
|
||||
);
|
||||
|
||||
@ -52,7 +60,7 @@ test ('allow access to excluded paths with correct method', async (t) => {
|
||||
|
||||
test ('reject access to excluded paths with wrong method', async (t) => {
|
||||
const resp = await fetch (
|
||||
'http://localhost:3000/noauthobj'
|
||||
`http://localhost:${port}/noauthobj`
|
||||
);
|
||||
|
||||
t.is (resp.status, consts.http.status_unauthorized);
|
||||
@ -62,7 +70,7 @@ test ('reject invalid user', async (t) => {
|
||||
await t.throwsAsync (client.login (
|
||||
'foo',
|
||||
'foo',
|
||||
'http://localhost:3000'
|
||||
`http://localhost:${port}`
|
||||
));
|
||||
});
|
||||
|
||||
@ -70,6 +78,6 @@ test ('reject invalid password', async (t) => {
|
||||
await t.throwsAsync (client.login (
|
||||
'testuser',
|
||||
'bar',
|
||||
'http://localhost:3000'
|
||||
`http://localhost:${port}`
|
||||
));
|
||||
});
|
||||
|
Reference in New Issue
Block a user