feat: Store account settings separately

Account settings are stored using the WebID as key.
Reason for using the WebID is that this allows faster access to the settings
in authenticated requests.
A consequence of this is that passwords are now always required during registration,
and that there can only be 1 account per WebID.
This commit is contained in:
Joachim Van Herwegen
2021-08-30 16:47:34 +02:00
parent f40e2c768f
commit 6c4ccb334d
11 changed files with 246 additions and 166 deletions

View File

@@ -23,7 +23,15 @@ const configs: [string, any][] = [
// Tests are very similar to subdomain/pod tests. Would be nice if they can be combined
describe.each(configs)('A dynamic pod server with template config %s', (template, { teardown }): void => {
let app: App;
const settings = { podName: 'alice', webId: 'http://test.com/#alice', email: 'alice@test.email', template, createPod: true };
const settings = {
podName: 'alice',
webId: 'http://test.com/#alice',
email: 'alice@test.email',
password: 'password',
confirmPassword: 'password',
template,
createPod: true,
};
const podUrl = `${baseUrl}${settings.podName}/`;
beforeAll(async(): Promise<void> => {
@@ -109,10 +117,11 @@ describe.each(configs)('A dynamic pod server with template config %s', (template
});
it('should not be able to create a pod with the same name.', async(): Promise<void> => {
const newSettings = { ...settings, webId: 'http://test.com/#bob', email: 'bob@test.email' };
const res = await fetch(`${baseUrl}idp/register`, {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify(settings),
body: JSON.stringify(newSettings),
});
expect(res.status).toBe(409);
await expect(res.text()).resolves.toContain(`There already is a pod at ${podUrl}`);

View File

@@ -53,6 +53,7 @@ describe('A Solid server with IDP', (): void => {
const oidcIssuer = baseUrl;
const card = joinUrl(baseUrl, 'profile/card');
const webId = `${card}#me`;
const webId2 = `${card}#someoneElse`;
const email = 'test@test.com';
const password = 'password!';
const password2 = 'password2!';
@@ -241,25 +242,32 @@ describe('A Solid server with IDP', (): void => {
});
});
describe('creating pods without registering', (): void => {
describe('creating pods without registering with the IDP', (): void => {
let formBody: string;
let registrationTriple: string;
const podName = 'myPod';
beforeAll(async(): Promise<void> => {
// We will need this twice
formBody = stringify({ email, webId, podName, createPod: 'ok' });
formBody = stringify({
email: 'bob@test.email',
webId: webId2,
password,
confirmPassword: password,
podName,
createPod: 'ok',
});
});
it('sends the form once to receive the registration triple.', async(): Promise<void> => {
const res = await postForm(`${baseUrl}idp/register`, formBody);
expect(res.status).toBe(400);
registrationTriple = extractRegistrationTriple(await res.text(), webId);
registrationTriple = extractRegistrationTriple(await res.text(), webId2);
});
it('updates the webId with the registration token.', async(): Promise<void> => {
const patchBody = `INSERT DATA { ${registrationTriple} }`;
const res = await fetch(webId, {
const res = await fetch(webId2, {
method: 'PATCH',
headers: { 'content-type': 'application/sparql-update' },
body: patchBody,

View File

@@ -28,7 +28,14 @@ const stores: [string, any][] = [
// Simulating subdomains using the forwarded header so no DNS changes are required
describe.each(stores)('A subdomain server with %s', (name, { storeConfig, teardown }): void => {
let app: App;
const settings = { podName: 'alice', webId: 'http://test.com/#alice', email: 'alice@test.email', createPod: true };
const settings = {
podName: 'alice',
webId: 'http://test.com/#alice',
email: 'alice@test.email',
password: 'password',
confirmPassword: 'password',
createPod: true,
};
const podHost = `alice.localhost:${port}`;
const podUrl = `http://${podHost}/`;
@@ -142,10 +149,11 @@ describe.each(stores)('A subdomain server with %s', (name, { storeConfig, teardo
});
it('should not be able to create a pod with the same name.', async(): Promise<void> => {
const newSettings = { ...settings, webId: 'http://test.com/#bob', email: 'bob@test.email' };
const res = await fetch(`${baseUrl}idp/register`, {
method: 'POST',
headers: { 'content-type': 'application/json' },
body: JSON.stringify(settings),
body: JSON.stringify(newSettings),
});
expect(res.status).toBe(409);
await expect(res.text()).resolves.toContain(`There already is a resource at ${podUrl}`);