Skip to content

Commit

Permalink
chore: update Mattr test to latest version
Browse files Browse the repository at this point in the history
  • Loading branch information
nklomp committed Sep 4, 2023
1 parent 7800999 commit 42c6b19
Show file tree
Hide file tree
Showing 4 changed files with 218 additions and 157 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-test-on-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
node-version: '16.x'
- uses: pnpm/action-setup@v2
with:
version: 8.1.0
version: 8
- run: pnpm install
- run: pnpm build
- name: run CI tests
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build-test-publish-on-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ jobs:
node-version: '16.x'
- uses: pnpm/action-setup@v2
with:
version: 8.1.0
version: 8
# - name: Get yarn cache directory path
# id: yarn-cache-dir-path
# run: echo "::set-output name=dir::$(yarn cache dir)"
Expand Down
72 changes: 43 additions & 29 deletions packages/client/lib/__tests__/MattrE2E.spec.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,38 +19,51 @@ const jwk: JWK = {
const did = `did:key:z6Mki5ZwZKN1dBQprfJTikUvkDxrHijiiQngkWviMF5gw2Hv`;
const kid = `${did}#z6Mki5ZwZKN1dBQprfJTikUvkDxrHijiiQngkWviMF5gw2Hv`;
describe('OID4VCI-Client using Mattr issuer should', () => {
async function test(format: 'ldp_vc' | 'jwt_vc_json') {
const offer = await getCredentialOffer(format)
const client = await OpenID4VCIClient.fromURI({
uri: offer.offerUrl,
flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW,
kid,
alg: Alg.EdDSA
})
expect(client.flowType).toEqual(AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW)
expect(client.credentialOffer).toBeDefined()
expect(client.endpointMetadata).toBeDefined()
expect(client.getCredentialEndpoint()).toEqual(`${ISSUER_URL}/oidc/v1/auth/credential`)
expect(client.getAccessTokenEndpoint()).toEqual('https://launchpad.vii.electron.mattrlabs.io/oidc/v1/auth/token')

const accessToken = await client.acquireAccessToken()
console.log(accessToken)
expect(accessToken).toMatchObject({
expires_in: 3600,
scope: 'OpenBadgeCredential',
token_type: 'Bearer'
})

const credentialResponse = await client.acquireCredentials({
credentialTypes: 'OpenBadgeCredential',
format,
proofCallbacks: {
signCallback: proofOfPossessionCallbackFunction
}
})
expect(credentialResponse.credential).toBeDefined()
}

it(
'succeed in a full flow with the client using OpenID4VCI version 11',
'succeed in a full flow with the client using OpenID4VCI version 11 and ldp_vc',
async () => {
const offer = await getCredentialOffer();
const client = await OpenID4VCIClient.fromURI({
uri: offer.offerUrl,
flowType: AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW,
kid,
alg: Alg.EdDSA,
});
expect(client.flowType).toEqual(AuthzFlowType.PRE_AUTHORIZED_CODE_FLOW);
expect(client.credentialOffer).toBeDefined();
expect(client.endpointMetadata).toBeDefined();
expect(client.getCredentialEndpoint()).toEqual(`${ISSUER_URL}/oidc/v1/auth/credential`);
expect(client.getAccessTokenEndpoint()).toEqual('https://launchpad.vii.electron.mattrlabs.io/oidc/v1/auth/token');

const accessToken = await client.acquireAccessToken();
console.log(accessToken);
expect(accessToken).toMatchObject({
expires_in: 3600,
scope: 'OpenBadgeCredential',
token_type: 'Bearer',
});
await test('ldp_vc')
},
UNIT_TEST_TIMEOUT,
);
it(
'succeed in a full flow with the client using OpenID4VCI version 11 and jwt_vc_json',
async () => {

const credentialResponse = await client.acquireCredentials({
credentialTypes: 'OpenBadgeCredential',
format: 'ldp_vc',
proofCallbacks: {
signCallback: proofOfPossessionCallbackFunction,
},
});
expect(credentialResponse.credential).toBeDefined();
await test('jwt_vc_json')
},
UNIT_TEST_TIMEOUT,
);
Expand All @@ -61,7 +74,7 @@ interface CreateCredentialOfferResponse {
offerUrl: string;
}

async function getCredentialOffer(): Promise<CreateCredentialOfferResponse> {
async function getCredentialOffer(format: 'ldp_vc' | 'jwt_vc_json'): Promise<CreateCredentialOfferResponse> {
const credentialOffer = await fetch('https://launchpad.mattrlabs.com/api/credential-offer', {
method: 'post',
headers: {
Expand All @@ -71,6 +84,7 @@ async function getCredentialOffer(): Promise<CreateCredentialOfferResponse> {

//make sure to serialize your JSON body
body: JSON.stringify({
format,
type: 'OpenBadgeCredential',
userId: '622a9f65-21c0-4c0b-9a6a-f7574c2a1549',
userAuthenticationRequired: false,
Expand Down
Loading

0 comments on commit 42c6b19

Please sign in to comment.