javascript-solid-server 0.0.5 → 0.0.7
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/package.json +9 -3
- package/src/auth/middleware.js +10 -8
- package/src/auth/solid-oidc.js +260 -0
- package/src/auth/token.js +43 -5
- package/src/handlers/resource.js +97 -0
- package/src/patch/n3-patch.js +522 -0
- package/src/server.js +4 -3
- package/test/patch.test.js +295 -0
- package/test/solid-oidc.test.js +211 -0
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PATCH (N3 Patch) tests
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { describe, it, before, after } from 'node:test';
|
|
6
|
+
import assert from 'node:assert';
|
|
7
|
+
import {
|
|
8
|
+
startTestServer,
|
|
9
|
+
stopTestServer,
|
|
10
|
+
request,
|
|
11
|
+
createTestPod,
|
|
12
|
+
getBaseUrl,
|
|
13
|
+
assertStatus,
|
|
14
|
+
assertHeader
|
|
15
|
+
} from './helpers.js';
|
|
16
|
+
|
|
17
|
+
describe('PATCH Operations', () => {
|
|
18
|
+
before(async () => {
|
|
19
|
+
await startTestServer();
|
|
20
|
+
await createTestPod('patchtest');
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
after(async () => {
|
|
24
|
+
await stopTestServer();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
describe('N3 Patch', () => {
|
|
28
|
+
it('should insert a triple into a JSON-LD resource', async () => {
|
|
29
|
+
// Create initial resource
|
|
30
|
+
const initial = {
|
|
31
|
+
'@context': { 'foaf': 'http://xmlns.com/foaf/0.1/' },
|
|
32
|
+
'@id': '#me',
|
|
33
|
+
'foaf:name': 'Alice'
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
await request('/patchtest/public/patch-insert.json', {
|
|
37
|
+
method: 'PUT',
|
|
38
|
+
headers: { 'Content-Type': 'application/ld+json' },
|
|
39
|
+
body: JSON.stringify(initial),
|
|
40
|
+
auth: 'patchtest'
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// Apply N3 Patch to insert a new triple
|
|
44
|
+
const patch = `
|
|
45
|
+
@prefix solid: <http://www.w3.org/ns/solid/terms#>.
|
|
46
|
+
@prefix foaf: <http://xmlns.com/foaf/0.1/>.
|
|
47
|
+
_:patch a solid:InsertDeletePatch;
|
|
48
|
+
solid:inserts { <#me> foaf:mbox <mailto:alice@example.org> }.
|
|
49
|
+
`;
|
|
50
|
+
|
|
51
|
+
const res = await request('/patchtest/public/patch-insert.json', {
|
|
52
|
+
method: 'PATCH',
|
|
53
|
+
headers: { 'Content-Type': 'text/n3' },
|
|
54
|
+
body: patch,
|
|
55
|
+
auth: 'patchtest'
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
assertStatus(res, 204);
|
|
59
|
+
|
|
60
|
+
// Verify the change
|
|
61
|
+
const verify = await request('/patchtest/public/patch-insert.json');
|
|
62
|
+
const data = await verify.json();
|
|
63
|
+
|
|
64
|
+
assert.ok(data['foaf:mbox'], 'Should have new mbox property');
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('should delete a triple from a JSON-LD resource', async () => {
|
|
68
|
+
// Create initial resource with multiple properties
|
|
69
|
+
const initial = {
|
|
70
|
+
'@context': { 'foaf': 'http://xmlns.com/foaf/0.1/' },
|
|
71
|
+
'@id': '#me',
|
|
72
|
+
'foaf:name': 'Bob',
|
|
73
|
+
'foaf:age': 30
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
await request('/patchtest/public/patch-delete.json', {
|
|
77
|
+
method: 'PUT',
|
|
78
|
+
headers: { 'Content-Type': 'application/ld+json' },
|
|
79
|
+
body: JSON.stringify(initial),
|
|
80
|
+
auth: 'patchtest'
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
// Apply N3 Patch to delete the age property
|
|
84
|
+
const patch = `
|
|
85
|
+
@prefix solid: <http://www.w3.org/ns/solid/terms#>.
|
|
86
|
+
@prefix foaf: <http://xmlns.com/foaf/0.1/>.
|
|
87
|
+
_:patch a solid:InsertDeletePatch;
|
|
88
|
+
solid:deletes { <#me> foaf:age 30 }.
|
|
89
|
+
`;
|
|
90
|
+
|
|
91
|
+
const res = await request('/patchtest/public/patch-delete.json', {
|
|
92
|
+
method: 'PATCH',
|
|
93
|
+
headers: { 'Content-Type': 'text/n3' },
|
|
94
|
+
body: patch,
|
|
95
|
+
auth: 'patchtest'
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
assertStatus(res, 204);
|
|
99
|
+
|
|
100
|
+
// Verify the change
|
|
101
|
+
const verify = await request('/patchtest/public/patch-delete.json');
|
|
102
|
+
const data = await verify.json();
|
|
103
|
+
|
|
104
|
+
assert.ok(!data['foaf:age'], 'Should not have age property');
|
|
105
|
+
assert.strictEqual(data['foaf:name'], 'Bob', 'Should still have name');
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('should insert and delete in same patch', async () => {
|
|
109
|
+
// Create initial resource
|
|
110
|
+
const initial = {
|
|
111
|
+
'@context': { 'foaf': 'http://xmlns.com/foaf/0.1/' },
|
|
112
|
+
'@id': '#me',
|
|
113
|
+
'foaf:name': 'Charlie'
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
await request('/patchtest/public/patch-both.json', {
|
|
117
|
+
method: 'PUT',
|
|
118
|
+
headers: { 'Content-Type': 'application/ld+json' },
|
|
119
|
+
body: JSON.stringify(initial),
|
|
120
|
+
auth: 'patchtest'
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
// Apply N3 Patch to change name
|
|
124
|
+
const patch = `
|
|
125
|
+
@prefix solid: <http://www.w3.org/ns/solid/terms#>.
|
|
126
|
+
@prefix foaf: <http://xmlns.com/foaf/0.1/>.
|
|
127
|
+
_:patch a solid:InsertDeletePatch;
|
|
128
|
+
solid:deletes { <#me> foaf:name "Charlie" };
|
|
129
|
+
solid:inserts { <#me> foaf:name "Charles" }.
|
|
130
|
+
`;
|
|
131
|
+
|
|
132
|
+
const res = await request('/patchtest/public/patch-both.json', {
|
|
133
|
+
method: 'PATCH',
|
|
134
|
+
headers: { 'Content-Type': 'text/n3' },
|
|
135
|
+
body: patch,
|
|
136
|
+
auth: 'patchtest'
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
assertStatus(res, 204);
|
|
140
|
+
|
|
141
|
+
// Verify the change
|
|
142
|
+
const verify = await request('/patchtest/public/patch-both.json');
|
|
143
|
+
const data = await verify.json();
|
|
144
|
+
|
|
145
|
+
assert.strictEqual(data['foaf:name'], 'Charles', 'Name should be updated');
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
it('should add a new subject node', async () => {
|
|
149
|
+
// Create initial resource with @graph
|
|
150
|
+
const initial = {
|
|
151
|
+
'@context': { 'foaf': 'http://xmlns.com/foaf/0.1/' },
|
|
152
|
+
'@graph': [
|
|
153
|
+
{ '@id': '#alice', 'foaf:name': 'Alice' }
|
|
154
|
+
]
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
await request('/patchtest/public/patch-newnode.json', {
|
|
158
|
+
method: 'PUT',
|
|
159
|
+
headers: { 'Content-Type': 'application/ld+json' },
|
|
160
|
+
body: JSON.stringify(initial),
|
|
161
|
+
auth: 'patchtest'
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
// Add a new person
|
|
165
|
+
const patch = `
|
|
166
|
+
@prefix solid: <http://www.w3.org/ns/solid/terms#>.
|
|
167
|
+
@prefix foaf: <http://xmlns.com/foaf/0.1/>.
|
|
168
|
+
_:patch a solid:InsertDeletePatch;
|
|
169
|
+
solid:inserts { <#bob> foaf:name "Bob" }.
|
|
170
|
+
`;
|
|
171
|
+
|
|
172
|
+
const res = await request('/patchtest/public/patch-newnode.json', {
|
|
173
|
+
method: 'PATCH',
|
|
174
|
+
headers: { 'Content-Type': 'text/n3' },
|
|
175
|
+
body: patch,
|
|
176
|
+
auth: 'patchtest'
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
assertStatus(res, 204);
|
|
180
|
+
|
|
181
|
+
// Verify the change
|
|
182
|
+
const verify = await request('/patchtest/public/patch-newnode.json');
|
|
183
|
+
const data = await verify.json();
|
|
184
|
+
|
|
185
|
+
assert.ok(data['@graph'], 'Should have @graph');
|
|
186
|
+
assert.strictEqual(data['@graph'].length, 2, 'Should have 2 nodes');
|
|
187
|
+
});
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
describe('PATCH Error Handling', () => {
|
|
191
|
+
it('should return 415 for unsupported content type', async () => {
|
|
192
|
+
// Create a resource first
|
|
193
|
+
await request('/patchtest/public/patch-error.json', {
|
|
194
|
+
method: 'PUT',
|
|
195
|
+
headers: { 'Content-Type': 'application/json' },
|
|
196
|
+
body: JSON.stringify({ test: true }),
|
|
197
|
+
auth: 'patchtest'
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
const res = await request('/patchtest/public/patch-error.json', {
|
|
201
|
+
method: 'PATCH',
|
|
202
|
+
headers: { 'Content-Type': 'application/json' },
|
|
203
|
+
body: JSON.stringify({ op: 'add' }),
|
|
204
|
+
auth: 'patchtest'
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
assertStatus(res, 415);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
it('should return 404 for non-existent resource', async () => {
|
|
211
|
+
const patch = `
|
|
212
|
+
@prefix solid: <http://www.w3.org/ns/solid/terms#>.
|
|
213
|
+
_:patch a solid:InsertDeletePatch;
|
|
214
|
+
solid:inserts { <#me> <http://example.org/p> "test" }.
|
|
215
|
+
`;
|
|
216
|
+
|
|
217
|
+
const res = await request('/patchtest/public/nonexistent.json', {
|
|
218
|
+
method: 'PATCH',
|
|
219
|
+
headers: { 'Content-Type': 'text/n3' },
|
|
220
|
+
body: patch,
|
|
221
|
+
auth: 'patchtest'
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
assertStatus(res, 404);
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
it('should return 409 when patching non-JSON-LD resource', async () => {
|
|
228
|
+
// Create a plain text resource
|
|
229
|
+
await request('/patchtest/public/plain.txt', {
|
|
230
|
+
method: 'PUT',
|
|
231
|
+
headers: { 'Content-Type': 'text/plain' },
|
|
232
|
+
body: 'Hello World',
|
|
233
|
+
auth: 'patchtest'
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
const patch = `
|
|
237
|
+
@prefix solid: <http://www.w3.org/ns/solid/terms#>.
|
|
238
|
+
_:patch a solid:InsertDeletePatch;
|
|
239
|
+
solid:inserts { <#me> <http://example.org/p> "test" }.
|
|
240
|
+
`;
|
|
241
|
+
|
|
242
|
+
const res = await request('/patchtest/public/plain.txt', {
|
|
243
|
+
method: 'PATCH',
|
|
244
|
+
headers: { 'Content-Type': 'text/n3' },
|
|
245
|
+
body: patch,
|
|
246
|
+
auth: 'patchtest'
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
assertStatus(res, 409);
|
|
250
|
+
});
|
|
251
|
+
|
|
252
|
+
it('should return 409 for PATCH to container', async () => {
|
|
253
|
+
const patch = `
|
|
254
|
+
@prefix solid: <http://www.w3.org/ns/solid/terms#>.
|
|
255
|
+
_:patch a solid:InsertDeletePatch;
|
|
256
|
+
solid:inserts { <#me> <http://example.org/p> "test" }.
|
|
257
|
+
`;
|
|
258
|
+
|
|
259
|
+
const res = await request('/patchtest/public/', {
|
|
260
|
+
method: 'PATCH',
|
|
261
|
+
headers: { 'Content-Type': 'text/n3' },
|
|
262
|
+
body: patch,
|
|
263
|
+
auth: 'patchtest'
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
assertStatus(res, 409);
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
it('should require authentication for PATCH', async () => {
|
|
270
|
+
// Create a resource first
|
|
271
|
+
await request('/patchtest/public/patch-auth.json', {
|
|
272
|
+
method: 'PUT',
|
|
273
|
+
headers: { 'Content-Type': 'application/json' },
|
|
274
|
+
body: JSON.stringify({ test: true }),
|
|
275
|
+
auth: 'patchtest'
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
const patch = `
|
|
279
|
+
@prefix solid: <http://www.w3.org/ns/solid/terms#>.
|
|
280
|
+
_:patch a solid:InsertDeletePatch;
|
|
281
|
+
solid:inserts { <#me> <http://example.org/p> "test" }.
|
|
282
|
+
`;
|
|
283
|
+
|
|
284
|
+
// Try without auth
|
|
285
|
+
const res = await request('/patchtest/public/patch-auth.json', {
|
|
286
|
+
method: 'PATCH',
|
|
287
|
+
headers: { 'Content-Type': 'text/n3' },
|
|
288
|
+
body: patch
|
|
289
|
+
// No auth
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
assertStatus(res, 401);
|
|
293
|
+
});
|
|
294
|
+
});
|
|
295
|
+
});
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Solid-OIDC tests
|
|
3
|
+
* Tests for DPoP token verification
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { describe, it, before, after } from 'node:test';
|
|
7
|
+
import assert from 'node:assert';
|
|
8
|
+
import * as jose from 'jose';
|
|
9
|
+
import {
|
|
10
|
+
startTestServer,
|
|
11
|
+
stopTestServer,
|
|
12
|
+
request,
|
|
13
|
+
createTestPod,
|
|
14
|
+
getBaseUrl,
|
|
15
|
+
assertStatus
|
|
16
|
+
} from './helpers.js';
|
|
17
|
+
|
|
18
|
+
describe('Solid-OIDC', () => {
|
|
19
|
+
let keyPair;
|
|
20
|
+
let publicJwk;
|
|
21
|
+
|
|
22
|
+
before(async () => {
|
|
23
|
+
await startTestServer();
|
|
24
|
+
await createTestPod('oidctest');
|
|
25
|
+
|
|
26
|
+
// Generate a key pair for testing
|
|
27
|
+
keyPair = await jose.generateKeyPair('ES256');
|
|
28
|
+
publicJwk = await jose.exportJWK(keyPair.publicKey);
|
|
29
|
+
publicJwk.alg = 'ES256';
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
after(async () => {
|
|
33
|
+
await stopTestServer();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe('DPoP Header Parsing', () => {
|
|
37
|
+
// Use private folder - requires authentication
|
|
38
|
+
const privatePath = '/oidctest/private/';
|
|
39
|
+
|
|
40
|
+
it('should reject requests with DPoP auth but no DPoP proof', async () => {
|
|
41
|
+
const res = await fetch(`${getBaseUrl()}${privatePath}`, {
|
|
42
|
+
headers: {
|
|
43
|
+
'Authorization': 'DPoP some-token'
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
assertStatus(res, 401);
|
|
48
|
+
const body = await res.json();
|
|
49
|
+
assert.ok(body.message.includes('DPoP proof'), 'Should mention DPoP proof');
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('should reject invalid DPoP proof JWT', async () => {
|
|
53
|
+
const res = await fetch(`${getBaseUrl()}${privatePath}`, {
|
|
54
|
+
headers: {
|
|
55
|
+
'Authorization': 'DPoP some-token',
|
|
56
|
+
'DPoP': 'not-a-valid-jwt'
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
assertStatus(res, 401);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('should reject DPoP proof with wrong type', async () => {
|
|
64
|
+
// Create a JWT that's not a DPoP proof (wrong typ)
|
|
65
|
+
const wrongTypeJwt = await new jose.SignJWT({
|
|
66
|
+
htm: 'GET',
|
|
67
|
+
htu: `${getBaseUrl()}${privatePath}`,
|
|
68
|
+
iat: Math.floor(Date.now() / 1000),
|
|
69
|
+
jti: crypto.randomUUID()
|
|
70
|
+
})
|
|
71
|
+
.setProtectedHeader({ alg: 'ES256', typ: 'JWT', jwk: publicJwk })
|
|
72
|
+
.sign(keyPair.privateKey);
|
|
73
|
+
|
|
74
|
+
const res = await fetch(`${getBaseUrl()}${privatePath}`, {
|
|
75
|
+
headers: {
|
|
76
|
+
'Authorization': 'DPoP some-token',
|
|
77
|
+
'DPoP': wrongTypeJwt
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
assertStatus(res, 401);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('should reject DPoP proof with wrong HTTP method', async () => {
|
|
85
|
+
const dpopProof = await createDpopProof('POST', `${getBaseUrl()}${privatePath}`);
|
|
86
|
+
|
|
87
|
+
const res = await fetch(`${getBaseUrl()}${privatePath}`, {
|
|
88
|
+
method: 'GET',
|
|
89
|
+
headers: {
|
|
90
|
+
'Authorization': 'DPoP some-token',
|
|
91
|
+
'DPoP': dpopProof
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
assertStatus(res, 401);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('should reject DPoP proof with wrong URL', async () => {
|
|
99
|
+
const dpopProof = await createDpopProof('GET', 'https://other-server.example/');
|
|
100
|
+
|
|
101
|
+
const res = await fetch(`${getBaseUrl()}${privatePath}`, {
|
|
102
|
+
headers: {
|
|
103
|
+
'Authorization': 'DPoP some-token',
|
|
104
|
+
'DPoP': dpopProof
|
|
105
|
+
}
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
assertStatus(res, 401);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('should reject expired DPoP proof', async () => {
|
|
112
|
+
// Create a DPoP proof with old iat
|
|
113
|
+
const dpopProof = await new jose.SignJWT({
|
|
114
|
+
htm: 'GET',
|
|
115
|
+
htu: `${getBaseUrl()}${privatePath}`,
|
|
116
|
+
iat: Math.floor(Date.now() / 1000) - 600, // 10 minutes ago
|
|
117
|
+
jti: crypto.randomUUID()
|
|
118
|
+
})
|
|
119
|
+
.setProtectedHeader({ alg: 'ES256', typ: 'dpop+jwt', jwk: publicJwk })
|
|
120
|
+
.sign(keyPair.privateKey);
|
|
121
|
+
|
|
122
|
+
const res = await fetch(`${getBaseUrl()}${privatePath}`, {
|
|
123
|
+
headers: {
|
|
124
|
+
'Authorization': 'DPoP some-token',
|
|
125
|
+
'DPoP': dpopProof
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
assertStatus(res, 401);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('should reject DPoP proof missing jti', async () => {
|
|
133
|
+
const dpopProof = await new jose.SignJWT({
|
|
134
|
+
htm: 'GET',
|
|
135
|
+
htu: `${getBaseUrl()}${privatePath}`,
|
|
136
|
+
iat: Math.floor(Date.now() / 1000)
|
|
137
|
+
// missing jti
|
|
138
|
+
})
|
|
139
|
+
.setProtectedHeader({ alg: 'ES256', typ: 'dpop+jwt', jwk: publicJwk })
|
|
140
|
+
.sign(keyPair.privateKey);
|
|
141
|
+
|
|
142
|
+
const res = await fetch(`${getBaseUrl()}${privatePath}`, {
|
|
143
|
+
headers: {
|
|
144
|
+
'Authorization': 'DPoP some-token',
|
|
145
|
+
'DPoP': dpopProof
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
assertStatus(res, 401);
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
describe('Access Token Verification', () => {
|
|
154
|
+
const privatePath = '/oidctest/private/';
|
|
155
|
+
|
|
156
|
+
it('should reject token with invalid issuer (unreachable)', async () => {
|
|
157
|
+
// Create a valid DPoP proof
|
|
158
|
+
const dpopProof = await createDpopProof('GET', `${getBaseUrl()}${privatePath}`);
|
|
159
|
+
|
|
160
|
+
// Create a fake access token with unreachable issuer
|
|
161
|
+
const fakeToken = await new jose.SignJWT({
|
|
162
|
+
webid: 'https://example.com/user#me',
|
|
163
|
+
sub: 'https://example.com/user#me',
|
|
164
|
+
iss: 'https://nonexistent-idp.example.com',
|
|
165
|
+
aud: 'solid',
|
|
166
|
+
iat: Math.floor(Date.now() / 1000),
|
|
167
|
+
exp: Math.floor(Date.now() / 1000) + 3600
|
|
168
|
+
})
|
|
169
|
+
.setProtectedHeader({ alg: 'ES256' })
|
|
170
|
+
.sign(keyPair.privateKey);
|
|
171
|
+
|
|
172
|
+
const res = await fetch(`${getBaseUrl()}${privatePath}`, {
|
|
173
|
+
headers: {
|
|
174
|
+
'Authorization': `DPoP ${fakeToken}`,
|
|
175
|
+
'DPoP': dpopProof
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
assertStatus(res, 401);
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
describe('Bearer Token Fallback', () => {
|
|
184
|
+
it('should still accept simple Bearer tokens', async () => {
|
|
185
|
+
// This should work with our simple token system
|
|
186
|
+
const res = await request('/oidctest/public/', { auth: 'oidctest' });
|
|
187
|
+
assertStatus(res, 200);
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
it('should still accept simple Bearer tokens for writes', async () => {
|
|
191
|
+
const res = await request('/oidctest/public/solid-oidc-test.txt', {
|
|
192
|
+
method: 'PUT',
|
|
193
|
+
body: 'test content',
|
|
194
|
+
auth: 'oidctest'
|
|
195
|
+
});
|
|
196
|
+
assertStatus(res, 201);
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
// Helper to create DPoP proofs
|
|
201
|
+
async function createDpopProof(method, uri) {
|
|
202
|
+
return new jose.SignJWT({
|
|
203
|
+
htm: method,
|
|
204
|
+
htu: uri,
|
|
205
|
+
iat: Math.floor(Date.now() / 1000),
|
|
206
|
+
jti: crypto.randomUUID()
|
|
207
|
+
})
|
|
208
|
+
.setProtectedHeader({ alg: 'ES256', typ: 'dpop+jwt', jwk: publicJwk })
|
|
209
|
+
.sign(keyPair.privateKey);
|
|
210
|
+
}
|
|
211
|
+
});
|