Skip to content

Commit

Permalink
Extract dateRegex tests to separate file.
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitrizagidulin committed Mar 18, 2021
1 parent 14da26b commit ebcf94b
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 29 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
"babel-loader": "^8.2.2",
"chai": "^4.3.3",
"cross-env": "^7.0.3",
"crypto-ld": "^5.0.0",
"did-context": "^2.0.0",
"did-veres-one": "^13.0.0",
"eslint": "^7.21.0",
Expand Down Expand Up @@ -93,7 +92,7 @@
"prepublish": "npm run build && npm run ts:defs",
"build": "webpack",
"test": "npm run lint && npm run test-node && npm run test-karma",
"test-node": "cross-env NODE_ENV=test mocha --preserve-symlinks -t 10000 test/*.spec.js",
"test-node": "cross-env NODE_ENV=test mocha -b --preserve-symlinks -t 10000 test/*.spec.js",
"test-karma": "karma start karma.conf.js",
"lint": "eslint lib test/*.spec.js",
"coverage": "cross-env NODE_ENV=test nyc --reporter=lcov --reporter=text-summary npm run test-node",
Expand Down
35 changes: 8 additions & 27 deletions test/10-verify.spec.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/*!
* Copyright (c) 2019-2021 Digital Bazaar, Inc. All rights reserved.
*/
const chai = require('chai');
const should = chai.should();

Expand Down Expand Up @@ -151,27 +154,6 @@ describe('vc.signPresentation()', () => {
});
});

describe('verifies RFC3339 Dates', function() {
it('verify a valid date', function() {
const latest = new Date().toISOString();
vc.dateRegex.test(latest).should.be.true;
});
it('verify a valid date with lowercase t', function() {
const latest = new Date().toISOString().toLowerCase();
vc.dateRegex.test(latest).should.be.true;
});

it('should not verify an invalid date', function() {
const invalid = '2017/09/27';
vc.dateRegex.test(invalid).should.be.false;
});
it('should not verify 2 digit years', function() {
const invalid = '17-09-27T22:07:22.563z';
vc.dateRegex.test(invalid).should.be.false;
});

});

describe('verify API (credentials)', () => {
it('should verify a vc', async () => {
verifiableCredential = await vc.issue({
Expand Down Expand Up @@ -310,7 +292,7 @@ describe('verify API (credentials)', () => {
});

describe('verify API (presentations)', () => {
it('verifies a valid signed presentation', async () => {
it.only('verifies a valid signed presentation', async () => {
const challenge = uuid();

const {presentation, suite, documentLoader} =
Expand All @@ -323,6 +305,8 @@ describe('verify API (presentations)', () => {
presentation
});

console.log(result)

if(result.error) {
const firstError = [].concat(result.error)[0];
throw firstError;
Expand Down Expand Up @@ -352,12 +336,10 @@ describe('verify API (presentations)', () => {
});

describe('test for multiple credentials', async () => {

const credentialsCount = [5, 25, 50, 100];

for(const count of credentialsCount) {
it('cause error when credentials are tampered', async function() {
this.timeout(10000);
it('cause error when credentials are tampered', async () => {
const challenge = uuid();
const {presentation, suite: vcSuite, documentLoader} =
await _generatePresentation({challenge, credentialsCount: count});
Expand Down Expand Up @@ -401,8 +383,7 @@ describe('test for multiple credentials', async () => {
firstErrorMsg.should.contain('Invalid signature.');
});

it('should not cause error when credentials are correct', async function() {
this.timeout(10000);
it('should not cause error when credentials are correct', async () => {
const challenge = uuid();
const {presentation, suite: vcSuite, documentLoader} =
await _generatePresentation({challenge, credentialsCount: count});
Expand Down
27 changes: 27 additions & 0 deletions test/dateRegex.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*!
* Copyright (c) 2019-2021 Digital Bazaar, Inc. All rights reserved.
*/
const chai = require('chai');
chai.should();

const vc = require('..');

describe('verifies RFC3339 Dates', function() {
it('verify a valid date', function() {
const latest = new Date().toISOString();
vc.dateRegex.test(latest).should.be.true;
});
it('verify a valid date with lowercase t', function() {
const latest = new Date().toISOString().toLowerCase();
vc.dateRegex.test(latest).should.be.true;
});

it('should not verify an invalid date', function() {
const invalid = '2017/09/27';
vc.dateRegex.test(invalid).should.be.false;
});
it('should not verify 2 digit years', function() {
const invalid = '17-09-27T22:07:22.563z';
vc.dateRegex.test(invalid).should.be.false;
});
});
1 change: 1 addition & 0 deletions test/mocks/didDocument.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable */
module.exports = {
"@context": [
"https://w3id.org/did/v0.11",
Expand Down
1 change: 1 addition & 0 deletions test/mocks/didKeys.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable */
/**
* Private key store for the test DID Document.
* Note that this is for unit testing purposes only, please do not commit
Expand Down
1 change: 1 addition & 0 deletions test/mocks/mock.data.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable */
const constants = require('../constants');

const mock = {};
Expand Down

0 comments on commit ebcf94b

Please sign in to comment.