This commit is contained in:
parent
507c0ceba3
commit
c40e6c19ea
@ -45,9 +45,11 @@ async function start_server () {
|
|||||||
.end (`foo:${res.connection.user_id}`);
|
.end (`foo:${res.connection.user_id}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
app.listen (3000);
|
return new Promise ((res) => {
|
||||||
|
const listener = app.listen (0, () => {
|
||||||
return app;
|
res (listener.address ().port);
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { start_server };
|
module.exports = { start_server };
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
"@sapphirecode/eslint-config": "^2.1.4",
|
"@sapphirecode/eslint-config": "^2.1.4",
|
||||||
"@stryker-mutator/core": "^3.2.3",
|
"@stryker-mutator/core": "^3.2.3",
|
||||||
"@stryker-mutator/javascript-mutator": "^3.2.3",
|
"@stryker-mutator/javascript-mutator": "^3.2.3",
|
||||||
"ava": "^3.8.2",
|
"ava": "^3.10.1",
|
||||||
"eslint": "^7.0.0",
|
"eslint": "^7.0.0",
|
||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
"node-fetch": "^2.6.0",
|
"node-fetch": "^2.6.0",
|
||||||
@ -28,11 +28,11 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@sapphirecode/consts": "^1.1.18",
|
"@sapphirecode/consts": "^1.1.18",
|
||||||
"@sapphirecode/password-helper": "^1.0.35",
|
"@sapphirecode/crypto-helper": "^1.1.44",
|
||||||
"@sapphirecode/crypto-helper": "^1.1.44"
|
"@sapphirecode/password-helper": "^1.0.35"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"LICENSE",
|
"LICENSE",
|
||||||
"index.js"
|
"index.js"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -14,27 +14,35 @@ const client = require ('@sapphirecode/auth-client-helper');
|
|||||||
const consts = require ('@sapphirecode/consts');
|
const consts = require ('@sapphirecode/consts');
|
||||||
const fetch = require ('node-fetch');
|
const fetch = require ('node-fetch');
|
||||||
|
|
||||||
|
let port = 0;
|
||||||
|
|
||||||
test.before (async () => {
|
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 (
|
const session = await client.login (
|
||||||
'testuser',
|
'testuser',
|
||||||
'foo',
|
'foo',
|
||||||
'http://localhost:3000'
|
`http://localhost:${port}`
|
||||||
);
|
);
|
||||||
|
console.log ('server respond');
|
||||||
t.is (typeof session, 'string');
|
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 (resp.status, consts.http.status_ok);
|
||||||
t.is (await resp.text (), 'foo:69');
|
t.is (await resp.text (), 'foo:69');
|
||||||
|
console.log ('done test');
|
||||||
});
|
});
|
||||||
|
|
||||||
test ('allow access to excluded paths', async (t) => {
|
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 (resp.status, consts.http.status_ok);
|
||||||
t.is (await resp.text (), 'foo:undefined');
|
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) => {
|
test ('allow access to excluded paths with correct method', async (t) => {
|
||||||
const resp = await fetch (
|
const resp = await fetch (
|
||||||
'http://localhost:3000/noauthobj',
|
`http://localhost:${port}/noauthobj`,
|
||||||
{ method: 'POST' }
|
{ 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) => {
|
test ('reject access to excluded paths with wrong method', async (t) => {
|
||||||
const resp = await fetch (
|
const resp = await fetch (
|
||||||
'http://localhost:3000/noauthobj'
|
`http://localhost:${port}/noauthobj`
|
||||||
);
|
);
|
||||||
|
|
||||||
t.is (resp.status, consts.http.status_unauthorized);
|
t.is (resp.status, consts.http.status_unauthorized);
|
||||||
@ -62,7 +70,7 @@ test ('reject invalid user', async (t) => {
|
|||||||
await t.throwsAsync (client.login (
|
await t.throwsAsync (client.login (
|
||||||
'foo',
|
'foo',
|
||||||
'foo',
|
'foo',
|
||||||
'http://localhost:3000'
|
`http://localhost:${port}`
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -70,6 +78,6 @@ test ('reject invalid password', async (t) => {
|
|||||||
await t.throwsAsync (client.login (
|
await t.throwsAsync (client.login (
|
||||||
'testuser',
|
'testuser',
|
||||||
'bar',
|
'bar',
|
||||||
'http://localhost:3000'
|
`http://localhost:${port}`
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
|
@ -592,7 +592,7 @@ astral-regex@^2.0.0:
|
|||||||
resolved "https://registry.yarnpkg.com/astral-regex/-/astral-regex-2.0.0.tgz#483143c567aeed4785759c0865786dc77d7d2e31"
|
resolved "https://registry.yarnpkg.com/astral-regex/-/astral-regex-2.0.0.tgz#483143c567aeed4785759c0865786dc77d7d2e31"
|
||||||
integrity sha512-Z7tMw1ytTXt5jqMcOP+OQteU1VuNK9Y02uuJtKQ1Sv69jXQKKg5cibLwGJow8yzZP+eAc18EmLGPal0bp36rvQ==
|
integrity sha512-Z7tMw1ytTXt5jqMcOP+OQteU1VuNK9Y02uuJtKQ1Sv69jXQKKg5cibLwGJow8yzZP+eAc18EmLGPal0bp36rvQ==
|
||||||
|
|
||||||
ava@^3.8.2:
|
ava@^3.10.1:
|
||||||
version "3.10.1"
|
version "3.10.1"
|
||||||
resolved "https://registry.yarnpkg.com/ava/-/ava-3.10.1.tgz#a4e68b1a2bb248fa0d96529d23dd83f57082e944"
|
resolved "https://registry.yarnpkg.com/ava/-/ava-3.10.1.tgz#a4e68b1a2bb248fa0d96529d23dd83f57082e944"
|
||||||
integrity sha512-+w86ZHyFHIGCABi7NUrn/WJMyC+fDj0BSIlFNVS45WDKAD5vxbIiDWeclctxOOc2KDPfQD7tFOURSBz0FBLD0A==
|
integrity sha512-+w86ZHyFHIGCABi7NUrn/WJMyC+fDj0BSIlFNVS45WDKAD5vxbIiDWeclctxOOc2KDPfQD7tFOURSBz0FBLD0A==
|
||||||
|
Loading…
x
Reference in New Issue
Block a user