smartid-calls
Version:
Smart-ID client module for Node.JS with proxy layer
186 lines (151 loc) • 5.6 kB
text/typescript
import { expect } from 'chai';
import SmartID from '../index';
import AuthHash from '../authhash';
import { ModuleConfigI } from 'types/Request';
describe('SmartID test', () => {
let smartauth: SmartID;
let config: ModuleConfigI;
before(async () => {
config = {
algorithm: 'SHA256',
host: 'https://sid.demo.sk.ee/smart-id-rp/v1',
requestParams: {
relyingPartyUUID: '00000000-0000-0000-0000-000000000000',
relyingPartyName: 'DEMO',
}
}
smartauth = new SmartID(config);
});
describe('authenticate and get session information', async () => {
let sessionId: string;
let authHash: string;
beforeEach(async () => {
const persNr = '010101-10006';
const country = 'LV';
const resp = await smartauth.authenticate(country, persNr, 'Testing');
sessionId = resp.sessionId;
authHash = resp.authHash;
expect(resp).to.have.property('sessionId');
expect(resp).to.have.property('verificationCode');
expect(resp).to.have.property('authHash');
});
it('should authenticate and get session information', async () => {
const resp = await smartauth.getSession(sessionId);
expect(resp).to.have.property('data');
expect(resp).to.have.property('result');
expect(resp).to.have.property('all');
const verification = await smartauth.verifyRequest(sessionId, resp.all, authHash);
expect(verification).to.eq(true);
}).timeout(30000);
});
describe('request signing cert by document number', async () => {
let sessionId: string;
beforeEach(async () => {
const docNr = 'PNOLV-010101-10006-SGT7-Q';
const resp = await smartauth.getSigningCert(docNr);
sessionId = resp.sessionId;
expect(resp).to.have.property('sessionId');
});
it('should retrieve cert for signing', async () => {
const resp = await smartauth.getSession(sessionId);
expect(resp).to.have.property('data');
expect(resp).to.have.property('result');
expect(resp).to.have.property('all');
});
});
describe('request signing cert by personal number', async () => {
let sessionId: string;
beforeEach(async () => {
const persNr = '010101-10006';
const country = 'LV';
const resp = await smartauth.getSigningCert({
country: country,
personalNumber: persNr,
});
sessionId = resp.sessionId;
expect(resp).to.have.property('sessionId');
});
it('should retrieve cert for signing', async () => {
const resp = await smartauth.getSession(sessionId);
expect(resp).to.have.property('data');
expect(resp).to.have.property('result');
expect(resp).to.have.property('all');
});
});
describe('sign digest', async () => {
let sessionId: string;
beforeEach(async () => {
const docNr = 'PNOLV-010101-10006-SGT7-Q';
const digest = await AuthHash.generateRandomHash(config.algorithm);
const text = 'Testing the signing';
const resp = await smartauth.sign(docNr, digest.digest, text);
sessionId = resp.sessionId;
expect(resp).to.have.property('verificationCode');
expect(resp).to.have.property('sessionId');
});
it('should sign the provided digest', async () => {
const resp = await smartauth.getSession(sessionId);
expect(resp).to.have.property('data');
expect(resp).to.have.property('result');
expect(resp).to.have.property('all');
}).timeout(30000);
});
describe('user refused auth', async () => {
let sessionId: string;
let authHash: string;
beforeEach(async () => {
const persNr = '10101010016';
const country = 'EE';
const resp = await smartauth.authenticate(country, persNr, 'Testing');
sessionId = resp.sessionId;
authHash = resp.authHash;
expect(resp).to.have.property('sessionId');
expect(resp).to.have.property('verificationCode');
expect(resp).to.have.property('authHash');
});
it('should not authenticate since user refused', async () => {
try {
const resp = await smartauth.getSession(sessionId);
expect(resp).to.eq(null);
} catch (error) {
expect(error.message).to.eq('USER_REFUSED');
}
}).timeout(30000);
});
describe('user refused signing', async () => {
let sessionId: string;
let authHash: string;
beforeEach(async () => {
const docNr = 'PNOEE-10101010016-9RF6-Q';
const digest = await AuthHash.generateRandomHash(config.algorithm);
const text = 'Testing the signing';
const resp = await smartauth.sign(docNr, digest.digest, text);
sessionId = resp.sessionId;
expect(resp).to.have.property('verificationCode');
expect(resp).to.have.property('sessionId');
});
it('should have user refused signing', async () => {
try {
const resp = await smartauth.getSession(sessionId);
expect(resp).to.eq(null);
} catch (error) {
expect(error.message).to.eq('USER_REFUSED');
}
}).timeout(30000);
});
describe('user doesnt have valid certificates', async () => {
it('should have user refused signing', async () => {
const persNr = '10101020001';
const country = 'LT';
try {
const resp = await smartauth.getSigningCert({
country: country,
personalNumber: persNr,
});
expect(resp).to.not.have.property('sessionId');
} catch (error) {
expect(error.message).to.eq('NO_CERTS');
}
}).timeout(30000);
});
});