mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: Let CredentialsExtractors specify what type of Credentials they generate
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { createSolidTokenVerifier } from '@solid/access-token-verifier';
|
||||
import { BearerWebIdExtractor } from '../../../src/authentication/BearerWebIdExtractor';
|
||||
import { CredentialGroup } from '../../../src/authentication/Credentials';
|
||||
import type { HttpRequest } from '../../../src/server/HttpRequest';
|
||||
import { BadRequestHttpError } from '../../../src/util/errors/BadRequestHttpError';
|
||||
import { NotImplementedHttpError } from '../../../src/util/errors/NotImplementedHttpError';
|
||||
@@ -57,7 +58,7 @@ describe('A BearerWebIdExtractor', (): void => {
|
||||
|
||||
it('returns the extracted WebID.', async(): Promise<void> => {
|
||||
const result = webIdExtractor.handleSafe(request);
|
||||
await expect(result).resolves.toEqual({ webId: 'http://alice.example/card#me' });
|
||||
await expect(result).resolves.toEqual({ [CredentialGroup.agent]: { webId: 'http://alice.example/card#me' }});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { createSolidTokenVerifier } from '@solid/access-token-verifier';
|
||||
import { CredentialGroup } from '../../../src/authentication/Credentials';
|
||||
import { DPoPWebIdExtractor } from '../../../src/authentication/DPoPWebIdExtractor';
|
||||
import type { HttpRequest } from '../../../src/server/HttpRequest';
|
||||
import { BadRequestHttpError } from '../../../src/util/errors/BadRequestHttpError';
|
||||
@@ -85,7 +86,7 @@ describe('A DPoPWebIdExtractor', (): void => {
|
||||
|
||||
it('returns the extracted WebID.', async(): Promise<void> => {
|
||||
const result = webIdExtractor.handleSafe(request);
|
||||
await expect(result).resolves.toEqual({ webId: 'http://alice.example/card#me' });
|
||||
await expect(result).resolves.toEqual({ [CredentialGroup.agent]: { webId: 'http://alice.example/card#me' }});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { CredentialGroup } from '../../../src/authentication/Credentials';
|
||||
import { EmptyCredentialsExtractor } from '../../../src/authentication/EmptyCredentialsExtractor';
|
||||
import type { HttpRequest } from '../../../src/server/HttpRequest';
|
||||
import { NotImplementedHttpError } from '../../../src/util/errors/NotImplementedHttpError';
|
||||
@@ -15,6 +16,6 @@ describe('An EmptyCredentialsExtractor', (): void => {
|
||||
it('returns the empty credentials.', async(): Promise<void> => {
|
||||
const headers = {};
|
||||
const result = extractor.handleSafe({ headers } as HttpRequest);
|
||||
await expect(result).resolves.toEqual({});
|
||||
await expect(result).resolves.toEqual({ [CredentialGroup.public]: {}});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
import { CredentialGroup } from '../../../src/authentication/Credentials';
|
||||
import { UnsecureConstantCredentialsExtractor } from '../../../src/authentication/UnsecureConstantCredentialsExtractor';
|
||||
|
||||
describe('An UnsecureConstantCredentialsExtractor', (): void => {
|
||||
it('extracts a constant WebID.', async(): Promise<void> => {
|
||||
const agent = 'http://alice.example/card#me';
|
||||
const extractor = new UnsecureConstantCredentialsExtractor(agent);
|
||||
await expect(extractor.handle()).resolves.toEqual({ webId: agent });
|
||||
await expect(extractor.handle()).resolves.toEqual({ [CredentialGroup.agent]: { webId: agent }});
|
||||
});
|
||||
|
||||
it('extracts constant credentials.', async(): Promise<void> => {
|
||||
const agent = {};
|
||||
const extractor = new UnsecureConstantCredentialsExtractor(agent);
|
||||
await expect(extractor.handle()).resolves.toBe(agent);
|
||||
await expect(extractor.handle()).resolves.toEqual({ [CredentialGroup.agent]: agent });
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { CredentialGroup } from '../../../src/authentication/Credentials';
|
||||
import { UnsecureWebIdExtractor } from '../../../src/authentication/UnsecureWebIdExtractor';
|
||||
import type { HttpRequest } from '../../../src/server/HttpRequest';
|
||||
import { NotImplementedHttpError } from '../../../src/util/errors/NotImplementedHttpError';
|
||||
@@ -22,6 +23,6 @@ describe('An UnsecureWebIdExtractor', (): void => {
|
||||
it('returns the authorization header as WebID if there is one.', async(): Promise<void> => {
|
||||
const headers = { authorization: 'WebID http://alice.example/card#me' };
|
||||
const result = extractor.handleSafe({ headers } as HttpRequest);
|
||||
await expect(result).resolves.toEqual({ webId: 'http://alice.example/card#me' });
|
||||
await expect(result).resolves.toEqual({ [CredentialGroup.agent]: { webId: 'http://alice.example/card#me' }});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user