2019-02-22 23:48:01 +00:00
|
|
|
import { expect, tap } from '@pushrocks/tapbundle';
|
2019-02-22 23:50:21 +00:00
|
|
|
import * as smartjwt from '../ts/index';
|
2019-02-22 23:48:01 +00:00
|
|
|
|
2019-10-01 16:04:43 +00:00
|
|
|
let smartjwtInstance: smartjwt.SmartJwt;
|
2019-10-01 17:07:59 +00:00
|
|
|
let testJwt: string;
|
2019-10-01 16:04:43 +00:00
|
|
|
|
|
|
|
tap.test('should create a valid instance', async () => {
|
|
|
|
smartjwtInstance = new smartjwt.SmartJwt();
|
|
|
|
await smartjwtInstance.createNewKeyPair();
|
|
|
|
console.log(smartjwtInstance);
|
|
|
|
});
|
|
|
|
|
|
|
|
tap.test('should create a valid jwt', async () => {
|
2019-10-01 17:07:59 +00:00
|
|
|
await smartjwtInstance.createNewKeyPair();
|
|
|
|
});
|
|
|
|
|
|
|
|
tap.test('should create a new jwt', async () => {
|
2019-10-01 17:22:02 +00:00
|
|
|
testJwt = await smartjwtInstance.createJWT({ hi: 'there' });
|
2019-10-01 17:07:59 +00:00
|
|
|
console.log(testJwt);
|
2019-02-22 23:50:21 +00:00
|
|
|
});
|
2019-02-22 23:48:01 +00:00
|
|
|
|
2019-10-01 17:07:59 +00:00
|
|
|
tap.test('should verify a jwt', async () => {
|
|
|
|
const data = await smartjwtInstance.verifyJWTAndGetData(testJwt);
|
|
|
|
console.log(data);
|
|
|
|
});
|
|
|
|
|
2019-10-01 17:22:02 +00:00
|
|
|
tap.test('should not verify a wrong jwt', async () => {
|
|
|
|
const jwt2 = await smartjwtInstance.createJWT({ wow: 'soclear' });
|
|
|
|
const jwt2Array = jwt2.split('.');
|
|
|
|
const testJwtArray = testJwt.split('.');
|
|
|
|
const newJwt = `${testJwtArray[0]}.${jwt2Array[1]}.${testJwtArray[2]}`;
|
|
|
|
let error: Error;
|
|
|
|
try {
|
|
|
|
await smartjwtInstance.verifyJWTAndGetData(newJwt);
|
|
|
|
} catch (e) {
|
|
|
|
error = e;
|
|
|
|
}
|
|
|
|
expect(error).to.be.instanceOf(Error);
|
|
|
|
});
|
2019-10-01 17:07:59 +00:00
|
|
|
|
2019-02-22 23:50:21 +00:00
|
|
|
tap.start();
|