Unverified Commit e52d6437 authored by Matthieu Collé's avatar Matthieu Collé Committed by GitHub
Browse files

Merge pull request #716 from...

Merge pull request #716 from blockchain-certificates/feat/715-revocationLis-pass-assertion-id-parameter

Feat/715 revocation list passes assertion id parameter
parents 87ce7649 7bea7db3
......@@ -21,6 +21,8 @@ module.exports = {
'@typescript-eslint/interface-name-prefix': [0],
'@typescript-eslint/strict-boolean-expressions': [0],
'@typescript-eslint/no-explicit-any': [0], // remove one day, maybe. This is early days so we have some anys.
'@typescript-eslint/restrict-plus-operands': [0] // when this rule functions correctly, we can remove it. It does not pick up the correct type when returning from a JS function
'@typescript-eslint/restrict-plus-operands': [0], // when this rule functions correctly, we can remove it. It
// does not pick up the correct type when returning from a JS function
'@typescript-eslint/no-inferrable-types': 'off'
}
};
......@@ -275,6 +275,11 @@ interface TransactionData {
The consumer needs to write their own function for each service used.
## Revocation
The `assertionId` is appended to the `revocationList` URL request as query parameter, to allow the filtering of the
`revokedAssertions` by the provider: `{revocationList}?assertionId={assertionIdValue}`
More details here [in this ticket](https://github.com/blockchain-certificates/cert-verifier-js/issues/715).
## Contribute
### Run the tests
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -2,20 +2,26 @@ import { request } from '../../../services';
import { VerifierError } from '../../../models';
import { SUB_STEPS } from '../../../constants';
import { getText } from '../../i18n/useCases';
import { RevocationList, RevokedAssertion } from '../../../models/RevokedAssertions';
import { safelyAppendUrlParameter } from '../../../helpers/url';
export default async function getRevokedAssertions (revocationListUrl) {
const ASSERTION_ID_NAME: string = 'assertionId';
export default async function getRevokedAssertions (revocationListUrl: string, assertionId?: string): Promise<RevokedAssertion[]> {
if (!revocationListUrl) {
return Promise.resolve([]);
return [];
}
const errorMessage = getText('errors', 'getRevokedAssertions');
const errorMessage: string = getText('errors', 'getRevokedAssertions');
if (assertionId) {
revocationListUrl = safelyAppendUrlParameter(revocationListUrl, ASSERTION_ID_NAME, encodeURIComponent(assertionId));
}
const response = await request({ url: revocationListUrl }).catch(() => {
const response: any = await request({ url: revocationListUrl }).catch(() => {
throw new VerifierError(SUB_STEPS.parseIssuerKeys, errorMessage);
});
const issuerRevocationJson = JSON.parse(response);
return issuerRevocationJson.revokedAssertions
? issuerRevocationJson.revokedAssertions
: [];
const issuerRevocationJson: RevocationList = JSON.parse(response);
return issuerRevocationJson.revokedAssertions ?? [];
}
export function safelyAppendUrlParameter (url: string, parameterKey: string, parameterValue: string): string {
const separator = url.includes('?') ? '&' : '?';
return `${url}${separator}${parameterKey}=${parameterValue}`;
}
export interface RevocationList {
type: string | any[];
id: string;
issuer: string;
revokedAssertions: RevokedAssertion[];
}
export interface RevokedAssertion {
id: string;
revocationReason: string;
}
import { ExplorerAPI } from '../certificate';
import { TRANSACTION_ID_PLACEHOLDER } from '../constants/api';
import { safelyAppendUrlParameter } from '../helpers/url';
function appendApiIdentifier (url: string, explorerAPI: ExplorerAPI): string {
if (!explorerAPI.key) {
......@@ -10,8 +11,7 @@ function appendApiIdentifier (url: string, explorerAPI: ExplorerAPI): string {
throw new Error(`No keyPropertyName defined for explorerAPI ${explorerAPI.serviceName}`);
}
const separator = url.includes('?') ? '&' : '?';
return `${url}${separator}${explorerAPI.keyPropertyName}=${explorerAPI.key}`;
return safelyAppendUrlParameter(url, explorerAPI.keyPropertyName, explorerAPI.key);
}
export function buildTransactionServiceUrl ({
......
......@@ -251,7 +251,7 @@ export default class Verifier {
// Get revoked assertions
revokedAddresses = await this._doAsyncAction(
null,
async () => await domain.verifier.getRevokedAssertions(this._getRevocationListUrl(issuerProfileJson))
async () => await domain.verifier.getRevokedAssertions(this._getRevocationListUrl(issuerProfileJson), this.id)
);
keys = this.id;
}
......
......@@ -25,13 +25,36 @@ describe('Verifier domain getRevokedAssertions use case test suite', function ()
describe('given it is called with an revocationListUrl', function () {
const revokedAssertionsAssertionString = JSON.stringify(revokedAssertionsFixture);
const issuerIdFixture = 'http://domain.tld';
const issuerIdFixture = 'http://domain.tld/path';
describe('when the request is successful', function () {
it('should return the revoked assertions JSON object', async function () {
describe('and an assertionId', function () {
it('should request the correct URL with the appended assertionId', async function () {
stubRequest.resolves(revokedAssertionsAssertionString);
const result = await getRevokedAssertions(issuerIdFixture);
expect(result).toEqual(revokedAssertionsFixture.revokedAssertions);
const fixtureAssertionId = 'https://fixture-assertion-id.domain.tld';
await getRevokedAssertions(issuerIdFixture, fixtureAssertionId);
expect(stubRequest.getCall(0).args[0]).toEqual({
url: 'http://domain.tld/path?assertionId=https%3A%2F%2Ffixture-assertion-id.domain.tld'
});
});
});
describe('when the request is successful', function () {
describe('and the response does not have revokedAssertions', function () {
it('should return an empty array', async function () {
const revokedAssertionsAssertionCopy = { ...revokedAssertionsFixture };
delete revokedAssertionsAssertionCopy.revokedAssertions;
stubRequest.resolves(JSON.stringify(revokedAssertionsAssertionCopy));
const result = await getRevokedAssertions(issuerIdFixture);
expect(result).toEqual([]);
});
});
describe('and the response has revokedAssertions', function () {
it('should return the revoked assertions JSON object', async function () {
stubRequest.resolves(revokedAssertionsAssertionString);
const result = await getRevokedAssertions(issuerIdFixture);
expect(result).toEqual(revokedAssertionsFixture.revokedAssertions);
});
});
});
......
import { safelyAppendUrlParameter } from '../../../src/helpers/url';
describe('safelyAppendUrlParameter method', function () {
let fixtureUrl: string;
const fixtureParameterKey = 'parameterKey';
const fixtureParameterValue = 'parameterValue';
describe('given the url already has parameter', function () {
it('should return the url with the parameter correctly appended', function () {
fixtureUrl = 'https://www.domain.tld/path/to/page?key=value';
const assertionURL = `${fixtureUrl}&${fixtureParameterKey}=${fixtureParameterValue}`;
expect(safelyAppendUrlParameter(fixtureUrl, fixtureParameterKey, fixtureParameterValue))
.toEqual(assertionURL);
});
});
describe('given the url does not already have parameter', function () {
it('should return the url with the parameter correctly appended', function () {
fixtureUrl = 'https://www.domain.tld/path/to/page';
const assertionURL = `${fixtureUrl}?${fixtureParameterKey}=${fixtureParameterValue}`;
expect(safelyAppendUrlParameter(fixtureUrl, fixtureParameterKey, fixtureParameterValue))
.toEqual(assertionURL);
});
});
});
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment