Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
Signed-off-by: F-Node-Karlsruhe <[email protected]>
  • Loading branch information
F-Node-Karlsruhe committed Jun 14, 2023
1 parent 46eac68 commit a4fecba
Show file tree
Hide file tree
Showing 2 changed files with 191 additions and 0 deletions.
87 changes: 87 additions & 0 deletions api/__tests__/credential.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,70 @@ import request from "supertest";

import app from "../src/index";

const revokedCredential: any = {
"@context": [
"https://www.w3.org/2018/credentials/v1",
"https://ssi.eecc.de/api/registry/context/productpassport",
"https://w3id.org/vc-revocation-list-2020/v1",
"https://w3id.org/security/suites/ed25519-2020/v1"
],
"id": "https://ssi.eecc.de/api/registry/vc/0a720a69-34f0-4ed0-b767-a0a5f9212020",
"type": [
"VerifiableCredential",
"ProductPassportCredential"
],
"issuer": "did:web:ssi.eecc.de",
"issuanceDate": "2023-01-03T13:54:14Z",
"credentialStatus": {
"id": "https://ssi.eecc.de/api/registry/vc/status/did:web:ssi.eecc.de/1#0",
"type": "RevocationList2020Status",
"revocationListIndex": 0,
"revocationListCredential": "https://ssi.eecc.de/api/registry/vc/status/did:web:ssi.eecc.de/1"
},
"credentialSubject": {
"id": "https://id.eecc.de/253/04047111020226acf129b8afd612b3",
"country_of_origin": "Germany"
},
"proof": {
"type": "Ed25519Signature2020",
"created": "2023-01-03T13:54:14Z",
"proofPurpose": "assertionMethod",
"verificationMethod": "did:web:ssi.eecc.de#z6MkoHWsmSZnHisAxnVdokYHnXaVqWFZ4H33FnNg13zyymxd",
"proofValue": "z4vkGt3B7x1p31kJpTrhwe8EGsTEmd48M4Jrzco86iw4n9pHRsx4wbwbNG14s39Vjxi9LzcQ9Ym595dZ54vetLrPS"
}
}

const SDCredential: any = {
"@context": [
"https://www.w3.org/2018/credentials/v1",
"ipfs://QmQsgaZPy6zyFAMPvASjz9tyGpmS5LT1zrrNVqP7aorQrN",
"https://w3id.org/security/data-integrity/v1"
],
"id": "https://ssi.eecc.de/api/registry/vc/3187e4ca-9129-4059-af26-0f85650c2d0f",
"type": [
"VerifiableCredential",
"ProductPassportCredential"
],
"credentialSubject": {
"id": "https://id.eecc.de/01/04012345999990/10/20210401-A/21/XYZ-1234",
"digital_link": "https://id.eecc.de/01/04012345999990/10/20210401-A/21/XYZ-1234"
},
"issuanceDate": "2023-06-02T08:16:50Z",
"issuer": {
"id": "did:web:ssi.eecc.de",
"image": "https://id.eecc.de/assets/img/logo_big.png",
"name": "EECC"
},
"proof": {
"type": "DataIntegrityProof",
"created": "2023-06-02T08:16:50Z",
"proofPurpose": "assertionMethod",
"verificationMethod": "did:web:ssi.eecc.de#selective-disclosure",
"proofValue": "u2V0BhVhAYf_lmn1aGK8R1IaMmLTSs4AN_l3qfDUqFSRmwjRCenPlGNq-0rtjpk4NX2JNWbd0brKeifHuG_P6sy_3AARmW1gkge0PzyPDCxH_sbVlcIuOsD5wLCtkCmL0Ub_IYEjit8Yk5CJBiFhAZ2uy2m5bkn3nQuC1ntJxW4AWjLGuCS2GwoKgBRDvBdh2Sc9_hIMhbMpAJ5x8UyTeoP7VTVZOKRttDeTwtIvgiFhATqtnXpYJdu7x_qtIZJOMsPgNkfbHEXlUMgRIDPEuiio_KzehUjV5LkjssclwrRh4Qlt9juy7GNAPGyZRohMOXFhA7i-IxotjHR3wbSppxyxIpLkJv-hYPuAmeVakDviRaZbMteI81J3tDYWh3e5-ZxGNNT0qnM1XyCybZWc0O_FdCFhAi7T8KEHO78BDBQPn6KJ-IQmfgLPtcbYFbSoTT8h3bR7pyI6UfvXNXlBMWR8IY4ELVWQZQ9iaYO0wsZKTOc-1gFhAUTYy8tvLsTH-ObyqDIcDNQ2OWSX9xh5KHvHOpM4UrGV4uzqYf9IW9mrQPXip2eTehLidmSdRuw7o58k61qeekFhAc7DqraObZRjq30_pi-EupCWIfy5PH7Qv6mnGnW5RR85rMyddhvvX0s2SLbOM6oi0wDBo_BGeDEIeCGboP4hA3FhAvvgfu48dgjGparKilA9tu0mf-MMycFd-3FSzCgs1dAWLxk9_WYS8_XI4OZ6xXjwGlUek0kN2y0eXQlA6fWAR01hAaqYlopNOIkzmIrRReci7A96S8BT96HUFH8qtN3yfh3T7mN5guKXnzSPmVzx1LKp4MkIwycb4O8c1-vv4mczbVaCA",
"cryptosuite": "ecdsa-sd-2023"
}
}

const GS1LicenceCredential: any = {
"@context": [
"https://www.w3.org/2018/credentials/v1",
Expand Down Expand Up @@ -63,6 +127,16 @@ describe("Verifier API Test for Credentials", () => {
expect(res.body[0].verified).toBe(true);
});

/**
* Test selective disclosure DataIntegrityProof credential
*/
test("Verify single DataIntegrityProof credential", async () => {
const res = await request(app).post("/api/verifier").send([SDCredential]);
expect(res.statusCode).toEqual(200);
expect(res.body[0]).toHaveProperty('verified');
expect(res.body[0].verified).toBe(true);
});

test("Verify multiple credentials", async () => {
const res = await request(app).post("/api/verifier").send([GS1LicenceCredential, GS1LicenceCredential]);
expect(res.statusCode).toEqual(200);
Expand All @@ -72,6 +146,19 @@ describe("Verifier API Test for Credentials", () => {
});
});

/**
* Test StatusList2020 revoked credential
*/
test("Verify revoked credential", async () => {
const res = await request(app).post("/api/verifier").send([revokedCredential]);
expect(res.statusCode).toEqual(200);
console.log(res.body)
expect(res.body[0]).toHaveProperty('verified');
expect(res.body[0].verified).toBe(false);
expect(res.body[0]).toHaveProperty('statusResult');
expect(res.body[0].statusResult.verified).toBe(false);
});

test("Falsify single credential", async () => {
const res = await request(app).post("/api/verifier").send([manipulatedCredential]);
expect(res.statusCode).toEqual(200);
Expand Down
104 changes: 104 additions & 0 deletions api/__tests__/presentation.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import request from "supertest";

import app from "../src/index";

const multiPresentation: any = {
"@context": [
"https://www.w3.org/2018/credentials/v1",
"https://w3id.org/security/suites/ed25519-2020/v1"
],
"type": [
"VerifiablePresentation"
],
"verifiableCredential": [
{
"@context": [
"https://www.w3.org/2018/credentials/v1",
"https://ref.gs1.org/gs1/vc/licence-context/",
"https://ssi.eecc.de/api/registry/context",
"https://w3id.org/security/suites/ed25519-2020/v1"
],
"id": "https://ssi.eecc.de/api/registry/vc/e8be5b36-f520-4bdf-ba34-1785b254f0a6",
"type": [
"VerifiableCredential",
"GS1PrefixLicenceCredential"
],
"issuer": {
"id": "did:web:ssi.eecc.de",
"image": "https://id.eecc.de/assets/img/logo_big.png",
"name": "EECC"
},
"issuanceDate": "2023-05-16T11:11:04Z",
"credentialSubject": {
"id": "did:web:ssi.eecc.de",
"partyGLN": "4047111000006",
"licenceValue": "4047111",
"organizationName": "European EPC Competence Center"
},
"proof": {
"type": "Ed25519Signature2020",
"created": "2023-05-16T11:11:04Z",
"proofPurpose": "assertionMethod",
"verificationMethod": "did:web:ssi.eecc.de#z6MkoHWsmSZnHisAxnVdokYHnXaVqWFZ4H33FnNg13zyymxd",
"proofValue": "z4GKxTZzba6B4Bs2vCETRi3frX9vFn9m61ZsNKPaxH9yZBX382DLGY1yRvuKgwbxUag88eJQfALuBdBHhp3m2r5nA"
}
},
{
"@context": [
"https://www.w3.org/2018/credentials/v1",
"https://ref.gs1.org/gs1/vc/licence-context/",
"https://ssi.eecc.de/api/registry/context",
"https://w3id.org/security/suites/ed25519-2020/v1"
],
"id": "https://ssi.eecc.de/api/registry/vc/740fb8fb-b530-4807-8c8f-6e0943581e4c",
"type": [
"VerifiableCredential",
"GS1PrefixLicenceCredential"
],
"issuer": {
"id": "did:web:ssi.eecc.de",
"image": "https://id.eecc.de/assets/img/logo_big.png",
"name": "EECC"
},
"issuanceDate": "2023-05-16T10:49:51Z",
"credentialSubject": {
"id": "did:web:eecc.de",
"partyGLN": "4047111000006",
"organizationName": "European EPC Competence Center",
"licenceValue": "4047111"
},
"proof": {
"type": "Ed25519Signature2020",
"created": "2023-05-16T10:49:51Z",
"proofPurpose": "assertionMethod",
"verificationMethod": "did:web:ssi.eecc.de#z6MkoHWsmSZnHisAxnVdokYHnXaVqWFZ4H33FnNg13zyymxd",
"proofValue": "zmwT31nYTHhecy594pxMCMmuidTAEWsPSZsXAYj84bQfGSDUD8z5uCNy6WfyqwnkG58YQiZAYjevMdw6nBZaPTJ6"
}
}
],
"holder": "did:web:ssi.eecc.de",
"proof": {
"type": "Ed25519Signature2020",
"created": "2023-06-14T14:23:34Z",
"verificationMethod": "did:web:ssi.eecc.de#z6MkoHWsmSZnHisAxnVdokYHnXaVqWFZ4H33FnNg13zyymxd",
"proofPurpose": "authentication",
"challenge": "12345",
"proofValue": "z2aP6o5AeB9sD6N1H26X6bvwcLPjeRpAvBhYo6xixYX7AvieVNFH4K6brZxhdKnXCw7BKYnhf7wfqQTrmGugwL5hr"
}
}

describe("Verifier API Test for Presentations", () => {

test("Verify single presentation", async () => {
const res = await request(app).post("/api/verifier").send([multiPresentation]);
expect(res.statusCode).toEqual(200);
expect(res.body[0]).toHaveProperty('verified');
expect(res.body[0].verified).toBe(true);
expect(res.body[0]).toHaveProperty('credentialResults');
res.body[0].credentialResults.forEach((el: any) => {
expect(el).toHaveProperty('verified');
expect(el.verified).toBe(true);
});
});

});

0 comments on commit a4fecba

Please sign in to comment.