Skip to content

Commit f993adb

Browse files
First tests, passing against NSS
1 parent e858214 commit f993adb

24 files changed

+7256
-3
lines changed

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v14

Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM node
2+
RUN apt-get update && apt-get install -yq \
3+
vim \
4+
&& apt-get clean
5+
ADD . /app
6+
WORKDIR /app
7+
RUN npm install
8+
ENV NODE_TLS_REJECT_UNAUTHORIZED 0
9+
CMD npm run jest

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2021 Solid
3+
Copyright (c) 2020 Solid
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,35 @@
1-
# monetization-tests
2-
Tests around https://github.com/solid/webmonetization
1+
# WAC Tests
2+
Surface tests for CRUD and Websockets-pubsub functionality of a pod server
3+
4+
## Usage
5+
### In development
6+
Start your server with a self-signed cert on port 443 of localhost (for node-solid-server, make sure to set `ACL_CACHE_TIME=5`) and run `sh ./example.sh`.
7+
8+
### Against CSS
9+
In one terminal window:
10+
* check out the https://github.com/solid/community-server repo locally, and run `npm ci; npm run build`
11+
* find the function `isRSAPublicJWK(x)` in node_modules/@solid/dist/identity-token-verifier/dist/guards/DPoPJWKGuard.js and add `x.alg = 'RS256'` at the top of that function, to work around a bug in NSS v5.6.4, caused by https://github.com/solid/oidc-op/issues/29.
12+
* ./bin/server.js -l debug
13+
14+
In another terminal window:
15+
* check out this repo from https://github.com/solid/web-access-control-tests and run `npm ci`
16+
* check out the `run-against-css` branch
17+
* simple test (sets a root ACL doc from node and reads it back):
18+
- run `node ./setup.js http://localhost:3000/.acl` to create a root ACL at http://localhost:3000/.acl which gives https://solidtestsuite.solidcommunity.net/profile/card#me full read/write/control access.
19+
- run `node ./fetch.js http://localhost:3000/.acl` to check that Alice ('solidtestsuite') can access it.
20+
- run `node ./fetch-bob.js http://localhost:3000/.acl` to check that Bob ('solid-crud-tests-example-2') can *not* access it.
21+
* advanced test (uses the same root ACL doc, but from bash): `bash ./run-against-css.sh`
22+
23+
You can also cut-and-paste the lines from run-against-css.sh into your bash shell, then you can more easily run tests interactively.
24+
25+
### Against CSS with local NSS instance as the IDP
26+
If you want to use your NSS on localhost instead of on solidcommunity.net, then:
27+
* Run NSS on localhost, in multi-user mode so you can support both Alice and Bob
28+
* You may need to set up alice.localhost in your /etc/hosts, but on Mac that is automatic.
29+
* Browse to https://localhost:8443/ with Firefox and say you accept the self-signed cert (with Chrome the use of self-signed certs has become harder and harder recently)
30+
* Set up a user, alice / 123, and edit ./fetch.js so that `oidcIssuer = 'https://localhost:8443';`, `nssUsername = 'alice'`, and `nssPassword = '123';`.
31+
* Run CSS with `NODE_TLS_REJECT_UNAUTHORIZED=0 ./bin/server.js -l debug`.
32+
* Run the fetch script with `NODE_TLS_REJECT_UNAUTHORIZED=0` as well, for instance:
33+
```sh
34+
NODE_TLS_REJECT_UNAUTHORIZED=0 node fetch.js http://localhost:3000/404.txt
35+
```

debug.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
export function log (...args: any[]) {
2+
// eslint-disable-next-line no-console
3+
console.log(...args)
4+
}
5+
6+
export function warn (...args: any[]) {
7+
// eslint-disable-next-line no-console
8+
console.warn(...args)
9+
}
10+
11+
export function error (...args: any[]) {
12+
// eslint-disable-next-line no-console
13+
console.error(...args)
14+
}
15+
16+
export function trace (...args: any[]) {
17+
// eslint-disable-next-line no-console
18+
console.trace(...args)
19+
}

example.sh

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/bin/bash
2+
set -e
3+
4+
# either test against a local server or in a container testnet
5+
#export SERVER_ROOT=https://localhost
6+
export SERVER_ROOT=https://server
7+
export USERNAME_ALICE=alice
8+
export PASSWORD_ALICE=123
9+
10+
export SERVER2_ROOT=https://solidcommunity.net
11+
export USERNAME_BOB=solid-crud-tests-example-1
12+
export BOB_ROOT=https://$USERNAME_BOB.solidcommunity.net
13+
export PASSWORD_BOB=123
14+
15+
export RESULTS_PATH=../NSS-wac-results.json
16+
17+
echo Automated way to get an OIDC issuer cookie for Alice:
18+
export CURL_RESULT_ALICE=`curl -ki $SERVER_ROOT/login/password -d"username=$USERNAME_ALICE&password=$PASSWORD_ALICE" | grep Set-Cookie`
19+
export COOKIE_ALICE=`expr "$CURL_RESULT_ALICE" : '^Set-Cookie:\ \(.*\).'`
20+
21+
echo Other env vars for Alice:
22+
export OIDC_ISSUER_ALICE=$SERVER_ROOT
23+
export WEBID_ALICE=$SERVER_ROOT/profile/card#me
24+
export STORAGE_ROOT_ALICE=$SERVER_ROOT/
25+
26+
echo Automated way to get an OIDC issuer cookie for Bob:
27+
export CURL_RESULT_BOB=`curl -ki $SERVER2_ROOT/login/password -d"username=$USERNAME_BOB&password=$PASSWORD_BOB" | grep Set-Cookie`
28+
export COOKIE_BOB=`expr "$CURL_RESULT_BOB" : '^Set-Cookie:\ \(.*\).'`
29+
30+
echo Other env vars for Bob:
31+
export OIDC_ISSUER_BOB=$SERVER2_ROOT
32+
export WEBID_BOB=$BOB_ROOT/profile/card#me
33+
export STORAGE_ROOT_BOB=$BOB_ROOT/
34+
35+
echo Running with these values for Alice:
36+
echo Cookie: $COOKIE_ALICE
37+
echo OIDC issuer: $OIDC_ISSUER_ALICE
38+
echo WebID: $WEBID_ALICE
39+
echo Storage Root: $STORAGE_ROOT_ALICE
40+
41+
echo Running with these values for Bob:
42+
echo Cookie: $COOKIE_BOB
43+
echo OIDC issuer: $OIDC_ISSUER_BOB
44+
echo WebID: $WEBID_BOB
45+
echo Storage Root: $STORAGE_ROOT_BOB
46+
47+
export NODE_TLS_REJECT_UNAUTHORIZED=0
48+
49+
# npm run jest "$@"
50+
npm run jest -- --json --outputFile="$RESULTS_PATH" "$@"

fetch-bob.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const fetch = require('node-fetch');
2+
const { getAuthFetcher, getNodeSolidServerCookie } = require('solid-auth-fetcher');
3+
4+
const oidcIssuer = 'https://solidcommunity.net';
5+
const nssUsername = 'solid-crud-tests-example-2';
6+
const nssPassword = '123';
7+
const origin = 'https://tester';
8+
9+
async function run(url) {
10+
console.log('Getting cookie', { oidcIssuer, nssUsername, nssPassword });
11+
const cookie = await getNodeSolidServerCookie(oidcIssuer, nssUsername, nssPassword);
12+
console.log('Getting fetcher', { oidcIssuer, cookie, origin });
13+
const fetcher = await getAuthFetcher(oidcIssuer, cookie, origin);
14+
console.log('Fetching', { url });
15+
const result = await fetcher.fetch(url);
16+
console.log(result.status, await result.text());
17+
for (let pair of result.headers.entries()) {
18+
console.log(`Response header: ${pair[0]}: ${pair[1]}`);
19+
}
20+
}
21+
22+
// ...
23+
run(process.argv[2]);

fetch.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
const fetch = require('node-fetch');
2+
const { getAuthFetcher, getNodeSolidServerCookie } = require('solid-auth-fetcher');
3+
4+
const oidcIssuer = 'https://solidcommunity.net';
5+
const nssUsername = 'solidtestsuite';
6+
const nssPassword = 'Testing123';
7+
const origin = 'https://tester';
8+
9+
async function run(url) {
10+
console.log('Getting cookie', { oidcIssuer, nssUsername, nssPassword });
11+
const cookie = await getNodeSolidServerCookie(oidcIssuer, nssUsername, nssPassword);
12+
console.log('Getting fetcher', { oidcIssuer, cookie, origin });
13+
const fetcher = await getAuthFetcher(oidcIssuer, cookie, origin);
14+
console.log('Fetching', { url });
15+
const result = await fetcher.fetch(url);
16+
console.log(result.status, await result.text());
17+
for (let pair of result.headers.entries()) {
18+
console.log(`Response header: ${pair[0]}: ${pair[1]}`);
19+
}
20+
}
21+
22+
// ...
23+
run(process.argv[2]);

jest.config.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
module.exports = {
2+
roots: [
3+
"<rootDir>/test",
4+
],
5+
preset: 'ts-jest',
6+
testEnvironment: 'node',
7+
verbose: false,
8+
collectCoverage: false,
9+
testTimeout: 10000,
10+
globals: {
11+
'ts-jest': {
12+
// reference: https://kulshekhar.github.io/ts-jest/user/config/
13+
}
14+
}
15+
};

0 commit comments

Comments
 (0)