mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: Full rework of account management
Complete rewrite of the account management and related systems. Makes the architecture more modular, allowing for easier extensions and configurations.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import fetch from 'cross-fetch';
|
||||
import { outputJson } from 'fs-extra';
|
||||
import { ensureFile, writeJson } from 'fs-extra';
|
||||
import type { App } from '../../src/init/App';
|
||||
import { joinFilePath, joinUrl } from '../../src/util/PathUtil';
|
||||
import { getPort } from '../util/Util';
|
||||
@@ -11,34 +11,50 @@ const baseUrl = `http://localhost:${port}/`;
|
||||
const rootFilePath = getTestFolder('seeding-pods');
|
||||
|
||||
describe('A server with seeded pods', (): void => {
|
||||
const seedingJson = joinFilePath(rootFilePath, 'pods.json');
|
||||
const indexUrl = joinUrl(baseUrl, '.account/');
|
||||
let app: App;
|
||||
|
||||
beforeAll(async(): Promise<void> => {
|
||||
// Create seeding config
|
||||
await outputJson(seedingJson, [
|
||||
// Create the seed file
|
||||
const seed = [
|
||||
{
|
||||
podName: 'alice',
|
||||
email: 'alice@example.com',
|
||||
password: 'alice-password',
|
||||
email: 'test1@example.com',
|
||||
password: 'password1',
|
||||
pods: [
|
||||
{ name: 'pod1' },
|
||||
{ name: 'pod2' },
|
||||
],
|
||||
},
|
||||
{
|
||||
podName: 'bob',
|
||||
email: 'bob@example.com',
|
||||
password: 'bob-password',
|
||||
register: false,
|
||||
email: 'test2@example.com',
|
||||
password: 'password2',
|
||||
pods: [
|
||||
{ name: 'pod3' },
|
||||
// This will fail
|
||||
{ name: 'pod2' },
|
||||
],
|
||||
},
|
||||
]);
|
||||
|
||||
const variables = {
|
||||
...getDefaultVariables(port, baseUrl),
|
||||
'urn:solid-server:default:variable:seededPodConfigJson': seedingJson,
|
||||
};
|
||||
{
|
||||
// This will all fail
|
||||
email: 'test1@example.com',
|
||||
password: 'password3',
|
||||
pods: [
|
||||
{ name: 'pod4' },
|
||||
],
|
||||
},
|
||||
];
|
||||
const path = joinFilePath(rootFilePath, 'seed.json');
|
||||
await ensureFile(path);
|
||||
await writeJson(path, seed);
|
||||
|
||||
// Start server with the seed config
|
||||
const instances = await instantiateFromConfig(
|
||||
'urn:solid-server:test:Instances',
|
||||
getTestConfigPath('server-memory.json'),
|
||||
variables,
|
||||
{
|
||||
...getDefaultVariables(port, baseUrl),
|
||||
'urn:solid-server:default:variable:seedConfig': path,
|
||||
},
|
||||
) as Record<string, any>;
|
||||
({ app } = instances);
|
||||
await app.start();
|
||||
@@ -49,10 +65,33 @@ describe('A server with seeded pods', (): void => {
|
||||
await app.stop();
|
||||
});
|
||||
|
||||
it('has created the requested pods.', async(): Promise<void> => {
|
||||
let response = await fetch(joinUrl(baseUrl, 'alice/profile/card#me'));
|
||||
expect(response.status).toBe(200);
|
||||
response = await fetch(joinUrl(baseUrl, 'bob/profile/card#me'));
|
||||
expect(response.status).toBe(200);
|
||||
it('can seed accounts and pods.', async(): Promise<void> => {
|
||||
// Get the controls
|
||||
const res = await fetch(indexUrl);
|
||||
expect(res.status).toBe(200);
|
||||
const { controls } = await res.json();
|
||||
|
||||
// Verify that the pods exists
|
||||
await expect(fetch(joinUrl(baseUrl, 'pod1/'))).resolves.toEqual(expect.objectContaining({ status: 200 }));
|
||||
await expect(fetch(joinUrl(baseUrl, 'pod2/'))).resolves.toEqual(expect.objectContaining({ status: 200 }));
|
||||
await expect(fetch(joinUrl(baseUrl, 'pod3/'))).resolves.toEqual(expect.objectContaining({ status: 200 }));
|
||||
await expect(fetch(joinUrl(baseUrl, 'pod4/'))).resolves.toEqual(expect.objectContaining({ status: 404 }));
|
||||
|
||||
// Verify that we can log in with the accounts
|
||||
await expect(fetch(controls.password.login, {
|
||||
method: 'POST',
|
||||
headers: { 'content-type': 'application/json' },
|
||||
body: JSON.stringify({ email: 'test1@example.com', password: 'password1' }),
|
||||
})).resolves.toEqual(expect.objectContaining({ status: 200 }));
|
||||
await expect(fetch(controls.password.login, {
|
||||
method: 'POST',
|
||||
headers: { 'content-type': 'application/json' },
|
||||
body: JSON.stringify({ email: 'test2@example.com', password: 'password2' }),
|
||||
})).resolves.toEqual(expect.objectContaining({ status: 200 }));
|
||||
await expect(fetch(controls.password.login, {
|
||||
method: 'POST',
|
||||
headers: { 'content-type': 'application/json' },
|
||||
body: JSON.stringify({ email: 'test1@example.com', password: 'password3' }),
|
||||
})).resolves.toEqual(expect.objectContaining({ status: 403 }));
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user