This commit is contained in:
parent
3d93b0cd9a
commit
b54068954c
12
jasmine.json
Normal file
12
jasmine.json
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
|
||||||
|
{
|
||||||
|
"spec_dir": "test",
|
||||||
|
"spec_files": [
|
||||||
|
"spec/*.js"
|
||||||
|
],
|
||||||
|
"helpers": [
|
||||||
|
"helpers/*.js"
|
||||||
|
],
|
||||||
|
"stopSpecOnExpectationFailure": false,
|
||||||
|
"random": false
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@sapphirecode/auth-client-helper",
|
"name": "@sapphirecode/auth-client-helper",
|
||||||
"version": "1.1.1",
|
"version": "1.1.2",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"author": {
|
"author": {
|
||||||
"name": "Timo Hocker",
|
"name": "Timo Hocker",
|
||||||
@ -17,13 +17,14 @@
|
|||||||
"@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",
|
"@types/jasmine": "^3.5.14",
|
||||||
|
"jasmine": "^3.6.1",
|
||||||
"eslint": "^7.0.0",
|
"eslint": "^7.0.0",
|
||||||
"nyc": "^15.0.1"
|
"nyc": "^15.0.1"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"lint": "eslint . --ext .js,.jsx,.ts,.tsx,.vue,.mjs",
|
"lint": "eslint . --ext .js,.jsx,.ts,.tsx,.vue,.mjs",
|
||||||
"test": "nyc ava",
|
"test": "nyc jasmine --config=\"jasmine.json\"",
|
||||||
"mutate": "stryker run",
|
"mutate": "stryker run",
|
||||||
"compile": "tsc --allowJs --declaration --emitDeclarationOnly index.js"
|
"compile": "tsc --allowJs --declaration --emitDeclarationOnly index.js"
|
||||||
},
|
},
|
||||||
|
@ -1,57 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) Sapphirecode - All Rights Reserved
|
|
||||||
* This file is part of auth-client-helper which is released under MIT.
|
|
||||||
* See file 'LICENSE' for full license details.
|
|
||||||
* Created by Timo Hocker <timo@scode.ovh>, May 2020
|
|
||||||
*/
|
|
||||||
|
|
||||||
// @ts-nocheck
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
const test = require ('ava');
|
|
||||||
const http = require ('http');
|
|
||||||
const client = require ('../index');
|
|
||||||
const consts = require ('@sapphirecode/consts');
|
|
||||||
|
|
||||||
|
|
||||||
test.before (() => {
|
|
||||||
http.createServer ((req, res) => {
|
|
||||||
let str = '';
|
|
||||||
if (req.headers.user)
|
|
||||||
str += req.headers.user;
|
|
||||||
if (req.headers.key)
|
|
||||||
str += req.headers.key;
|
|
||||||
res.writeHead (
|
|
||||||
req.headers.user === 'fail'
|
|
||||||
// eslint-disable-next-line max-len
|
|
||||||
|| req.headers.key === '73192367f6dde83a7e3c0bb412dff8e1b7dfbdb5e5010f00057f317b8eab68e8e448528303142c1455dfe72e062bb2e48f07441b38c7b65329ba7e5acbea6126'
|
|
||||||
? consts.http.status_forbidden
|
|
||||||
: consts.http.status_ok
|
|
||||||
);
|
|
||||||
res.end (str);
|
|
||||||
})
|
|
||||||
// eslint-disable-next-line no-magic-numbers
|
|
||||||
.listen (3000);
|
|
||||||
});
|
|
||||||
|
|
||||||
test ('send request', async (t) => {
|
|
||||||
const session = await client.login ('foo', 'bar', 'http://localhost:3000');
|
|
||||||
|
|
||||||
t.is (
|
|
||||||
session,
|
|
||||||
// eslint-disable-next-line max-len
|
|
||||||
'foo39082c11afda7a927fe4e23c5ba81b64186c33f7e58adf492be5a5c64ddc9db459e0778d573000a5ebaeeae902b6c8641198406b58bf9c53ce48ecdef73a33d1'
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test ('fail salt', async (t) => {
|
|
||||||
await t.throwsAsync (
|
|
||||||
client.login ('fail', 'bar', 'http://localhost:3000')
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test ('fail password', async (t) => {
|
|
||||||
await t.throwsAsync (
|
|
||||||
client.login ('foo', 'fail', 'http://localhost:3000')
|
|
||||||
);
|
|
||||||
});
|
|
62
test/spec/index.js
Normal file
62
test/spec/index.js
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) Sapphirecode - All Rights Reserved
|
||||||
|
* This file is part of auth-client-helper which is released under MIT.
|
||||||
|
* See file 'LICENSE' for full license details.
|
||||||
|
* Created by Timo Hocker <timo@scode.ovh>, May 2020
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* eslint-disable no-undef */
|
||||||
|
// @ts-nocheck
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const http = require ('http');
|
||||||
|
const client = require ('../../index');
|
||||||
|
const consts = require ('@sapphirecode/consts');
|
||||||
|
|
||||||
|
describe ('client helper', () => {
|
||||||
|
beforeAll (() => {
|
||||||
|
http.createServer ((req, res) => {
|
||||||
|
let str = '';
|
||||||
|
if (req.headers.user)
|
||||||
|
str += req.headers.user;
|
||||||
|
if (req.headers.key)
|
||||||
|
str += req.headers.key;
|
||||||
|
res.writeHead (
|
||||||
|
req.headers.user === 'fail'
|
||||||
|
// eslint-disable-next-line max-len
|
||||||
|
|| req.headers.key === '73192367f6dde83a7e3c0bb412dff8e1b7dfbdb5e5010f00057f317b8eab68e8e448528303142c1455dfe72e062bb2e48f07441b38c7b65329ba7e5acbea6126'
|
||||||
|
? consts.http.status_forbidden
|
||||||
|
: consts.http.status_ok
|
||||||
|
);
|
||||||
|
res.end (str);
|
||||||
|
})
|
||||||
|
// eslint-disable-next-line no-magic-numbers
|
||||||
|
.listen (3000);
|
||||||
|
});
|
||||||
|
|
||||||
|
it ('should send request', async () => {
|
||||||
|
const session = await client.login ('foo', 'bar', 'http://localhost:3000');
|
||||||
|
|
||||||
|
expect (
|
||||||
|
session
|
||||||
|
)
|
||||||
|
.toEqual (
|
||||||
|
// eslint-disable-next-line max-len
|
||||||
|
'foo39082c11afda7a927fe4e23c5ba81b64186c33f7e58adf492be5a5c64ddc9db459e0778d573000a5ebaeeae902b6c8641198406b58bf9c53ce48ecdef73a33d1'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it ('should fail salt', async () => {
|
||||||
|
await expectAsync (
|
||||||
|
client.login ('fail', 'bar', 'http://localhost:3000')
|
||||||
|
)
|
||||||
|
.toBeRejectedWithError ('user or password invalid');
|
||||||
|
});
|
||||||
|
|
||||||
|
it ('should fail password', async () => {
|
||||||
|
await expectAsync (
|
||||||
|
client.login ('foo', 'fail', 'http://localhost:3000')
|
||||||
|
)
|
||||||
|
.toBeRejectedWithError ('user or password invalid');
|
||||||
|
});
|
||||||
|
});
|
Reference in New Issue
Block a user