Skip to content

Commit

Permalink
First API test
Browse files Browse the repository at this point in the history
Signed-off-by: Felix Hoops <9974641+jfelixh@users.noreply.github.com>
  • Loading branch information
jfelixh committed Aug 26, 2024
1 parent 7d79109 commit 5a71101
Show file tree
Hide file tree
Showing 7 changed files with 191 additions and 12 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Credentials from a mobile wallet. But building that takes considerable time and
expertise.

<!-- prettier-ignore -->
> [!NOTE]
> [!NOTE]
> As a new feature, the bridge now supports incremental authorization.
> This allows the service provider to request additional Verifiable Credentials
> from the user via the bridge. Please see the
Expand Down Expand Up @@ -196,15 +196,15 @@ dynamic API endpoints. The API is documented using Swagger, which provides a
user-friendly interface to explore and test the API.

<!-- prettier-ignore -->
> [!NOTE]
> [!NOTE]
> To access the Swagger documentation, you need to run the bridge in development mode and
> navigate to `http://localhost:5002/api-docs`.
To authenticate requests to the dynamic API in Swagger, you need to provide a
valid API key. The API key is stored in the `.env` file in the `vclogin` folder.

<!-- prettier-ignore -->
> [!NOTE]
> [!NOTE]
> To authenticate requests to the dynamic API in Swagger, first click on
> the "Authorize" button in the top right corner of the Swagger UI. Then, enter
> the API key in the "Value" field with the format `API_KEY <api_key>`and click
Expand Down Expand Up @@ -327,7 +327,7 @@ refer to the end of the previous section.

## Running Tests

This repository includes unit tests with `jest` and end-to-end tests with
This repository includes unit tests with `vitest` and end-to-end tests with
`playwright`. You may run them as follows:

```bash
Expand Down Expand Up @@ -490,18 +490,18 @@ authorization. An example of such a policy file is:
```

<!-- prettier-ignore -->
> [!IMPORTANT]
> [!IMPORTANT]
> Each `credentialId` should be unique across all policy objects,
> and should have integer string values starting from 1, incrementing by 1 for each subsequent policy object. This helps us determine
> the correct policy object to apply to the VCs.
<!-- prettier-ignore -->
> [!IMPORTANT]
> [!IMPORTANT]
> Altough the `type` field is an optional parameter, it needs to be
> present in a policy file that has multiple policy objects. This is crucial for the accurate application of policies.
<!-- prettier-ignore -->
> [!NOTE]
> [!NOTE]
> First we reorder the policy objects in a policy file based on the `credentialId` and
> then we reorder the credentials in the VP based on the `type` field from the reordered policy file.
> This ensures that each credential is matched with the correct policy object.
Expand Down Expand Up @@ -576,7 +576,7 @@ below, the first VC's `credentialSubject.id` is compared with the second VC's
`credentialSubject.id` in the second policy object.

<!-- prettier-ignore -->
> [!IMPORTANT]
> [!IMPORTANT]
> You need to correctly define the JSONPaths of the constraint
> operands to be able to perform constraints check. The JSONPaths should have a
> structure like `$<credentialId>.<claimPath>` when having multiple policy
Expand Down
1 change: 1 addition & 0 deletions vclogin/.env.test
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
LOGIN_POLICY=./__tests__/testdata/policies/acceptAnything.json
DID_KEY_JWK={"kty":"OKP","crv":"Ed25519","x":"cwa3dufHNLg8aQb2eEUqTyoM1cKQW3XnOkMkj_AAl5M","d":"me03qhLByT-NKrfXDeji-lpADSpVOKWoaMUzv5EyzKY"}
EXTERNAL_URL=http://example.com
40 changes: 40 additions & 0 deletions vclogin/__tests__/unit/pages/api/clientMetadata.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* Copyright 2024 Software Engineering for Business Information Systems (sebis) <matthes@tum.de> .
* SPDX-License-Identifier: MIT
*/

import { describe, it, expect } from "vitest";
import { createMocks } from "node-mocks-http";
import handler from "@/api/clientMetadata";
import type { NextApiRequest, NextApiResponse } from "next";

describe("/api/clientMetadata", () => {
const mockRequest = () => {
const { req, res } = createMocks<NextApiRequest, NextApiResponse>({
method: "GET",
url: "api/clientMetadata",
});
return { req, res };
};

it("returns 200 OK", async () => {
const { req, res } = mockRequest();

await handler(req, res);

expect(res.statusCode).toBe(200);
});

it("returns valid JSON", async () => {
const { req, res } = mockRequest();

await handler(req, res);

expect(res._isJSON()).toBe(true);
expect(res._getJSONData()).toEqual(
expect.objectContaining({
client_name: "SSI-to-OIDC Bridge",
}),
);
});
});
2 changes: 1 addition & 1 deletion vclogin/lib/getMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export const getMetadata = (redirect_uris: string[]) => {
],
subject_trust_frameworks_supported: ["ebsi"],
id_token_types_supported: ["subject_signed_id_token"],
client_name: "VP Login Service",
client_name: "SSI-to-OIDC Bridge",
request_uri_parameter_supported: true,
request_parameter_supported: false,
redirect_uris,
Expand Down
142 changes: 139 additions & 3 deletions vclogin/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vclogin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"eslint": "8.38.0",
"eslint-config-next": "13.3.0",
"eslint-plugin-react-hooks": "^4.6.0",
"node-mocks-http": "^1.15.1",
"postcss": "^8.4.39",
"prettier": "^2.8.8",
"swagger-ui": "^5.17.14",
Expand Down
1 change: 1 addition & 0 deletions vclogin/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"paths": {
"@/testdata/*": ["__tests__/testdata/*"],
"@/lib/*": ["lib/*"],
"@/api/*": ["pages/api/*"],
"@/config/*": ["config/*"],
"@/types/*": ["types/*"],
"@/pages/*": ["pages/*"],
Expand Down

0 comments on commit 5a71101

Please sign in to comment.