Skip to content

Commit 7f0fae2

Browse files
committed
add testsuite
1 parent e9fbc1d commit 7f0fae2

File tree

5 files changed

+192
-2
lines changed

5 files changed

+192
-2
lines changed
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ FROM php:8.3-apache
22
LABEL maintainer="[email protected]"
33
RUN apt-get update
44
RUN apt-get install -y ssl-cert
5-
# RUN docker-php-ext-install pdo pdo_sqlite
5+
RUN docker-php-ext-install bcmath
66
RUN a2enmod rewrite allowmethods ssl
77

88
COPY . /opt/solid
9-
COPY solid.conf /etc/apache2/sites-enabled/000-default.conf
9+
COPY ./docker/solid.conf /etc/apache2/sites-enabled/000-default.conf
10+
EXPOSE 443
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
keys/
2+
pods/
3+
db/
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
const BASEDOMAIN = "solid.local";
3+
const BASEURL = "https://" . BASEDOMAIN;
4+
const LIBDIR = __DIR__ . "/lib/";
5+
const KEYDIR = __DIR__ . "/keys/";
6+
const FRONTENDDIR = __DIR__ . "/frontend/";
7+
const DBPATH = __DIR__ . "/db/solid.db";
8+
const CLEANUP_FILE = __DIR__ . "/db/lastcleanup";
9+
10+
const MAILER = [
11+
"host" => "mailpit",
12+
"port" => 1025,
13+
// user
14+
// pass
15+
"from" => "[email protected]"
16+
];
17+
18+
const MAILSTYLES = [
19+
];
20+
21+
const PUBSUB_SERVER = "https://pubsub:8080";
22+
23+
const STORAGEBASE = __DIR__ . "/pods/";
24+
const TRUSTED_IPS = [];
25+
const TRUSTED_APPS = ['https://tester', 'http://localhost:3002'];
26+
27+
const MINIMUM_PASSWORD_ENTROPY = 15;
28+
const BANNED_PASSWORDS = [];

tests/testsuite/init-testsuite.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
require_once(__DIR__ . "/../../config.php");
3+
4+
class TestUser {
5+
private static $pdo;
6+
private static function connect() {
7+
if (!isset(self::$pdo)) {
8+
self::$pdo = new \PDO("sqlite:" . DBPATH);
9+
}
10+
}
11+
12+
public static function createUser($testUser) {
13+
self::connect();
14+
$query = self::$pdo->prepare(
15+
'INSERT INTO users VALUES (:userId, :email, :passwordHash, :data)'
16+
);
17+
18+
$queryParams = [];
19+
$queryParams[':userId'] = $testUser['id'];
20+
$queryParams[':email'] = $testUser['email'];
21+
$queryParams[':passwordHash'] = password_hash($testUser['password'], PASSWORD_BCRYPT);
22+
23+
$testUser['webId'] = "https://id-" . $testUser['id'] . "." . BASEDOMAIN . "/#me";
24+
$queryParams[':data'] = json_encode($testUser);
25+
$query->execute($queryParams);
26+
}
27+
}
28+
29+
TestUser::createUser([
30+
"id" => "alice",
31+
"password" => "alice123",
32+
"email" => "alice"
33+
]);
34+
35+
TestUser::createUser([
36+
"id" => "bob",
37+
"password" => "bob345",
38+
"email" => "bob"
39+
]);
40+
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
# Note that .github/workflows/solid-tests-suites.yml does not use this, this function is just for manual runs of this script.
6+
# You can pick different values for the NEXTCLOUD_VERSION build arg, as required:
7+
function setup {
8+
docker build -t pubsub-server https://github.com/pdsinterop/php-solid-pubsub-server.git#main
9+
docker build -t solid-php -f docker/solid.Dockerfile .
10+
11+
docker network create local
12+
13+
docker pull solidtestsuite/solid-crud-tests:v7.0.5
14+
docker pull solidtestsuite/web-access-control-tests:v7.1.0
15+
docker pull solidtestsuite/webid-provider-tests:v2.1.1
16+
17+
docker tag solidtestsuite/solid-crud-tests:v7.0.5 solid-crud-tests
18+
docker tag solidtestsuite/web-access-control-tests:v7.1.0 web-access-control-tests
19+
docker tag solidtestsuite/webid-provider-tests:v2.1.1 webid-provider-tests
20+
}
21+
22+
function teardown {
23+
docker stop `docker ps --filter network=local -q`
24+
docker rm `docker ps --filter network=local -qa`
25+
docker network remove local
26+
}
27+
28+
function startPubSub {
29+
docker run -d --name pubsub --network=local pubsub-server
30+
}
31+
32+
function startSolidPhp {
33+
docker run -d --name "$1" --network-alias="id-alice.solid" --network-alias="storage-alice.solid" --network-alias="id-bob.solid" --network-alias="storage-bob.solid" --network=local "${2:-solid-php}"
34+
35+
echo "Running init script for Solid PHP $1 ..."
36+
docker exec -w /opt/solid/ "$1" mkdir keys pods db
37+
docker exec -w /opt/solid/ "$1" chown -R www-data:www-data keys pods db
38+
docker exec -w /opt/solid/ "$1" cp tests/testsuite/config.php.testsuite config.php
39+
docker exec -u www-data -i -w /opt/solid/ "$1" php init.php
40+
docker exec -u www-data -i -w /opt/solid/ "$1" php tests/testsuite/init-testsuite.php
41+
42+
export ALICE_COOKIE=`docker exec "$1" curl --output /dev/null --silent --insecure --dump-header - 'https://solid.local/login/password' -X POST -H 'Content-Type: application/x-www-form-urlencoded' --data-raw 'password=alice123&username=alice&response_type=&display=&scope=&client_id=&redirect_uri=&state=&nonce=&request=' |grep Set-Cookie |sort -u |sed -e 's/Set-Cookie: //'|sed -e 's/; expires=.*/; /' |tr -d '\n'`
43+
export BOB_COOKIE=`docker exec "$1" curl --output /dev/null --silent --insecure --dump-header - 'https://solid.local/login/password' -X POST -H 'Content-Type: application/x-www-form-urlencoded' --data-raw 'password=bob345&username=bob&response_type=&display=&scope=&client_id=&redirect_uri=&state=&nonce=&request=' |grep Set-Cookie |sort -u |sed -e 's/Set-Cookie: //'|sed -e 's/; expires=.*/; /' |tr -d '\n'`
44+
}
45+
46+
function runTests {
47+
export RESULTS_PATH=testsuite-results.json
48+
export SKIP_CONC=1
49+
export SKIP_SECURE_WEBSOCKETS=1
50+
export SKIP_WEBHOOKS=1
51+
export NODE_TLS_REJECT_UNAUTHORIZED=0
52+
53+
export PUBSUB=wss://pubsub:8080
54+
55+
export ALICE_SERVER_ROOT=https://solid.local
56+
export ALICE_WEBID=https://id-alice.solid.local/#me
57+
export ALICE_OIDC_ISSUER=https://solid.local
58+
export ALICE_STORAGE_ROOT=https://storage-alice.solid.local
59+
export ALICE_SERVER_ROOT_ESCAPED=https:\/\/solid.local
60+
61+
export BOB_SERVER_ROOT=https://solid.local
62+
export BOB_WEBID=https://id-bob.solid.local/#me
63+
export BOB_OIDC_ISSUER=https://solid.local
64+
export BOB_STORAGE_ROOT=https://storage-bob.solid.local
65+
66+
echo "Alice session cookie: $ALICE_COOKIE"
67+
echo "Bob session cookie: $BOB_COOKIE"
68+
echo "Running $1 tests"
69+
docker run --rm --network=local \
70+
--name tester \
71+
--env RESULTS_PATH="$RESULTS_PATH" \
72+
--env SKIP_CONC="$SKIP_CONC" \
73+
--env SKIP_SECURE_WEBSOCKETS="$SKIP_SECURE_WEBSOCKETS" \
74+
--env SKIP_WEBHOOKS="$SKIP_WEBHOOKS" \
75+
--env NODE_TLS_REJECT_UNAUTHORIZED="$NODE_TLS_REJECT_UNAUTHORIZED" \
76+
--env PUBSUB="$PUBSUB" \
77+
--env ALICE_WEBID="$ALICE_WEBID" \
78+
--env WEBID_ALICE="$ALICE_WEBID" \
79+
--env COOKIE_ALICE="$ALICE_COOKIE" \
80+
--env OIDC_ISSUER_ALICE="$ALICE_OIDC_ISSUER" \
81+
--env STORAGE_ROOT_ALICE="$ALICE_STORAGE_ROOT" \
82+
--env BOB_WEBID="$BOB_WEBID" \
83+
--env WEBID_BOB="$BOB_WEBID" \
84+
--env COOKIE_BOB="$BOB_COOKIE" \
85+
--env OIDC_ISSUER_BOB="$BOB_OIDC_ISSUER" \
86+
--env STORAGE_ROOT_BOB="$BOB_STORAGE_ROOT" \
87+
--env COOKIE="$ALICE_COOKIE" \
88+
--env STORAGE_ROOT="$ALICE_STORAGE_ROOT" \
89+
--env SERVER_ROOT="$ALICE_SERVER_ROOT" \
90+
--env SERVER_ROOT_ECSAPED="$ALICE_SERVER_ROOT_ESCAPED" \
91+
--env SECOND_SERVER_ROOT="$BOB_SERVER_ROOT" \
92+
--env OIDC_ISSUER="$ALICE_OIDC_ISSUER" \
93+
# --env DEBUG=* \
94+
"$1-tests"
95+
}
96+
97+
run_solid_test_suite() {
98+
# ...
99+
teardown || true
100+
setup
101+
startPubSub
102+
startSolidPhp solid
103+
runTests webid-provider
104+
runTests web-access-control
105+
runTests solid-crud
106+
teardown
107+
}
108+
109+
if [ "${BASH_SOURCE[0]}" == "${0}" ]; then
110+
run_solid_test_suite "${@}"
111+
else
112+
export -f run_solid_test_suite
113+
export -f runTests
114+
export -f setup
115+
export -f startPubSub
116+
export -f startSolidPhp
117+
export -f teardown
118+
fi

0 commit comments

Comments
 (0)