@ldo/test-solid-server 1.0.0-alpha.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.txt +21 -0
- package/Readme.md +17 -0
- package/dist/authFetch.d.ts +2 -0
- package/dist/authFetch.d.ts.map +1 -0
- package/dist/authFetch.js +100 -0
- package/dist/authFetch.js.map +1 -0
- package/dist/configs/configs/server-config-without-websocket.json +44 -0
- package/dist/configs/configs/server-config.json +43 -0
- package/dist/configs/configs/solid-css-seed.json +9 -0
- package/dist/configs/server-config-without-websocket.json +44 -0
- package/dist/configs/server-config.json +43 -0
- package/dist/configs/solid-css-seed.json +9 -0
- package/dist/createServer.d.ts +3 -0
- package/dist/createServer.d.ts.map +1 -0
- package/dist/createServer.js +27 -0
- package/dist/createServer.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/resourceUtils.d.ts +18 -0
- package/dist/resourceUtils.d.ts.map +1 -0
- package/dist/resourceUtils.js +37 -0
- package/dist/resourceUtils.js.map +1 -0
- package/dist/setupTestServer.d.ts +10 -0
- package/dist/setupTestServer.d.ts.map +1 -0
- package/dist/setupTestServer.js +40 -0
- package/dist/setupTestServer.js.map +1 -0
- package/package.json +37 -0
- package/src/authFetch.ts +121 -0
- package/src/configs/server-config-without-websocket.json +44 -0
- package/src/configs/server-config.json +43 -0
- package/src/configs/solid-css-seed.json +9 -0
- package/src/createServer.ts +33 -0
- package/src/index.ts +3 -0
- package/src/resourceUtils.ts +75 -0
- package/src/setupTestServer.ts +71 -0
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Jackson Morgan
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/Readme.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# @ldo/test-solid-server
|
|
2
|
+
|
|
3
|
+
This is a reusable Solid Server to be used in Jest integration tests.
|
|
4
|
+
|
|
5
|
+
## Setup
|
|
6
|
+
|
|
7
|
+
Install cross-env
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
npm i --save-dev cross-env
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Use the following to run your tests
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
"test": "cross-env NODE_OPTIONS=--experimental-vm-modules jest --coverage",
|
|
17
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authFetch.d.ts","sourceRoot":"","sources":["../src/authFetch.ts"],"names":[],"mappings":"AAmHA,wBAAsB,iBAAiB,CAAC,IAAI,EAAE,MAAM,oCAKnD"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { buildAuthenticatedFetch, createDpopHeader, generateDpopKeyPair, } from "@inrupt/solid-client-authn-core";
|
|
2
|
+
import fetch from "cross-fetch";
|
|
3
|
+
const config = {
|
|
4
|
+
podName: "example",
|
|
5
|
+
email: "hello@example.com",
|
|
6
|
+
password: "abc123",
|
|
7
|
+
};
|
|
8
|
+
async function reportError(response) {
|
|
9
|
+
if (response.status >= 400) {
|
|
10
|
+
console.error(await response.text());
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
async function getAuthorization(port) {
|
|
14
|
+
// First we request the account API controls to find out where we can log in
|
|
15
|
+
const indexResponse = await fetch(`http://localhost:${port}/.account/`);
|
|
16
|
+
const { controls } = await indexResponse.json();
|
|
17
|
+
// And then we log in to the account API
|
|
18
|
+
const response = await fetch(controls.password.login, {
|
|
19
|
+
method: "POST",
|
|
20
|
+
headers: { "content-type": "application/json" },
|
|
21
|
+
body: JSON.stringify({
|
|
22
|
+
email: config.email,
|
|
23
|
+
password: config.password,
|
|
24
|
+
}),
|
|
25
|
+
});
|
|
26
|
+
// This authorization value will be used to authenticate in the next step
|
|
27
|
+
await reportError(response);
|
|
28
|
+
const result = await response.json();
|
|
29
|
+
return result.authorization;
|
|
30
|
+
}
|
|
31
|
+
async function getSecret(port, authorization) {
|
|
32
|
+
// Now that we are logged in, we need to request the updated controls from the server.
|
|
33
|
+
// These will now have more values than in the previous example.
|
|
34
|
+
const indexResponse = await fetch(`http://localhost:${port}/.account/`, {
|
|
35
|
+
headers: { authorization: `CSS-Account-Token ${authorization}` },
|
|
36
|
+
});
|
|
37
|
+
const { controls } = await indexResponse.json();
|
|
38
|
+
// Here we request the server to generate a token on our account
|
|
39
|
+
const response = await fetch(controls.account.clientCredentials, {
|
|
40
|
+
method: "POST",
|
|
41
|
+
headers: {
|
|
42
|
+
authorization: `CSS-Account-Token ${authorization}`,
|
|
43
|
+
"content-type": "application/json",
|
|
44
|
+
},
|
|
45
|
+
// The name field will be used when generating the ID of your token.
|
|
46
|
+
// The WebID field determines which WebID you will identify as when using the token.
|
|
47
|
+
// Only WebIDs linked to your account can be used.
|
|
48
|
+
body: JSON.stringify({
|
|
49
|
+
name: "my-token",
|
|
50
|
+
webId: `http://localhost:${port}/${config.podName}/profile/card#me`,
|
|
51
|
+
}),
|
|
52
|
+
});
|
|
53
|
+
await reportError(response);
|
|
54
|
+
// These are the identifier and secret of your token.
|
|
55
|
+
// Store the secret somewhere safe as there is no way to request it again from the server!
|
|
56
|
+
// The `resource` value can be used to delete the token at a later point in time.
|
|
57
|
+
const response2 = await response.json();
|
|
58
|
+
return response2;
|
|
59
|
+
}
|
|
60
|
+
async function getAccessToken(port, id, secret) {
|
|
61
|
+
try {
|
|
62
|
+
// A key pair is needed for encryption.
|
|
63
|
+
// This function from `solid-client-authn` generates such a pair for you.
|
|
64
|
+
const dpopKey = await generateDpopKeyPair();
|
|
65
|
+
// These are the ID and secret generated in the previous step.
|
|
66
|
+
// Both the ID and the secret need to be form-encoded.
|
|
67
|
+
const authString = `${encodeURIComponent(id)}:${encodeURIComponent(secret)}`;
|
|
68
|
+
// This URL can be found by looking at the "token_endpoint" field at
|
|
69
|
+
// http://localhost:PORT/.well-known/openid-configuration
|
|
70
|
+
// if your server is hosted at http://localhost:3000/.
|
|
71
|
+
const tokenUrl = `http://localhost:${port}/.oidc/token`;
|
|
72
|
+
const response = await fetch(tokenUrl, {
|
|
73
|
+
method: "POST",
|
|
74
|
+
headers: {
|
|
75
|
+
// The header needs to be in base64 encoding.
|
|
76
|
+
authorization: `Basic ${Buffer.from(authString).toString("base64")}`,
|
|
77
|
+
"content-type": "application/x-www-form-urlencoded",
|
|
78
|
+
dpop: await createDpopHeader(tokenUrl, "POST", dpopKey),
|
|
79
|
+
},
|
|
80
|
+
body: "grant_type=client_credentials&scope=webid",
|
|
81
|
+
});
|
|
82
|
+
await reportError(response);
|
|
83
|
+
// This is the Access token that will be used to do an authenticated request to the server.
|
|
84
|
+
// The JSON also contains an "expires_in" field in seconds,
|
|
85
|
+
// which you can use to know when you need request a new Access token.
|
|
86
|
+
const response2 = await response.json();
|
|
87
|
+
return { accessToken: response2.access_token, dpopKey };
|
|
88
|
+
}
|
|
89
|
+
catch (err) {
|
|
90
|
+
console.error(err);
|
|
91
|
+
throw err;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
export async function generateAuthFetch(port) {
|
|
95
|
+
const authorization = await getAuthorization(port);
|
|
96
|
+
const { id, secret } = await getSecret(port, authorization);
|
|
97
|
+
const { accessToken, dpopKey } = await getAccessToken(port, id, secret);
|
|
98
|
+
return await buildAuthenticatedFetch(accessToken, { dpopKey });
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=authFetch.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authFetch.js","sourceRoot":"","sources":["../src/authFetch.ts"],"names":[],"mappings":"AACA,OAAO,EACL,uBAAuB,EACvB,gBAAgB,EAChB,mBAAmB,GACpB,MAAM,iCAAiC,CAAC;AACzC,OAAO,KAAK,MAAM,aAAa,CAAC;AAEhC,MAAM,MAAM,GAAG;IACb,OAAO,EAAE,SAAS;IAClB,KAAK,EAAE,mBAAmB;IAC1B,QAAQ,EAAE,QAAQ;CACnB,CAAC;AAEF,KAAK,UAAU,WAAW,CAAC,QAAkB;IAC3C,IAAI,QAAQ,CAAC,MAAM,IAAI,GAAG,EAAE,CAAC;QAC3B,OAAO,CAAC,KAAK,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;IACvC,CAAC;AACH,CAAC;AAED,KAAK,UAAU,gBAAgB,CAAC,IAAY;IAC1C,4EAA4E;IAC5E,MAAM,aAAa,GAAG,MAAM,KAAK,CAAC,oBAAoB,IAAI,YAAY,CAAC,CAAC;IACxE,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,aAAa,CAAC,IAAI,EAAE,CAAC;IAEhD,wCAAwC;IAC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ACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,IAAY;IAClD,MAAM,aAAa,GAAG,MAAM,gBAAgB,CAAC,IAAI,CAAC,CAAC;IACnD,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,MAAM,SAAS,CAAC,IAAI,EAAE,aAAa,CAAC,CAAC;IAC5D,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,GAAG,MAAM,cAAc,CAAC,IAAI,EAAE,EAAE,EAAE,MAAM,CAAC,CAAC;IACxE,OAAO,MAAM,uBAAuB,CAAC,WAAW,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC;AACjE,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"@context": "https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/^7.0.0/components/context.jsonld",
|
|
3
|
+
"import": [
|
|
4
|
+
"css:config/app/init/initialize-root.json",
|
|
5
|
+
"css:config/app/main/default.json",
|
|
6
|
+
"css:config/app/variables/default.json",
|
|
7
|
+
"css:config/http/handler/default.json",
|
|
8
|
+
"css:config/http/middleware/default.json",
|
|
9
|
+
"css:config/http/notifications/webhooks.json",
|
|
10
|
+
"css:config/http/server-factory/http.json",
|
|
11
|
+
"css:config/http/static/default.json",
|
|
12
|
+
"css:config/identity/access/public.json",
|
|
13
|
+
"css:config/identity/email/default.json",
|
|
14
|
+
"css:config/identity/handler/no-accounts.json",
|
|
15
|
+
"css:config/identity/oidc/default.json",
|
|
16
|
+
"css:config/identity/ownership/token.json",
|
|
17
|
+
"css:config/identity/pod/static.json",
|
|
18
|
+
"css:config/ldp/authentication/dpop-bearer.json",
|
|
19
|
+
"css:config/ldp/authorization/webacl.json",
|
|
20
|
+
"css:config/ldp/handler/default.json",
|
|
21
|
+
"css:config/ldp/metadata-parser/default.json",
|
|
22
|
+
"css:config/ldp/metadata-writer/default.json",
|
|
23
|
+
"css:config/ldp/modes/default.json",
|
|
24
|
+
"css:config/storage/backend/file.json",
|
|
25
|
+
"css:config/storage/key-value/resource-store.json",
|
|
26
|
+
"css:config/storage/location/root.json",
|
|
27
|
+
"css:config/storage/middleware/default.json",
|
|
28
|
+
"css:config/util/auxiliary/acl.json",
|
|
29
|
+
"css:config/util/identifiers/suffix.json",
|
|
30
|
+
"css:config/util/index/default.json",
|
|
31
|
+
"css:config/util/logging/winston.json",
|
|
32
|
+
"css:config/util/representation-conversion/default.json",
|
|
33
|
+
"css:config/util/resource-locker/file.json",
|
|
34
|
+
"css:config/util/variables/default.json"
|
|
35
|
+
],
|
|
36
|
+
"@graph": [
|
|
37
|
+
{
|
|
38
|
+
"comment": [
|
|
39
|
+
"A Solid server that stores its resources on disk and uses WAC for authorization.",
|
|
40
|
+
"No registration and the root container is initialized to allow full access for everyone so make sure to change this."
|
|
41
|
+
]
|
|
42
|
+
}
|
|
43
|
+
]
|
|
44
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"@context": [
|
|
3
|
+
"https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/^7.0.0/components/context.jsonld"
|
|
4
|
+
],
|
|
5
|
+
"import": [
|
|
6
|
+
"css:config/app/init/static-root.json",
|
|
7
|
+
"css:config/app/main/default.json",
|
|
8
|
+
"css:config/app/variables/default.json",
|
|
9
|
+
"css:config/http/handler/default.json",
|
|
10
|
+
"css:config/http/middleware/default.json",
|
|
11
|
+
"css:config/http/notifications/all.json",
|
|
12
|
+
"css:config/http/server-factory/http.json",
|
|
13
|
+
"css:config/http/static/default.json",
|
|
14
|
+
"css:config/identity/access/public.json",
|
|
15
|
+
"css:config/identity/email/default.json",
|
|
16
|
+
"css:config/identity/handler/default.json",
|
|
17
|
+
"css:config/identity/oidc/default.json",
|
|
18
|
+
"css:config/identity/ownership/token.json",
|
|
19
|
+
"css:config/identity/pod/static.json",
|
|
20
|
+
"css:config/ldp/authentication/dpop-bearer.json",
|
|
21
|
+
"css:config/ldp/authorization/webacl.json",
|
|
22
|
+
"css:config/ldp/handler/default.json",
|
|
23
|
+
"css:config/ldp/metadata-parser/default.json",
|
|
24
|
+
"css:config/ldp/metadata-writer/default.json",
|
|
25
|
+
"css:config/ldp/modes/default.json",
|
|
26
|
+
"css:config/storage/backend/memory.json",
|
|
27
|
+
"css:config/storage/key-value/resource-store.json",
|
|
28
|
+
"css:config/storage/location/pod.json",
|
|
29
|
+
"css:config/storage/middleware/default.json",
|
|
30
|
+
"css:config/util/auxiliary/acl.json",
|
|
31
|
+
"css:config/util/identifiers/suffix.json",
|
|
32
|
+
"css:config/util/index/default.json",
|
|
33
|
+
"css:config/util/logging/winston.json",
|
|
34
|
+
"css:config/util/representation-conversion/default.json",
|
|
35
|
+
"css:config/util/resource-locker/memory.json",
|
|
36
|
+
"css:config/util/variables/default.json"
|
|
37
|
+
],
|
|
38
|
+
"@graph": [
|
|
39
|
+
{
|
|
40
|
+
"comment": "A Solid server that stores its resources on disk and uses WAC for authorization."
|
|
41
|
+
}
|
|
42
|
+
]
|
|
43
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"@context": "https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/^7.0.0/components/context.jsonld",
|
|
3
|
+
"import": [
|
|
4
|
+
"css:config/app/init/initialize-root.json",
|
|
5
|
+
"css:config/app/main/default.json",
|
|
6
|
+
"css:config/app/variables/default.json",
|
|
7
|
+
"css:config/http/handler/default.json",
|
|
8
|
+
"css:config/http/middleware/default.json",
|
|
9
|
+
"css:config/http/notifications/webhooks.json",
|
|
10
|
+
"css:config/http/server-factory/http.json",
|
|
11
|
+
"css:config/http/static/default.json",
|
|
12
|
+
"css:config/identity/access/public.json",
|
|
13
|
+
"css:config/identity/email/default.json",
|
|
14
|
+
"css:config/identity/handler/no-accounts.json",
|
|
15
|
+
"css:config/identity/oidc/default.json",
|
|
16
|
+
"css:config/identity/ownership/token.json",
|
|
17
|
+
"css:config/identity/pod/static.json",
|
|
18
|
+
"css:config/ldp/authentication/dpop-bearer.json",
|
|
19
|
+
"css:config/ldp/authorization/webacl.json",
|
|
20
|
+
"css:config/ldp/handler/default.json",
|
|
21
|
+
"css:config/ldp/metadata-parser/default.json",
|
|
22
|
+
"css:config/ldp/metadata-writer/default.json",
|
|
23
|
+
"css:config/ldp/modes/default.json",
|
|
24
|
+
"css:config/storage/backend/file.json",
|
|
25
|
+
"css:config/storage/key-value/resource-store.json",
|
|
26
|
+
"css:config/storage/location/root.json",
|
|
27
|
+
"css:config/storage/middleware/default.json",
|
|
28
|
+
"css:config/util/auxiliary/acl.json",
|
|
29
|
+
"css:config/util/identifiers/suffix.json",
|
|
30
|
+
"css:config/util/index/default.json",
|
|
31
|
+
"css:config/util/logging/winston.json",
|
|
32
|
+
"css:config/util/representation-conversion/default.json",
|
|
33
|
+
"css:config/util/resource-locker/file.json",
|
|
34
|
+
"css:config/util/variables/default.json"
|
|
35
|
+
],
|
|
36
|
+
"@graph": [
|
|
37
|
+
{
|
|
38
|
+
"comment": [
|
|
39
|
+
"A Solid server that stores its resources on disk and uses WAC for authorization.",
|
|
40
|
+
"No registration and the root container is initialized to allow full access for everyone so make sure to change this."
|
|
41
|
+
]
|
|
42
|
+
}
|
|
43
|
+
]
|
|
44
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"@context": [
|
|
3
|
+
"https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/^7.0.0/components/context.jsonld"
|
|
4
|
+
],
|
|
5
|
+
"import": [
|
|
6
|
+
"css:config/app/init/static-root.json",
|
|
7
|
+
"css:config/app/main/default.json",
|
|
8
|
+
"css:config/app/variables/default.json",
|
|
9
|
+
"css:config/http/handler/default.json",
|
|
10
|
+
"css:config/http/middleware/default.json",
|
|
11
|
+
"css:config/http/notifications/all.json",
|
|
12
|
+
"css:config/http/server-factory/http.json",
|
|
13
|
+
"css:config/http/static/default.json",
|
|
14
|
+
"css:config/identity/access/public.json",
|
|
15
|
+
"css:config/identity/email/default.json",
|
|
16
|
+
"css:config/identity/handler/default.json",
|
|
17
|
+
"css:config/identity/oidc/default.json",
|
|
18
|
+
"css:config/identity/ownership/token.json",
|
|
19
|
+
"css:config/identity/pod/static.json",
|
|
20
|
+
"css:config/ldp/authentication/dpop-bearer.json",
|
|
21
|
+
"css:config/ldp/authorization/webacl.json",
|
|
22
|
+
"css:config/ldp/handler/default.json",
|
|
23
|
+
"css:config/ldp/metadata-parser/default.json",
|
|
24
|
+
"css:config/ldp/metadata-writer/default.json",
|
|
25
|
+
"css:config/ldp/modes/default.json",
|
|
26
|
+
"css:config/storage/backend/memory.json",
|
|
27
|
+
"css:config/storage/key-value/resource-store.json",
|
|
28
|
+
"css:config/storage/location/pod.json",
|
|
29
|
+
"css:config/storage/middleware/default.json",
|
|
30
|
+
"css:config/util/auxiliary/acl.json",
|
|
31
|
+
"css:config/util/identifiers/suffix.json",
|
|
32
|
+
"css:config/util/index/default.json",
|
|
33
|
+
"css:config/util/logging/winston.json",
|
|
34
|
+
"css:config/util/representation-conversion/default.json",
|
|
35
|
+
"css:config/util/resource-locker/memory.json",
|
|
36
|
+
"css:config/util/variables/default.json"
|
|
37
|
+
],
|
|
38
|
+
"@graph": [
|
|
39
|
+
{
|
|
40
|
+
"comment": "A Solid server that stores its resources on disk and uses WAC for authorization."
|
|
41
|
+
}
|
|
42
|
+
]
|
|
43
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createServer.d.ts","sourceRoot":"","sources":["../src/createServer.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,yBAAyB,CAAC;AAGnD,wBAAsB,SAAS,CAC7B,IAAI,EAAE,MAAM,EACZ,gBAAgB,CAAC,EAAE,MAAM,GACxB,OAAO,CAAC,GAAG,CAAC,CAuBd"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// Taken from https://github.com/comunica/comunica/blob/b237be4265c353a62a876187d9e21e3bc05123a3/engines/query-sparql/test/QuerySparql-solid-test.ts#L9
|
|
2
|
+
import * as path from "path";
|
|
3
|
+
import { AppRunner, resolveModulePath } from "@solid/community-server";
|
|
4
|
+
export async function createApp(port, customConfigPath) {
|
|
5
|
+
if (process.env.SERVER) {
|
|
6
|
+
return {
|
|
7
|
+
start: () => { },
|
|
8
|
+
stop: () => { },
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
const appRunner = new AppRunner();
|
|
12
|
+
return appRunner.create({
|
|
13
|
+
loaderProperties: {
|
|
14
|
+
mainModulePath: resolveModulePath(""),
|
|
15
|
+
typeChecking: false,
|
|
16
|
+
},
|
|
17
|
+
config: customConfigPath ?? resolveModulePath("config/file-root.json"),
|
|
18
|
+
variableBindings: {},
|
|
19
|
+
shorthand: {
|
|
20
|
+
port: port,
|
|
21
|
+
loggingLevel: "off",
|
|
22
|
+
seedConfig: path.join(__dirname, "configs", "solid-css-seed.json"),
|
|
23
|
+
rootFilePath: path.join(__dirname, `./data${port}`),
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=createServer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createServer.js","sourceRoot":"","sources":["../src/createServer.ts"],"names":[],"mappings":"AAAA,uJAAuJ;AAEvJ,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,OAAO,EAAE,SAAS,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAEvE,MAAM,CAAC,KAAK,UAAU,SAAS,CAC7B,IAAY,EACZ,gBAAyB;IAEzB,IAAI,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC;QACvB,OAAO;YACL,KAAK,EAAE,GAAG,EAAE,GAAE,CAAC;YACf,IAAI,EAAE,GAAG,EAAE,GAAE,CAAC;SACR,CAAC;IACX,CAAC;IACD,MAAM,SAAS,GAAG,IAAI,SAAS,EAAE,CAAC;IAElC,OAAO,SAAS,CAAC,MAAM,CAAC;QACtB,gBAAgB,EAAE;YAChB,cAAc,EAAE,iBAAiB,CAAC,EAAE,CAAC;YACrC,YAAY,EAAE,KAAK;SACpB;QACD,MAAM,EAAE,gBAAgB,IAAI,iBAAiB,CAAC,uBAAuB,CAAC;QACtE,gBAAgB,EAAE,EAAE;QACpB,SAAS,EAAE;YACT,IAAI,EAAE,IAAI;YACV,YAAY,EAAE,KAAK;YACnB,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,SAAS,EAAE,qBAAqB,CAAC;YAClE,YAAY,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,SAAS,IAAI,EAAE,CAAC;SACpD;KACF,CAAC,CAAC;AACL,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type ResourceInfo = ContainerInfo | LeafInfo;
|
|
2
|
+
interface ContainerInfo {
|
|
3
|
+
slug: string;
|
|
4
|
+
isContainer: true;
|
|
5
|
+
shouldNotInit?: boolean;
|
|
6
|
+
contains: (ContainerInfo | LeafInfo)[];
|
|
7
|
+
}
|
|
8
|
+
interface LeafInfo {
|
|
9
|
+
slug: string;
|
|
10
|
+
isContainer: false;
|
|
11
|
+
data: string;
|
|
12
|
+
shouldNotInit?: boolean;
|
|
13
|
+
mimeType: string;
|
|
14
|
+
}
|
|
15
|
+
export declare function initResources(rootUri: string, resourceInfo: ResourceInfo, authFetch: typeof fetch): Promise<void>;
|
|
16
|
+
export declare function cleanResources(rootUri: string, resourceInfo: ResourceInfo, authFetch: typeof fetch): Promise<void>;
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=resourceUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resourceUtils.d.ts","sourceRoot":"","sources":["../src/resourceUtils.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG,aAAa,GAAG,QAAQ,CAAC;AAEpD,UAAU,aAAa;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,IAAI,CAAC;IAClB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,QAAQ,EAAE,CAAC,aAAa,GAAG,QAAQ,CAAC,EAAE,CAAC;CACxC;AAED,UAAU,QAAQ;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,KAAK,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,wBAAsB,aAAa,CACjC,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,YAAY,EAC1B,SAAS,EAAE,OAAO,KAAK,GACtB,OAAO,CAAC,IAAI,CAAC,CA4Bf;AAED,wBAAsB,cAAc,CAClC,OAAO,EAAE,MAAM,EACf,YAAY,EAAE,YAAY,EAC1B,SAAS,EAAE,OAAO,KAAK,GACtB,OAAO,CAAC,IAAI,CAAC,CAmBf"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export async function initResources(rootUri, resourceInfo, authFetch) {
|
|
2
|
+
if (resourceInfo?.shouldNotInit)
|
|
3
|
+
return;
|
|
4
|
+
if (resourceInfo.isContainer) {
|
|
5
|
+
await authFetch(rootUri, {
|
|
6
|
+
method: "POST",
|
|
7
|
+
headers: {
|
|
8
|
+
link: '<http://www.w3.org/ns/ldp#Container>; rel="type"',
|
|
9
|
+
slug: resourceInfo.slug,
|
|
10
|
+
},
|
|
11
|
+
});
|
|
12
|
+
await Promise.all(resourceInfo.contains.map((subResourceInfo) => initResources(`${rootUri}${resourceInfo.slug}`, subResourceInfo, authFetch)));
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
await authFetch(`${rootUri}${resourceInfo.slug}`, {
|
|
16
|
+
method: "PUT",
|
|
17
|
+
headers: {
|
|
18
|
+
"content-type": resourceInfo.mimeType,
|
|
19
|
+
},
|
|
20
|
+
body: resourceInfo.data,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export async function cleanResources(rootUri, resourceInfo, authFetch) {
|
|
25
|
+
if (resourceInfo.isContainer) {
|
|
26
|
+
await Promise.all(resourceInfo.contains.map((subResourceInfo) => cleanResources(`${rootUri}${resourceInfo.slug}`, subResourceInfo, authFetch)));
|
|
27
|
+
await authFetch(`${rootUri}${resourceInfo.slug}`, {
|
|
28
|
+
method: "DELETE",
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
await authFetch(`${rootUri}${resourceInfo.slug}`, {
|
|
33
|
+
method: "DELETE",
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=resourceUtils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resourceUtils.js","sourceRoot":"","sources":["../src/resourceUtils.ts"],"names":[],"mappings":"AAiBA,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,OAAe,EACf,YAA0B,EAC1B,SAAuB;IAEvB,IAAI,YAAY,EAAE,aAAa;QAAE,OAAO;IACxC,IAAI,YAAY,CAAC,WAAW,EAAE,CAAC;QAC7B,MAAM,SAAS,CAAC,OAAO,EAAE;YACvB,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACP,IAAI,EAAE,kDAAkD;gBACxD,IAAI,EAAE,YAAY,CAAC,IAAI;aACxB;SACF,CAAC,CAAC;QACH,MAAM,OAAO,CAAC,GAAG,CACf,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,eAAe,EAAE,EAAE,CAC5C,aAAa,CACX,GAAG,OAAO,GAAG,YAAY,CAAC,IAAI,EAAE,EAChC,eAAe,EACf,SAAS,CACV,CACF,CACF,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,MAAM,SAAS,CAAC,GAAG,OAAO,GAAG,YAAY,CAAC,IAAI,EAAE,EAAE;YAChD,MAAM,EAAE,KAAK;YACb,OAAO,EAAE;gBACP,cAAc,EAAE,YAAY,CAAC,QAAQ;aACtC;YACD,IAAI,EAAE,YAAY,CAAC,IAAI;SACxB,CAAC,CAAC;IACL,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,OAAe,EACf,YAA0B,EAC1B,SAAuB;IAEvB,IAAI,YAAY,CAAC,WAAW,EAAE,CAAC;QAC7B,MAAM,OAAO,CAAC,GAAG,CACf,YAAY,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,eAAe,EAAE,EAAE,CAC5C,cAAc,CACZ,GAAG,OAAO,GAAG,YAAY,CAAC,IAAI,EAAE,EAChC,eAAe,EACf,SAAS,CACV,CACF,CACF,CAAC;QACF,MAAM,SAAS,CAAC,GAAG,OAAO,GAAG,YAAY,CAAC,IAAI,EAAE,EAAE;YAChD,MAAM,EAAE,QAAQ;SACjB,CAAC,CAAC;IACL,CAAC;SAAM,CAAC;QACN,MAAM,SAAS,CAAC,GAAG,OAAO,GAAG,YAAY,CAAC,IAAI,EAAE,EAAE;YAChD,MAAM,EAAE,QAAQ;SACjB,CAAC,CAAC;IACL,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { App } from "@solid/community-server";
|
|
2
|
+
import type { ResourceInfo } from "./resourceUtils.js";
|
|
3
|
+
import { type MockedFunction } from "vitest";
|
|
4
|
+
export declare function setupServer(port: number, resourceInfo: ResourceInfo, customConfigPath?: string, skipAuthentication?: boolean): {
|
|
5
|
+
app: App;
|
|
6
|
+
fetchMock: MockedFunction<(input: RequestInfo | URL, init?: RequestInit | undefined) => Promise<Response>>;
|
|
7
|
+
authFetch: typeof fetch;
|
|
8
|
+
rootUri: string;
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=setupTestServer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setupTestServer.d.ts","sourceRoot":"","sources":["../src/setupTestServer.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,yBAAyB,CAAC;AAGnD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAIvD,OAAO,EAML,KAAK,cAAc,EACpB,MAAM,QAAQ,CAAC;AAKhB,wBAAgB,WAAW,CACzB,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,YAAY,EAC1B,gBAAgB,CAAC,EAAE,MAAM,EACzB,kBAAkB,CAAC,EAAE,OAAO;SAGrB,GAAG;eACG,cAAc,CACvB,CACE,KAAK,EAAE,WAAW,GAAG,GAAG,EACxB,IAAI,CAAC,EAAE,WAAW,GAAG,SAAS,KAC3B,OAAO,CAAC,QAAQ,CAAC,CACvB;eACU,OAAO,KAAK;aACd,MAAM;EAmClB"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { createApp } from "./createServer.js";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { cleanResources, initResources } from "./resourceUtils.js";
|
|
4
|
+
import { generateAuthFetch } from "./authFetch.js";
|
|
5
|
+
import fs from "fs/promises";
|
|
6
|
+
import { beforeAll, afterAll, beforeEach, afterEach, vi, } from "vitest";
|
|
7
|
+
// Use an increased timeout, since the CSS server takes too much setup time.
|
|
8
|
+
vi.setConfig({ testTimeout: 40_000 });
|
|
9
|
+
export function setupServer(port, resourceInfo, customConfigPath, skipAuthentication) {
|
|
10
|
+
const data = {
|
|
11
|
+
rootUri: `http://localhost:${port}/`,
|
|
12
|
+
};
|
|
13
|
+
let previousJestId;
|
|
14
|
+
let previousNodeEnv;
|
|
15
|
+
beforeAll(async () => {
|
|
16
|
+
// Remove Jest ID so that community solid server doesn't use the Jest Import
|
|
17
|
+
process.env.NODE_ENV = "other_test";
|
|
18
|
+
// Start up the server
|
|
19
|
+
data.app = await createApp(port, customConfigPath);
|
|
20
|
+
await data.app.start();
|
|
21
|
+
data.authFetch = skipAuthentication ? fetch : await generateAuthFetch(port);
|
|
22
|
+
});
|
|
23
|
+
afterAll(async () => {
|
|
24
|
+
data.app.stop();
|
|
25
|
+
process.env.JEST_WORKER_ID = previousJestId;
|
|
26
|
+
process.env.NODE_ENV = previousNodeEnv;
|
|
27
|
+
const testDataPath = path.join(__dirname, `./data${port}`);
|
|
28
|
+
await fs.rm(testDataPath, { recursive: true, force: true });
|
|
29
|
+
});
|
|
30
|
+
beforeEach(async () => {
|
|
31
|
+
data.fetchMock = vi.fn(data.authFetch);
|
|
32
|
+
// Create a new document called sample.ttl
|
|
33
|
+
await initResources(data.rootUri, resourceInfo, data.authFetch);
|
|
34
|
+
});
|
|
35
|
+
afterEach(async () => {
|
|
36
|
+
await cleanResources(data.rootUri, resourceInfo, data.authFetch);
|
|
37
|
+
});
|
|
38
|
+
return data;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=setupTestServer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setupTestServer.js","sourceRoot":"","sources":["../src/setupTestServer.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,MAAM,aAAa,CAAC;A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,KAAK,IAAI,EAAE;QACpB,IAAI,CAAC,SAAS,GAAG,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACvC,0CAA0C;QAC1C,MAAM,aAAa,CAAC,IAAI,CAAC,OAAO,EAAE,YAAY,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;IAClE,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,KAAK,IAAI,EAAE;QACnB,MAAM,cAAc,CAAC,IAAI,CAAC,OAAO,EAAE,YAAY,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;IACnE,CAAC,CAAC,CAAC;IAEH,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ldo/test-solid-server",
|
|
3
|
+
"version": "1.0.0-alpha.11",
|
|
4
|
+
"description": "A solid server to be used in jest tests",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"module": "dist/index.js",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "tsc --project tsconfig.build.json && npm run copy-configs",
|
|
10
|
+
"prepublishOnly": "npm run build",
|
|
11
|
+
"copy-configs": "cp -r src/configs dist/configs",
|
|
12
|
+
"lint": "eslint src/** --fix --no-error-on-unmatched-pattern"
|
|
13
|
+
},
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/o-development/ldo.git"
|
|
17
|
+
},
|
|
18
|
+
"author": "Jackson Morgan",
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"bugs": {
|
|
21
|
+
"url": "https://github.com/o-development/ldo/issues"
|
|
22
|
+
},
|
|
23
|
+
"homepage": "https://github.com/o-development/ldo/tree/main/packages/solid#readme",
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@inrupt/solid-client-authn-core": "^2.2.6",
|
|
26
|
+
"@solid/community-server": "^7.1.3",
|
|
27
|
+
"cross-env": "^7.0.3"
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"dist",
|
|
31
|
+
"src"
|
|
32
|
+
],
|
|
33
|
+
"publishConfig": {
|
|
34
|
+
"access": "public"
|
|
35
|
+
},
|
|
36
|
+
"gitHead": "84bd3d7cf0a1b28c5e20b019a6451973d69d0198"
|
|
37
|
+
}
|
package/src/authFetch.ts
ADDED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import type { KeyPair } from "@inrupt/solid-client-authn-core";
|
|
2
|
+
import {
|
|
3
|
+
buildAuthenticatedFetch,
|
|
4
|
+
createDpopHeader,
|
|
5
|
+
generateDpopKeyPair,
|
|
6
|
+
} from "@inrupt/solid-client-authn-core";
|
|
7
|
+
import fetch from "cross-fetch";
|
|
8
|
+
|
|
9
|
+
const config = {
|
|
10
|
+
podName: "example",
|
|
11
|
+
email: "hello@example.com",
|
|
12
|
+
password: "abc123",
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
async function reportError(response: Response) {
|
|
16
|
+
if (response.status >= 400) {
|
|
17
|
+
console.error(await response.text());
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async function getAuthorization(port: number): Promise<string> {
|
|
22
|
+
// First we request the account API controls to find out where we can log in
|
|
23
|
+
const indexResponse = await fetch(`http://localhost:${port}/.account/`);
|
|
24
|
+
const { controls } = await indexResponse.json();
|
|
25
|
+
|
|
26
|
+
// And then we log in to the account API
|
|
27
|
+
const response = await fetch(controls.password.login, {
|
|
28
|
+
method: "POST",
|
|
29
|
+
headers: { "content-type": "application/json" },
|
|
30
|
+
body: JSON.stringify({
|
|
31
|
+
email: config.email,
|
|
32
|
+
password: config.password,
|
|
33
|
+
}),
|
|
34
|
+
});
|
|
35
|
+
// This authorization value will be used to authenticate in the next step
|
|
36
|
+
await reportError(response);
|
|
37
|
+
const result = await response.json();
|
|
38
|
+
return result.authorization;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async function getSecret(
|
|
42
|
+
port: number,
|
|
43
|
+
authorization: string,
|
|
44
|
+
): Promise<{ id: string; secret: string; resource: string }> {
|
|
45
|
+
// Now that we are logged in, we need to request the updated controls from the server.
|
|
46
|
+
// These will now have more values than in the previous example.
|
|
47
|
+
const indexResponse = await fetch(`http://localhost:${port}/.account/`, {
|
|
48
|
+
headers: { authorization: `CSS-Account-Token ${authorization}` },
|
|
49
|
+
});
|
|
50
|
+
const { controls } = await indexResponse.json();
|
|
51
|
+
|
|
52
|
+
// Here we request the server to generate a token on our account
|
|
53
|
+
const response = await fetch(controls.account.clientCredentials, {
|
|
54
|
+
method: "POST",
|
|
55
|
+
headers: {
|
|
56
|
+
authorization: `CSS-Account-Token ${authorization}`,
|
|
57
|
+
"content-type": "application/json",
|
|
58
|
+
},
|
|
59
|
+
// The name field will be used when generating the ID of your token.
|
|
60
|
+
// The WebID field determines which WebID you will identify as when using the token.
|
|
61
|
+
// Only WebIDs linked to your account can be used.
|
|
62
|
+
body: JSON.stringify({
|
|
63
|
+
name: "my-token",
|
|
64
|
+
webId: `http://localhost:${port}/${config.podName}/profile/card#me`,
|
|
65
|
+
}),
|
|
66
|
+
});
|
|
67
|
+
await reportError(response);
|
|
68
|
+
// These are the identifier and secret of your token.
|
|
69
|
+
// Store the secret somewhere safe as there is no way to request it again from the server!
|
|
70
|
+
// The `resource` value can be used to delete the token at a later point in time.
|
|
71
|
+
const response2 = await response.json();
|
|
72
|
+
return response2;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async function getAccessToken(
|
|
76
|
+
port: number,
|
|
77
|
+
id: string,
|
|
78
|
+
secret: string,
|
|
79
|
+
): Promise<{ accessToken: string; dpopKey: KeyPair }> {
|
|
80
|
+
try {
|
|
81
|
+
// A key pair is needed for encryption.
|
|
82
|
+
// This function from `solid-client-authn` generates such a pair for you.
|
|
83
|
+
const dpopKey = await generateDpopKeyPair();
|
|
84
|
+
|
|
85
|
+
// These are the ID and secret generated in the previous step.
|
|
86
|
+
// Both the ID and the secret need to be form-encoded.
|
|
87
|
+
const authString = `${encodeURIComponent(id)}:${encodeURIComponent(
|
|
88
|
+
secret,
|
|
89
|
+
)}`;
|
|
90
|
+
// This URL can be found by looking at the "token_endpoint" field at
|
|
91
|
+
// http://localhost:PORT/.well-known/openid-configuration
|
|
92
|
+
// if your server is hosted at http://localhost:3000/.
|
|
93
|
+
const tokenUrl = `http://localhost:${port}/.oidc/token`;
|
|
94
|
+
const response = await fetch(tokenUrl, {
|
|
95
|
+
method: "POST",
|
|
96
|
+
headers: {
|
|
97
|
+
// The header needs to be in base64 encoding.
|
|
98
|
+
authorization: `Basic ${Buffer.from(authString).toString("base64")}`,
|
|
99
|
+
"content-type": "application/x-www-form-urlencoded",
|
|
100
|
+
dpop: await createDpopHeader(tokenUrl, "POST", dpopKey),
|
|
101
|
+
},
|
|
102
|
+
body: "grant_type=client_credentials&scope=webid",
|
|
103
|
+
});
|
|
104
|
+
await reportError(response);
|
|
105
|
+
// This is the Access token that will be used to do an authenticated request to the server.
|
|
106
|
+
// The JSON also contains an "expires_in" field in seconds,
|
|
107
|
+
// which you can use to know when you need request a new Access token.
|
|
108
|
+
const response2 = await response.json();
|
|
109
|
+
return { accessToken: response2.access_token, dpopKey };
|
|
110
|
+
} catch (err) {
|
|
111
|
+
console.error(err);
|
|
112
|
+
throw err;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export async function generateAuthFetch(port: number) {
|
|
117
|
+
const authorization = await getAuthorization(port);
|
|
118
|
+
const { id, secret } = await getSecret(port, authorization);
|
|
119
|
+
const { accessToken, dpopKey } = await getAccessToken(port, id, secret);
|
|
120
|
+
return await buildAuthenticatedFetch(accessToken, { dpopKey });
|
|
121
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"@context": "https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/^7.0.0/components/context.jsonld",
|
|
3
|
+
"import": [
|
|
4
|
+
"css:config/app/init/initialize-root.json",
|
|
5
|
+
"css:config/app/main/default.json",
|
|
6
|
+
"css:config/app/variables/default.json",
|
|
7
|
+
"css:config/http/handler/default.json",
|
|
8
|
+
"css:config/http/middleware/default.json",
|
|
9
|
+
"css:config/http/notifications/webhooks.json",
|
|
10
|
+
"css:config/http/server-factory/http.json",
|
|
11
|
+
"css:config/http/static/default.json",
|
|
12
|
+
"css:config/identity/access/public.json",
|
|
13
|
+
"css:config/identity/email/default.json",
|
|
14
|
+
"css:config/identity/handler/no-accounts.json",
|
|
15
|
+
"css:config/identity/oidc/default.json",
|
|
16
|
+
"css:config/identity/ownership/token.json",
|
|
17
|
+
"css:config/identity/pod/static.json",
|
|
18
|
+
"css:config/ldp/authentication/dpop-bearer.json",
|
|
19
|
+
"css:config/ldp/authorization/webacl.json",
|
|
20
|
+
"css:config/ldp/handler/default.json",
|
|
21
|
+
"css:config/ldp/metadata-parser/default.json",
|
|
22
|
+
"css:config/ldp/metadata-writer/default.json",
|
|
23
|
+
"css:config/ldp/modes/default.json",
|
|
24
|
+
"css:config/storage/backend/file.json",
|
|
25
|
+
"css:config/storage/key-value/resource-store.json",
|
|
26
|
+
"css:config/storage/location/root.json",
|
|
27
|
+
"css:config/storage/middleware/default.json",
|
|
28
|
+
"css:config/util/auxiliary/acl.json",
|
|
29
|
+
"css:config/util/identifiers/suffix.json",
|
|
30
|
+
"css:config/util/index/default.json",
|
|
31
|
+
"css:config/util/logging/winston.json",
|
|
32
|
+
"css:config/util/representation-conversion/default.json",
|
|
33
|
+
"css:config/util/resource-locker/file.json",
|
|
34
|
+
"css:config/util/variables/default.json"
|
|
35
|
+
],
|
|
36
|
+
"@graph": [
|
|
37
|
+
{
|
|
38
|
+
"comment": [
|
|
39
|
+
"A Solid server that stores its resources on disk and uses WAC for authorization.",
|
|
40
|
+
"No registration and the root container is initialized to allow full access for everyone so make sure to change this."
|
|
41
|
+
]
|
|
42
|
+
}
|
|
43
|
+
]
|
|
44
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"@context": [
|
|
3
|
+
"https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/^7.0.0/components/context.jsonld"
|
|
4
|
+
],
|
|
5
|
+
"import": [
|
|
6
|
+
"css:config/app/init/static-root.json",
|
|
7
|
+
"css:config/app/main/default.json",
|
|
8
|
+
"css:config/app/variables/default.json",
|
|
9
|
+
"css:config/http/handler/default.json",
|
|
10
|
+
"css:config/http/middleware/default.json",
|
|
11
|
+
"css:config/http/notifications/all.json",
|
|
12
|
+
"css:config/http/server-factory/http.json",
|
|
13
|
+
"css:config/http/static/default.json",
|
|
14
|
+
"css:config/identity/access/public.json",
|
|
15
|
+
"css:config/identity/email/default.json",
|
|
16
|
+
"css:config/identity/handler/default.json",
|
|
17
|
+
"css:config/identity/oidc/default.json",
|
|
18
|
+
"css:config/identity/ownership/token.json",
|
|
19
|
+
"css:config/identity/pod/static.json",
|
|
20
|
+
"css:config/ldp/authentication/dpop-bearer.json",
|
|
21
|
+
"css:config/ldp/authorization/webacl.json",
|
|
22
|
+
"css:config/ldp/handler/default.json",
|
|
23
|
+
"css:config/ldp/metadata-parser/default.json",
|
|
24
|
+
"css:config/ldp/metadata-writer/default.json",
|
|
25
|
+
"css:config/ldp/modes/default.json",
|
|
26
|
+
"css:config/storage/backend/memory.json",
|
|
27
|
+
"css:config/storage/key-value/resource-store.json",
|
|
28
|
+
"css:config/storage/location/pod.json",
|
|
29
|
+
"css:config/storage/middleware/default.json",
|
|
30
|
+
"css:config/util/auxiliary/acl.json",
|
|
31
|
+
"css:config/util/identifiers/suffix.json",
|
|
32
|
+
"css:config/util/index/default.json",
|
|
33
|
+
"css:config/util/logging/winston.json",
|
|
34
|
+
"css:config/util/representation-conversion/default.json",
|
|
35
|
+
"css:config/util/resource-locker/memory.json",
|
|
36
|
+
"css:config/util/variables/default.json"
|
|
37
|
+
],
|
|
38
|
+
"@graph": [
|
|
39
|
+
{
|
|
40
|
+
"comment": "A Solid server that stores its resources on disk and uses WAC for authorization."
|
|
41
|
+
}
|
|
42
|
+
]
|
|
43
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Taken from https://github.com/comunica/comunica/blob/b237be4265c353a62a876187d9e21e3bc05123a3/engines/query-sparql/test/QuerySparql-solid-test.ts#L9
|
|
2
|
+
|
|
3
|
+
import * as path from "path";
|
|
4
|
+
import type { App } from "@solid/community-server";
|
|
5
|
+
import { AppRunner, resolveModulePath } from "@solid/community-server";
|
|
6
|
+
|
|
7
|
+
export async function createApp(
|
|
8
|
+
port: number,
|
|
9
|
+
customConfigPath?: string,
|
|
10
|
+
): Promise<App> {
|
|
11
|
+
if (process.env.SERVER) {
|
|
12
|
+
return {
|
|
13
|
+
start: () => {},
|
|
14
|
+
stop: () => {},
|
|
15
|
+
} as App;
|
|
16
|
+
}
|
|
17
|
+
const appRunner = new AppRunner();
|
|
18
|
+
|
|
19
|
+
return appRunner.create({
|
|
20
|
+
loaderProperties: {
|
|
21
|
+
mainModulePath: resolveModulePath(""),
|
|
22
|
+
typeChecking: false,
|
|
23
|
+
},
|
|
24
|
+
config: customConfigPath ?? resolveModulePath("config/file-root.json"),
|
|
25
|
+
variableBindings: {},
|
|
26
|
+
shorthand: {
|
|
27
|
+
port: port,
|
|
28
|
+
loggingLevel: "off",
|
|
29
|
+
seedConfig: path.join(__dirname, "configs", "solid-css-seed.json"),
|
|
30
|
+
rootFilePath: path.join(__dirname, `./data${port}`),
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
export type ResourceInfo = ContainerInfo | LeafInfo;
|
|
2
|
+
|
|
3
|
+
interface ContainerInfo {
|
|
4
|
+
slug: string;
|
|
5
|
+
isContainer: true;
|
|
6
|
+
shouldNotInit?: boolean;
|
|
7
|
+
contains: (ContainerInfo | LeafInfo)[];
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface LeafInfo {
|
|
11
|
+
slug: string;
|
|
12
|
+
isContainer: false;
|
|
13
|
+
data: string;
|
|
14
|
+
shouldNotInit?: boolean;
|
|
15
|
+
mimeType: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export async function initResources(
|
|
19
|
+
rootUri: string,
|
|
20
|
+
resourceInfo: ResourceInfo,
|
|
21
|
+
authFetch: typeof fetch,
|
|
22
|
+
): Promise<void> {
|
|
23
|
+
if (resourceInfo?.shouldNotInit) return;
|
|
24
|
+
if (resourceInfo.isContainer) {
|
|
25
|
+
await authFetch(rootUri, {
|
|
26
|
+
method: "POST",
|
|
27
|
+
headers: {
|
|
28
|
+
link: '<http://www.w3.org/ns/ldp#Container>; rel="type"',
|
|
29
|
+
slug: resourceInfo.slug,
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
await Promise.all(
|
|
33
|
+
resourceInfo.contains.map((subResourceInfo) =>
|
|
34
|
+
initResources(
|
|
35
|
+
`${rootUri}${resourceInfo.slug}`,
|
|
36
|
+
subResourceInfo,
|
|
37
|
+
authFetch,
|
|
38
|
+
),
|
|
39
|
+
),
|
|
40
|
+
);
|
|
41
|
+
} else {
|
|
42
|
+
await authFetch(`${rootUri}${resourceInfo.slug}`, {
|
|
43
|
+
method: "PUT",
|
|
44
|
+
headers: {
|
|
45
|
+
"content-type": resourceInfo.mimeType,
|
|
46
|
+
},
|
|
47
|
+
body: resourceInfo.data,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export async function cleanResources(
|
|
53
|
+
rootUri: string,
|
|
54
|
+
resourceInfo: ResourceInfo,
|
|
55
|
+
authFetch: typeof fetch,
|
|
56
|
+
): Promise<void> {
|
|
57
|
+
if (resourceInfo.isContainer) {
|
|
58
|
+
await Promise.all(
|
|
59
|
+
resourceInfo.contains.map((subResourceInfo) =>
|
|
60
|
+
cleanResources(
|
|
61
|
+
`${rootUri}${resourceInfo.slug}`,
|
|
62
|
+
subResourceInfo,
|
|
63
|
+
authFetch,
|
|
64
|
+
),
|
|
65
|
+
),
|
|
66
|
+
);
|
|
67
|
+
await authFetch(`${rootUri}${resourceInfo.slug}`, {
|
|
68
|
+
method: "DELETE",
|
|
69
|
+
});
|
|
70
|
+
} else {
|
|
71
|
+
await authFetch(`${rootUri}${resourceInfo.slug}`, {
|
|
72
|
+
method: "DELETE",
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import type { App } from "@solid/community-server";
|
|
3
|
+
import { createApp } from "./createServer.js";
|
|
4
|
+
import path from "path";
|
|
5
|
+
import type { ResourceInfo } from "./resourceUtils.js";
|
|
6
|
+
import { cleanResources, initResources } from "./resourceUtils.js";
|
|
7
|
+
import { generateAuthFetch } from "./authFetch.js";
|
|
8
|
+
import fs from "fs/promises";
|
|
9
|
+
import {
|
|
10
|
+
beforeAll,
|
|
11
|
+
afterAll,
|
|
12
|
+
beforeEach,
|
|
13
|
+
afterEach,
|
|
14
|
+
vi,
|
|
15
|
+
type MockedFunction,
|
|
16
|
+
} from "vitest";
|
|
17
|
+
|
|
18
|
+
// Use an increased timeout, since the CSS server takes too much setup time.
|
|
19
|
+
vi.setConfig({ testTimeout: 40_000 });
|
|
20
|
+
|
|
21
|
+
export function setupServer(
|
|
22
|
+
port: number,
|
|
23
|
+
resourceInfo: ResourceInfo,
|
|
24
|
+
customConfigPath?: string,
|
|
25
|
+
skipAuthentication?: boolean,
|
|
26
|
+
) {
|
|
27
|
+
const data: {
|
|
28
|
+
app: App;
|
|
29
|
+
fetchMock: MockedFunction<
|
|
30
|
+
(
|
|
31
|
+
input: RequestInfo | URL,
|
|
32
|
+
init?: RequestInit | undefined,
|
|
33
|
+
) => Promise<Response>
|
|
34
|
+
>;
|
|
35
|
+
authFetch: typeof fetch;
|
|
36
|
+
rootUri: string;
|
|
37
|
+
} = {
|
|
38
|
+
rootUri: `http://localhost:${port}/`,
|
|
39
|
+
} as any;
|
|
40
|
+
|
|
41
|
+
let previousJestId: string | undefined;
|
|
42
|
+
let previousNodeEnv: string | undefined;
|
|
43
|
+
beforeAll(async () => {
|
|
44
|
+
// Remove Jest ID so that community solid server doesn't use the Jest Import
|
|
45
|
+
process.env.NODE_ENV = "other_test";
|
|
46
|
+
// Start up the server
|
|
47
|
+
data.app = await createApp(port, customConfigPath);
|
|
48
|
+
await data.app.start();
|
|
49
|
+
data.authFetch = skipAuthentication ? fetch : await generateAuthFetch(port);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
afterAll(async () => {
|
|
53
|
+
data.app.stop();
|
|
54
|
+
process.env.JEST_WORKER_ID = previousJestId;
|
|
55
|
+
process.env.NODE_ENV = previousNodeEnv;
|
|
56
|
+
const testDataPath = path.join(__dirname, `./data${port}`);
|
|
57
|
+
await fs.rm(testDataPath, { recursive: true, force: true });
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
beforeEach(async () => {
|
|
61
|
+
data.fetchMock = vi.fn(data.authFetch);
|
|
62
|
+
// Create a new document called sample.ttl
|
|
63
|
+
await initResources(data.rootUri, resourceInfo, data.authFetch);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
afterEach(async () => {
|
|
67
|
+
await cleanResources(data.rootUri, resourceInfo, data.authFetch);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
return data;
|
|
71
|
+
}
|