Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDK-3304: Initial end-to-end tests #188

Merged
merged 6 commits into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions .github/workflows/e2e-node.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: End-to-end Tests (Node)

on:
push:
# Allow manual triggering, e.g. to run end-to-end tests against Dependabot PRs:
workflow_dispatch:

env:
CI: true
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
e2e-node:
runs-on: ${{ matrix.os }}
environment:
name: ${{ matrix.environment-name }}
continue-on-error: ${{ matrix.experimental }}
strategy:
matrix:
os: [ubuntu-latest]
node-version: ["20.x", "18.x"]
# PodSpaces doesn't support error descriptions yet.
environment-name: ["ESS Dev-2-3"]
experimental: [false]
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: "npm"
cache-dependency-path: "**/package-lock.json"

- name: Install dependencies
run: npm ci

- run: npm run test:e2e:node
env:
E2E_TEST_IDP: ${{ secrets.E2E_TEST_IDP }}
E2E_TEST_ENVIRONMENT: ${{ matrix.environment-name }}
E2E_TEST_OWNER_CLIENT_ID: ${{ secrets.E2E_TEST_OWNER_CLIENT_ID }}
E2E_TEST_OWNER_CLIENT_SECRET: ${{ secrets.E2E_TEST_OWNER_CLIENT_SECRET }}
10 changes: 10 additions & 0 deletions e2e/env/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Select environment (see @inrupt/internal-test-env for a list of available environments)
E2E_TEST_ENVIRONMENT="Inrupt Production"
E2E_TEST_IDP=https://login.inrupt.com

# The following environment variables should be kept in a .env.test.local file
# Obtain credentials via https://login.inrupt.com/registration.html
E2E_TEST_CLIENT_ID="<client-id>"
E2E_TEST_CLIENT_SECRET="<client-secret>"
E2E_TEST_USER="<username>"
E2E_TEST_PASSWORD="<password>"
NSeydoux marked this conversation as resolved.
Show resolved Hide resolved
124 changes: 124 additions & 0 deletions e2e/node/error.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
//
// Copyright Inrupt Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal in
// the Software without restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
// Software, and to permit persons to whom the Software is furnished to do so,
// subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
// PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
import {
describe,
it,
expect,
jest,
beforeEach,
afterEach,
} from "@jest/globals";
import { custom } from "openid-client";
import { config } from "dotenv";
import { join } from "path";

import {
getNodeTestingEnvironment,
getPodRoot,
} from "@inrupt/internal-test-env";
import { Session } from "@inrupt/solid-client-authn-node";

import {
NotAcceptableError,
NotFoundError,
UnauthorizedError,
handleErrorResponse,
} from "../../src/index";

custom.setHttpOptionsDefaults({
timeout: 15000,
});

if (process.env.CI === "true") {
// Tests running in the CI runners tend to be more flaky.
jest.retryTimes(3, { logErrorsBeforeRetry: true });
} else {
// Load .env.local file
config({ path: join("..", "env", ".env.local") });
}

const ENV = getNodeTestingEnvironment();
const { owner } = ENV.clientCredentials;

describe(`End-to-end error description test for ${ENV.environment}`, () => {
const authenticatedSession = new Session({ keepAlive: false });

beforeEach(async () => {
await authenticatedSession.login({
clientId: owner.id,
clientSecret: owner.secret,
oidcIssuer: ENV.idp,
});
});

afterEach(async () => {
await authenticatedSession.logout();
});

it("returns an RFC9457 error response for unauthenticated requests", async () => {
const podRoot = await getPodRoot(authenticatedSession);
// This unauthenticated fetch should get a 401 response.
const response = await fetch(podRoot);
const responseBody = await response.text();
const error = handleErrorResponse(
response,
responseBody,
"Some error message",
);
expect(error).toBeInstanceOf(UnauthorizedError);
expect(error.problemDetails.detail).toBeDefined();
expect(error.problemDetails.instance).toBeDefined();
});

it("returns an RFC9457 error response for not found resources", async () => {
const podRoot = await getPodRoot(authenticatedSession);
const response = await authenticatedSession.fetch(
new URL("some-missing-resource", podRoot),
);
const responseBody = await response.text();
const error = handleErrorResponse(
response,
responseBody,
"Some error message",
);
expect(error).toBeInstanceOf(NotFoundError);
expect(error.problemDetails.detail).toBeDefined();
expect(error.problemDetails.instance).toBeDefined();
});

it("returns an RFC9457 error response for not acceptable content negotiation", async () => {
const podRoot = await getPodRoot(authenticatedSession);
const response = await authenticatedSession.fetch(podRoot, {
headers: {
Accept: "text/csv",
},
});
const responseBody = await response.text();
const error = handleErrorResponse(
response,
responseBody,
"Some error message",
);
expect(error).toBeInstanceOf(NotAcceptableError);
expect(error.problemDetails.detail).toBeDefined();
expect(error.problemDetails.instance).toBeDefined();
});
});
4 changes: 3 additions & 1 deletion package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@
"@inrupt/eslint-config-lib": "^3.0.1",
"@inrupt/internal-test-env": "^3.2.1",
"@inrupt/jest-jsdom-polyfills": "^3.2.1",
"@inrupt/solid-client-authn-node": "^2.2.4",
"@typescript-eslint/eslint-plugin": "^7.14.1",
"@typhonjs-typedoc/ts-lib-docs": "^2023.7.12",
"dotenv": "^16.4.5",
"eslint": "^8.57.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-jest": "^28.6.0",
Expand Down