Skip to content

Commit

Permalink
chore: test fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nklomp committed Dec 21, 2023
1 parent c44107f commit a504fb2
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 22 deletions.
11 changes: 5 additions & 6 deletions packages/client/lib/OpenID4VCIClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export class OpenID4VCIClient {
clientId,
kid,
alg,
credentialIssuer
credentialIssuer,
}: {
credentialOffer?: CredentialOfferRequestWithBaseUrl;
kid?: string;
Expand All @@ -69,12 +69,11 @@ export class OpenID4VCIClient {
credentialIssuer?: string;
}) {
this._credentialOffer = credentialOffer;
const issuer =
credentialIssuer ?? (credentialOffer ? getIssuerFromCredentialOfferPayload(credentialOffer.credential_offer) : undefined);
const issuer = credentialIssuer ?? (credentialOffer ? getIssuerFromCredentialOfferPayload(credentialOffer.credential_offer) : undefined);
if (!issuer) {
throw Error('No credential issuer supplied or deduced from offer')
throw Error('No credential issuer supplied or deduced from offer');
}
this._credentialIssuer = issuer
this._credentialIssuer = issuer;
this._kid = kid;
this._alg = alg;
this._clientId = clientId;
Expand Down Expand Up @@ -154,7 +153,7 @@ export class OpenID4VCIClient {
const creds = this.credentialOffer.credential_offer.credentials;

authorizationDetails = creds
.flatMap((cred) => (typeof cred === 'string' ? this.getCredentialsSupported(true) : cred as CredentialSupported))
.flatMap((cred) => (typeof cred === 'string' ? this.getCredentialsSupported(true) : (cred as CredentialSupported)))
.map((cred) => {
return {
...cred,
Expand Down
34 changes: 19 additions & 15 deletions packages/client/lib/__tests__/EBSIE2E.spec.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Alg, CodeChallengeMethod, Jwt } from '@sphereon/oid4vci-common'
import { toJwk } from '@sphereon/ssi-sdk-ext.key-utils'
import { CredentialMapper } from '@sphereon/ssi-types'
import { Alg, CodeChallengeMethod, Jwt } from '@sphereon/oid4vci-common';
import { toJwk } from '@sphereon/ssi-sdk-ext.key-utils';
import { CredentialMapper } from '@sphereon/ssi-types';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-ignore
import { from } from '@trust/keyto'
import { fetch } from 'cross-fetch'
import debug from 'debug'
import { base64url, importJWK, JWK, SignJWT } from 'jose'
import * as u8a from 'uint8arrays'
import { from } from '@trust/keyto';
import { fetch } from 'cross-fetch';
import debug from 'debug';
import { base64url, importJWK, JWK, SignJWT } from 'jose';
import * as u8a from 'uint8arrays';

import { OpenID4VCIClient } from '..'
import { OpenID4VCIClient } from '..';

export const UNIT_TEST_TIMEOUT = 30000;

Expand Down Expand Up @@ -60,17 +60,21 @@ describe('OID4VCI-Client using Sphereon issuer should', () => {
uri: offer,
kid,
alg: Alg.ES256,
clientId: DID_URL_ENCODED
clientId: DID_URL_ENCODED,
});
expect(client.credentialOffer).toBeDefined();
expect(client.endpointMetadata).toBeDefined();
expect(client.getCredentialEndpoint()).toEqual(`${ISSUER_URL}/credential`);
expect(client.getAccessTokenEndpoint()).toEqual(`${AUTH_URL}/token`);

if (credentialType !== 'CTWalletCrossPreAuthorised') {
const url = client.createAuthorizationRequestUrl({redirectUri: 'openid4vc%3A', codeChallenge: 'mE2kPHmIprOqtkaYmESWj35yz-PB5vzdiSu0tAZ8sqs', codeChallengeMethod: CodeChallengeMethod.SHA256})
const result = await fetch(url)
console.log(result.text())
const url = client.createAuthorizationRequestUrl({
redirectUri: 'openid4vc%3A',
codeChallenge: 'mE2kPHmIprOqtkaYmESWj35yz-PB5vzdiSu0tAZ8sqs',
codeChallengeMethod: CodeChallengeMethod.SHA256,
});
const result = await fetch(url);
console.log(result.text());
}

const accessToken = await client.acquireAccessToken({ pin: '0891' });
Expand All @@ -90,7 +94,7 @@ describe('OID4VCI-Client using Sphereon issuer should', () => {
},
kid,
});
console.log(JSON.stringify(credentialResponse, null, 2))
console.log(JSON.stringify(credentialResponse, null, 2));
expect(credentialResponse.credential).toBeDefined();
const wrappedVC = CredentialMapper.toWrappedVerifiableCredential(credentialResponse.credential!);
expect(format.startsWith(wrappedVC.format)).toEqual(true);
Expand All @@ -99,7 +103,7 @@ describe('OID4VCI-Client using Sphereon issuer should', () => {
it(
'succeed in a full flow with the client using OpenID4VCI version 11 and jwt_vc_json',
async () => {
await test('CTWalletCrossPreAuthorised')
await test('CTWalletCrossPreAuthorised');
// await test('CTWalletCrossInTime');
},
UNIT_TEST_TIMEOUT,
Expand Down
5 changes: 5 additions & 0 deletions packages/client/lib/__tests__/OpenID4VCIClient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ describe('OpenID4VCIClient should', () => {
expect(scope?.[0]).toBe('openid');
});
it('throw an error if no scope and no authorization_details is provided', async () => {
nock(MOCK_URL).get(/.*/).reply(200, {});
nock(MOCK_URL).get(WellKnownEndpoints.OAUTH_AS).reply(404, {});
nock(MOCK_URL).get(WellKnownEndpoints.OPENID_CONFIGURATION).reply(404, {});
// Use a client with issuer only to trigger the error
client = await OpenID4VCIClient.fromCredentialIssuer({ credentialIssuer: 'https://server.example.com' });
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
client._endpointMetadata?.credentialIssuerMetadata.authorization_endpoint = `${MOCK_URL}v1/auth/authorize`;
Expand Down
2 changes: 1 addition & 1 deletion packages/common/lib/functions/IssuerMetadataUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function getSupportedCredential(opts?: {
}
const { version, types } = opts ?? { version: OpenId4VCIVersion.VER_1_0_11 };
if (version === OpenId4VCIVersion.VER_1_0_08 || !Array.isArray(issuerMetadata.credentials_supported)) {
credentialsSupported = credentialsSupportedV8ToV11((issuerMetadata as IssuerMetadataV1_0_08).credentials_supported);
credentialsSupported = credentialsSupportedV8ToV11((issuerMetadata as IssuerMetadataV1_0_08).credentials_supported ?? {});
} else {
credentialsSupported = (issuerMetadata as CredentialIssuerMetadata).credentials_supported;
}
Expand Down

0 comments on commit a504fb2

Please sign in to comment.