Skip to content

Commit

Permalink
feat: make all claim types default
Browse files Browse the repository at this point in the history
When adding a default trusted claim issuer, if trustedFor is undefined, it is interpreted as "all
claim types"

BREAKING CHANGE: - `null` is no longer an accepted value for `trustedFor` in `TrustedClaimIssuer`.
That behavior is replaced by `undefined`
  • Loading branch information
monitz87 committed Dec 2, 2020
1 parent 2ed32a2 commit d85e26f
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 32 deletions.
6 changes: 3 additions & 3 deletions src/api/entities/DefaultTrustedClaimIssuer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface UniqueIdentifiers {
}

export interface Params {
trustedFor: ClaimType[] | null;
trustedFor?: ClaimType[];
}

/**
Expand All @@ -36,9 +36,9 @@ export class DefaultTrustedClaimIssuer extends Entity<UniqueIdentifiers> {
public identity: Identity;

/**
* claim types for which this Claim Issuer is trusted. A null value means that the issuer is trusted for all claim types
* claim types for which this Claim Issuer is trusted. An undefined value means that the issuer is trusted for all claim types
*/
public trustedFor: ClaimType[] | null;
public trustedFor?: ClaimType[];

/**
* ticker of the Security Token
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,7 @@ export class TrustedClaimIssuers extends Namespace<SecurityToken> {
const assembleResult = (issuers: TrustedIssuer[]): DefaultTrustedClaimIssuer[] =>
issuers.map(
({ issuer }) =>
new DefaultTrustedClaimIssuer(
{ did: identityIdToString(issuer), ticker, trustedFor: null },
context
)
new DefaultTrustedClaimIssuer({ did: identityIdToString(issuer), ticker }, context)
);

if (callback) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ describe('TrustedClaimIssuers class', () => {

const args: ModifyTokenTrustedClaimIssuersAddSetParams = {
claimIssuers: [
{ identity: entityMockUtils.getIdentityInstance({ did: 'someDid' }), trustedFor: null },
{ identity: entityMockUtils.getIdentityInstance({ did: 'otherDid' }), trustedFor: null },
{ identity: entityMockUtils.getIdentityInstance({ did: 'someDid' }) },
{ identity: entityMockUtils.getIdentityInstance({ did: 'otherDid' }) },
],
};

Expand Down Expand Up @@ -86,8 +86,8 @@ describe('TrustedClaimIssuers class', () => {

const args: ModifyTokenTrustedClaimIssuersAddSetParams = {
claimIssuers: [
{ identity: entityMockUtils.getIdentityInstance({ did: 'someDid' }), trustedFor: null },
{ identity: entityMockUtils.getIdentityInstance({ did: 'otherDid' }), trustedFor: null },
{ identity: entityMockUtils.getIdentityInstance({ did: 'someDid' }) },
{ identity: entityMockUtils.getIdentityInstance({ did: 'otherDid' }) },
],
};

Expand Down Expand Up @@ -168,9 +168,7 @@ describe('TrustedClaimIssuers class', () => {
claimIssuers = [];

expectedDids.forEach(did => {
expectedTrustedClaimIssuers.push(
new DefaultTrustedClaimIssuer({ did, ticker, trustedFor: null }, context)
);
expectedTrustedClaimIssuers.push(new DefaultTrustedClaimIssuer({ did, ticker }, context));
claimIssuers.push(
dsMockUtils.createMockTrustedIssuer({
issuer: dsMockUtils.createMockIdentityId(did),
Expand Down
15 changes: 3 additions & 12 deletions src/api/entities/__tests__/DefaultTrustedClaimIssuer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ describe('DefaultTrustedClaimIssuer class', () => {
const did = 'someDid';
const ticker = 'SOMETICKER';
const identity = new Identity({ did }, context);
const trustedClaimIssuer = new DefaultTrustedClaimIssuer(
{ did, ticker, trustedFor: null },
context
);
const trustedClaimIssuer = new DefaultTrustedClaimIssuer({ did, ticker }, context);

expect(trustedClaimIssuer.ticker).toBe(ticker);
expect(trustedClaimIssuer.identity).toEqual(identity);
Expand Down Expand Up @@ -71,10 +68,7 @@ describe('DefaultTrustedClaimIssuer class', () => {
const blockDate = new Date('4/14/2020');
const eventIdx = 1;
const fakeResult = { blockNumber, blockDate, eventIndex: eventIdx };
const trustedClaimIssuer = new DefaultTrustedClaimIssuer(
{ did, ticker, trustedFor: null },
context
);
const trustedClaimIssuer = new DefaultTrustedClaimIssuer({ did, ticker }, context);

dsMockUtils.createApolloQueryStub(eventByIndexedArgs(variables), {
/* eslint-disable @typescript-eslint/camelcase */
Expand All @@ -92,10 +86,7 @@ describe('DefaultTrustedClaimIssuer class', () => {
});

test('should return null if the query result is empty', async () => {
const trustedClaimIssuer = new DefaultTrustedClaimIssuer(
{ did, ticker, trustedFor: null },
context
);
const trustedClaimIssuer = new DefaultTrustedClaimIssuer({ did, ticker }, context);

dsMockUtils.createApolloQueryStub(eventByIndexedArgs(variables), {});
const result = await trustedClaimIssuer.addedAt();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ describe('modifyTokenTrustedClaimIssuers procedure', () => {
claimIssuerDids = ['aDid', 'otherDid', 'differentDid'];
claimIssuers = claimIssuerDids.map(did => ({
identity: new Identity({ did }, mockContext),
trustedFor: null,
}));
rawTicker = dsMockUtils.createMockTicker(ticker);
rawClaimIssuers = claimIssuerDids.map(did =>
Expand Down
4 changes: 2 additions & 2 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,9 @@ export interface ClaimScope {
export interface TrustedClaimIssuer {
identity: Identity;
/**
* a null value means that the issuer is trusted for all claim types
* an undefined value means that the issuer is trusted for all claim types.
*/
trustedFor: ClaimType[] | null;
trustedFor?: ClaimType[];
}

export enum ConditionType {
Expand Down
2 changes: 0 additions & 2 deletions src/utils/__tests__/conversion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3936,7 +3936,6 @@ describe('trustedClaimIssuerToTrustedIssuer and trustedIssuerToTrustedClaimIssue

let issuer: TrustedClaimIssuer = {
identity: entityMockUtils.getIdentityInstance({ did }),
trustedFor: null,
};

dsMockUtils
Expand Down Expand Up @@ -3972,7 +3971,6 @@ describe('trustedClaimIssuerToTrustedIssuer and trustedIssuerToTrustedClaimIssue
const context = dsMockUtils.getContextInstance();
let fakeResult: TrustedClaimIssuer = {
identity: new Identity({ did }, context),
trustedFor: null,
};
let trustedIssuer = dsMockUtils.createMockTrustedIssuer({
issuer: dsMockUtils.createMockIdentityId(did),
Expand Down
2 changes: 1 addition & 1 deletion src/utils/conversion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2025,7 +2025,7 @@ export function trustedIssuerToTrustedClaimIssuer(

const identity = new Identity({ did: identityIdToString(issuer) }, context);

let trustedFor: ClaimType[] | null = null;
let trustedFor: ClaimType[] | undefined;

if (claimTypes.isSpecific) {
trustedFor = claimTypes.asSpecific.map(meshClaimTypeToClaimType);
Expand Down

0 comments on commit d85e26f

Please sign in to comment.