mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
test: Update CTH run to use client credentials
This commit is contained in:
parent
2ec8fabd54
commit
c0bc150122
5
.github/workflows/schedule.yml
vendored
5
.github/workflows/schedule.yml
vendored
@ -38,6 +38,10 @@ jobs:
|
||||
until $(curl --output /dev/null --silent --head --fail -k http://localhost:3000/); do
|
||||
sleep 1
|
||||
done
|
||||
- name: Build test script
|
||||
run: npx tsc -p test/deploy/tsconfig.json
|
||||
- name: Create users
|
||||
run: node test/tmp/cth/createAccountCredentials.js http://localhost:3000/ >> test/deploy/conformance.env
|
||||
- name: Run the test harness
|
||||
run: >
|
||||
docker run -i --rm
|
||||
@ -45,6 +49,7 @@ jobs:
|
||||
--env-file=./test/deploy/conformance.env
|
||||
--network="host"
|
||||
solidproject/conformance-test-harness
|
||||
--skip-teardown
|
||||
--output=/reports
|
||||
--target=https://github.com/solid/conformance-test-harness/css
|
||||
# Steps below use `always()` to make sure logs get uploaded in case the CTH errors
|
||||
|
2
package-lock.json
generated
2
package-lock.json
generated
@ -72,7 +72,7 @@
|
||||
"community-solid-server": "bin/server.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@inrupt/solid-client-authn-core": "^1.11.7",
|
||||
"@inrupt/solid-client-authn-core": "^1.11.5",
|
||||
"@inrupt/solid-client-authn-node": "^1.11.5",
|
||||
"@microsoft/tsdoc-config": "^0.15.2",
|
||||
"@tsconfig/node12": "^1.0.9",
|
||||
|
@ -1,11 +1,6 @@
|
||||
SOLID_IDENTITY_PROVIDER=http://localhost:3000/idp/
|
||||
USER_REGISTRATION_ENDPOINT=http://localhost:3000/idp/register/
|
||||
USERS_ALICE_WEBID=http://localhost:3000/alice/profile/card#me
|
||||
USERS_ALICE_USERNAME=alice@alice.mail
|
||||
USERS_ALICE_PASSWORD=pass1234
|
||||
USERS_BOB_WEBID=http://localhost:3000/bob/profile/card#me
|
||||
USERS_BOB_USERNAME=bob@bob.mail
|
||||
USERS_BOB_PASSWORD=pass1234
|
||||
RESOURCE_SERVER_ROOT=http://localhost:3000
|
||||
TEST_CONTAINER=/alice/
|
||||
quarkus.log.category."ResultLogger".level=INFO
|
||||
|
95
test/deploy/createAccountCredentials.ts
Normal file
95
test/deploy/createAccountCredentials.ts
Normal file
@ -0,0 +1,95 @@
|
||||
#!/usr/bin/env node
|
||||
/* eslint-disable no-console */
|
||||
import fetch from 'cross-fetch';
|
||||
import urljoin from 'url-join';
|
||||
|
||||
if (process.argv.length !== 3) {
|
||||
throw new Error('Exactly 1 parameter is needed: the server URL.');
|
||||
}
|
||||
|
||||
const baseUrl = process.argv[2];
|
||||
|
||||
type User = {
|
||||
email: string;
|
||||
password: string;
|
||||
podName: string;
|
||||
};
|
||||
|
||||
const alice: User = {
|
||||
email: 'alice@example.com',
|
||||
password: 'alice-secret',
|
||||
podName: 'alice',
|
||||
};
|
||||
|
||||
const bob: User = {
|
||||
email: 'bob@example.com',
|
||||
password: 'bob-secret',
|
||||
podName: 'bob',
|
||||
};
|
||||
|
||||
/**
|
||||
* Registers a user with the server.
|
||||
* @param user - The user settings necessary to register a user.
|
||||
*/
|
||||
async function register(user: User): Promise<void> {
|
||||
const body = JSON.stringify({
|
||||
...user,
|
||||
confirmPassword: user.password,
|
||||
createWebId: true,
|
||||
register: true,
|
||||
createPod: true,
|
||||
});
|
||||
const res = await fetch(urljoin(baseUrl, '/idp/register/'), {
|
||||
method: 'POST',
|
||||
headers: { 'content-type': 'application/json' },
|
||||
body,
|
||||
});
|
||||
if (res.status !== 200) {
|
||||
throw new Error(`Registration failed: ${await res.text()}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests a client credentials API token.
|
||||
* @param user - User for which the token needs to be generated.
|
||||
* @returns The id/secret for the client credentials request.
|
||||
*/
|
||||
async function createCredentials(user: User): Promise<{ id: string; secret: string }> {
|
||||
const res = await fetch(urljoin(baseUrl, '/idp/credentials/'), {
|
||||
method: 'POST',
|
||||
headers: { 'content-type': 'application/json' },
|
||||
body: JSON.stringify({ email: user.email, password: user.password, name: 'token' }),
|
||||
});
|
||||
if (res.status !== 200) {
|
||||
throw new Error(`Token generation failed: ${await res.text()}`);
|
||||
}
|
||||
|
||||
return res.json();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates all the necessary data and outputs the necessary lines
|
||||
* that need to be added to the CTH environment file
|
||||
* so it can use client credentials.
|
||||
* @param user - User for which data needs to be generated.
|
||||
*/
|
||||
async function outputCredentials(user: User): Promise<void> {
|
||||
await register(user);
|
||||
const { id, secret } = await createCredentials(user);
|
||||
|
||||
const name = user.podName.toUpperCase();
|
||||
console.log(`USERS_${name}_CLIENTID=${id}`);
|
||||
console.log(`USERS_${name}_CLIENTSECRET=${secret}`);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ends the process and writes out an error in case something goes wrong.
|
||||
*/
|
||||
function endProcess(error: Error): never {
|
||||
console.error(error);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Create tokens for Alice and Bob
|
||||
outputCredentials(alice).catch(endProcess);
|
||||
outputCredentials(bob).catch(endProcess);
|
15
test/deploy/tsconfig.json
Normal file
15
test/deploy/tsconfig.json
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
"extends": "@tsconfig/node12/tsconfig.json",
|
||||
"compilerOptions": {
|
||||
"declaration": true,
|
||||
"inlineSources": true,
|
||||
"newLine": "lf",
|
||||
"outDir": "../tmp/cth",
|
||||
"preserveConstEnums": true,
|
||||
"sourceMap": true,
|
||||
"stripInternal": true
|
||||
},
|
||||
"include": [
|
||||
"createAccountCredentials.ts"
|
||||
]
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user