Skip to content

Commit

Permalink
Merge main, add Dockerfile and fix broken tests
Browse files Browse the repository at this point in the history
Signed-off-by: PatStLouis <[email protected]>
  • Loading branch information
PatStLouis committed Oct 18, 2024
2 parents 44ae8c8 + fb40c08 commit 65236ea
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 30 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ package-lock.json
config.json
reports/**
!.gitkeep
localConfig.cjs
localConfig.cjs
allure-results/
11 changes: 11 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM node:18

WORKDIR /test-suite

RUN apt update

COPY package.json ./
COPY tests/ ./tests

RUN npm i
CMD [ "npm", "t" ]
14 changes: 11 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,26 @@
"ed25519-signature-2020-context": "^1.1.0",
"jsonld-document-loader": "^2.0.0",
"klona": "^2.0.6",
"mocha": "^10.2.0",
"uuid": "^9.0.0",
"vc-test-suite-implementations": "github:w3c/vc-test-suite-implementations"
},
"devDependencies": {
"allure-commandline": "^2.30.0",
"allure-mocha": "^3.0.5",
"eslint": "^8.54.0",
"eslint-config-digitalbazaar": "^5.0.1",
"eslint-plugin-jsdoc": "^46.9.0",
"eslint-plugin-unicorn": "^49.0.0"
"eslint-plugin-unicorn": "^49.0.0",
"mocha": "^10.7.3"
},
"bugs": {
"url": "https://github.com/w3c/vc-bitstring-status-list-test-suite/issues"
},
"homepage": "https://github.com/w3c/vc-bitstring-status-list-test-suite#readme"
"homepage": "https://github.com/w3c/vc-bitstring-status-list-test-suite#readme",
"mocha": {
"reporter": "allure-mocha",
"reporterOptions": [
"resultsDir=allure-results"
]
}
}
2 changes: 1 addition & 1 deletion tests/30-interop.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function setupMatrix() {
this.columnLabel = 'Verifier';
}

describe('BitstringStatusList Credentials (Interop)', function() {
describe('Interop', function() {
setupMatrix.call(this, match);
for(const [issuerName, implementation] of match) {
const endpoints = new TestEndpoints({implementation, tag});
Expand Down
36 changes: 18 additions & 18 deletions tests/TestEndpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
createRequestBody,
createVerifyRequestBody
} from './mock.data.js';
import {addJsonAttachment} from './helpers.js';

export class TestEndpoints {
constructor({implementation, tag}) {
Expand All @@ -21,30 +22,29 @@ export class TestEndpoints {
async issue(credential) {
const {issuer} = this;
const issueBody = createRequestBody({issuer, vc: credential});
const response = await post(issuer, issueBody);
return response?.verifiableCredential || response;
await addJsonAttachment('Request', issueBody);
const response = post(issuer, issueBody);
await addJsonAttachment('Response', response);
return response;
}
async verify(vc) {
const {verifier} = this;
const verifyBody = createVerifyRequestBody({vc});
const result = await post(verifier, verifyBody);
const verifyBody = createVerifyRequestBody({verifier, vc});
await addJsonAttachment('Request', verifyBody);
const result = post(this.verifier, verifyBody);
if(result?.errors?.length) {
throw result.errors[0];
}
await addJsonAttachment('Response', result);
return result;
}
}

export async function post(endpoint, object) {
return fetch(endpoint.settings.endpoint, {
headers: {
'Content-type': 'application/json'
},
method: 'POST',
body: JSON.stringify(object)
})
.then(function(response) {
if(response.status >= 400) {
throw new Error('Error');
} else {
return response.json();
}
});
// Use vc-test-suite-implementations for HTTPS requests.
const {data, error} = await endpoint.post({json: object});
if(error) {
throw error;
}
return data;
}
17 changes: 17 additions & 0 deletions tests/helpers.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
/*!
* Copyright (c) 2022-2023 Digital Bazaar, Inc. All rights reserved.
*/

import * as allure from 'allure-js-commons';
import * as base64url from 'base64url-universal';
import {ContentType} from 'allure-js-commons';
// import * as sl from '@digitalbazaar/vc-status-list';
import chai from 'chai';
import {createRequire} from 'node:module';
Expand Down Expand Up @@ -171,3 +174,17 @@ export async function decodeSl({encodedList}) {
'representation of a GZIP-compressed bitstring.');
return decoded;
}

export async function addJsonAttachment(fileName, content) {
try {
// Temporarily disable the console log to avoid unnecessary info logs.
const consoleLog = console.log;
console.log = function() {};
await allure.attachment(
fileName,
JSON.stringify(content, null, 2),
ContentType.JSON
);
console.log = consoleLog;
} catch(err) {}
}
13 changes: 6 additions & 7 deletions tests/mock.data.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,13 @@ export const createRequestBody = ({issuer, vc = validVc}) => {
};
};

export const createVerifyRequestBody = ({vc}) => {
const body = {
verifiableCredential: vc,
options: {
checks: ['proof'],
}
export const createVerifyRequestBody = ({verifier, vc}) => {
const {settings: {options}} = verifier;
const verifiableCredential = vc;
return {
verifiableCredential,
options
};
return body;
};

/**
Expand Down

0 comments on commit 65236ea

Please sign in to comment.