-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
2 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
src/authentication/UnsecureConstantCredentialsExtractor.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { getLoggerFor } from '../logging/LogUtil'; | ||
import type { Credentials } from './Credentials'; | ||
import { CredentialsExtractor } from './CredentialsExtractor'; | ||
|
||
/** | ||
* Credentials extractor that authenticates a constant agent | ||
* (useful for development or debugging purposes). | ||
*/ | ||
export class UnsecureConstantCredentialsExtractor extends CredentialsExtractor { | ||
private readonly agent: Credentials; | ||
private readonly logger = getLoggerFor(this); | ||
|
||
public constructor(agent: string | Credentials) { | ||
super(); | ||
this.agent = typeof agent === 'string' ? { webId: agent } : agent; | ||
} | ||
|
||
public async handle(): Promise<Credentials> { | ||
this.logger.info(`Agent unsecurely claims to be ${this.agent.webId}`); | ||
return this.agent; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
test/unit/authentication/UnsecureConstantCredentialsExtractor.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
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 }); | ||
}); | ||
|
||
it('extracts constant credentials.', async(): Promise<void> => { | ||
const agent = {}; | ||
const extractor = new UnsecureConstantCredentialsExtractor(agent); | ||
await expect(extractor.handle()).resolves.toBe(agent); | ||
}); | ||
}); |