Merge branch 'main' into versions/5.0.0

This commit is contained in:
Joachim Van Herwegen
2022-05-24 10:40:27 +02:00
21 changed files with 2600 additions and 680 deletions

View File

@@ -1,4 +1,4 @@
#!/usr/bin/env node
#!/usr/bin/env ts-node
/* eslint-disable no-console */
import fetch from 'cross-fetch';
import urljoin from 'url-join';

View File

@@ -1,15 +0,0 @@
{
"extends": "@tsconfig/node14/tsconfig.json",
"compilerOptions": {
"declaration": true,
"inlineSources": true,
"newLine": "lf",
"outDir": "../tmp/cth",
"preserveConstEnums": true,
"sourceMap": true,
"stripInternal": true
},
"include": [
"createAccountCredentials.ts"
]
}

View File

@@ -5,7 +5,9 @@ import type { HttpRequest } from '../../../src/server/HttpRequest';
import type { HttpResponse } from '../../../src/server/HttpResponse';
describe('An OidcHttpHandler', (): void => {
const request: HttpRequest = {} as any;
const request: HttpRequest = {
url: '/.well-known/openid-configuration',
} as any;
const response: HttpResponse = {} as any;
let provider: jest.Mocked<Provider>;
let providerFactory: jest.Mocked<ProviderFactory>;
@@ -14,11 +16,12 @@ describe('An OidcHttpHandler', (): void => {
beforeEach(async(): Promise<void> => {
provider = {
callback: jest.fn().mockReturnValue(jest.fn()),
issuer: 'http://localhost:3000/',
} as any;
providerFactory = {
getProvider: jest.fn().mockResolvedValue(provider),
};
} as any;
handler = new OidcHttpHandler(providerFactory);
});
@@ -29,4 +32,24 @@ describe('An OidcHttpHandler', (): void => {
expect(provider.callback.mock.results[0].value).toHaveBeenCalledTimes(1);
expect(provider.callback.mock.results[0].value).toHaveBeenLastCalledWith(request, response);
});
it('rewrites the request when using base URL with root path.', async(): Promise<void> => {
Object.assign(provider, { issuer: 'http://localhost:3000/path/' });
request.url = '/path/.well-known/openid-configuration';
await expect(handler.handle({ request, response })).resolves.toBeUndefined();
expect(request.url).toBe('/.well-known/openid-configuration');
expect(provider.callback).toHaveBeenCalledTimes(1);
expect(provider.callback.mock.results[0].value).toHaveBeenCalledTimes(1);
expect(provider.callback.mock.results[0].value).toHaveBeenLastCalledWith(request, response);
});
it('respects query parameters when rewriting requests.', async(): Promise<void> => {
Object.assign(provider, { issuer: 'http://localhost:3000/path/' });
request.url = '/path/.well-known/openid-configuration?param1=value1';
await expect(handler.handle({ request, response })).resolves.toBeUndefined();
expect(request.url).toBe('/.well-known/openid-configuration?param1=value1');
expect(provider.callback).toHaveBeenCalledTimes(1);
expect(provider.callback.mock.results[0].value).toHaveBeenCalledTimes(1);
expect(provider.callback.mock.results[0].value).toHaveBeenLastCalledWith(request, response);
});
});

View File

@@ -85,6 +85,15 @@ describe('A WebIdAdapterFactory', (): void => {
});
});
it('can handle a context array.', async(): Promise<void> => {
json['@context'] = [ json['@context'] ];
fetchMock.mockResolvedValueOnce({ url: id, status: 200, text: (): string => JSON.stringify(json) });
await expect(adapter.find(id)).resolves.toEqual({
...json,
token_endpoint_auth_method: 'none',
});
});
it('errors if there is a client_id mismatch.', async(): Promise<void> => {
json.client_id = 'someone else';
fetchMock.mockResolvedValueOnce({ url: id, status: 200, text: (): string => JSON.stringify(json) });

View File

@@ -1,3 +1,4 @@
import { createHash } from 'crypto';
import { BasicRepresentation } from '../../../../src/http/representation/BasicRepresentation';
import type { Representation } from '../../../../src/http/representation/Representation';
import { RepresentationMetadata } from '../../../../src/http/representation/RepresentationMetadata';
@@ -5,7 +6,7 @@ import type { ResourceIdentifier } from '../../../../src/http/representation/Res
import { JsonResourceStorage } from '../../../../src/storage/keyvalue/JsonResourceStorage';
import type { ResourceStore } from '../../../../src/storage/ResourceStore';
import { NotFoundHttpError } from '../../../../src/util/errors/NotFoundHttpError';
import { isContainerIdentifier } from '../../../../src/util/PathUtil';
import { isContainerIdentifier, joinUrl } from '../../../../src/util/PathUtil';
import { readableToString } from '../../../../src/util/StreamUtil';
import { LDP } from '../../../../src/util/Vocabularies';
@@ -123,7 +124,23 @@ describe('A JsonResourceStorage', (): void => {
]);
});
it('can handle resources being deleted while iterating in the entries call.', async(): Promise<void> => {
//
});
it('converts keys that would result in too large filenames into an identifier that uses a hash.',
async(): Promise<void> => {
const longFileName = `${'sometext'.repeat(32)}.json`;
const b64LongFileName = Buffer.from(longFileName).toString('base64');
const longKey = `/container/${b64LongFileName}`;
const longKeyId = joinUrl(subContainerIdentifier, createHash('sha256').update(b64LongFileName).digest('hex'));
await storage.set(longKey, 'data');
// Check if a hash of the key has been used for the filename part of the key.
expect(data.has(longKeyId)).toBeTruthy();
data.clear();
// Check that normal keys stay unaffected
const normalKey = '/container/test';
const normalKeyId = joinUrl(containerIdentifier, normalKey);
await storage.set(normalKey, 'data');
expect(data.has(normalKeyId)).toBeTruthy();
});
});