feat: Create SubdomainIdentifierStrategy

This strategy interprets all subdomains of the base to also be root containers.
This commit is contained in:
Joachim Van Herwegen
2021-02-12 11:52:18 +01:00
parent bdb3621ee3
commit 29df380396
7 changed files with 136 additions and 39 deletions

View File

@@ -0,0 +1,32 @@
import { SubdomainIdentifierStrategy } from '../../../../src/util/identifiers/SubdomainIdentifierStrategy';
describe('A SubdomainIdentifierStrategy', (): void => {
const baseUrl = 'http://test.com/foo/';
const strategy = new SubdomainIdentifierStrategy(baseUrl);
it('supports URLs in its domain.', async(): Promise<void> => {
expect(strategy.supportsIdentifier({ path: 'http://test.com/foo/' })).toBe(true);
expect(strategy.supportsIdentifier({ path: 'http://alice.test.com/foo/' })).toBe(true);
expect(strategy.supportsIdentifier({ path: 'http://a.b.c.test.com/foo/' })).toBe(true);
expect(strategy.supportsIdentifier({ path: 'http://test.com/foo/bar' })).toBe(true);
expect(strategy.supportsIdentifier({ path: 'http://alice.test.com/foo/bar' })).toBe(true);
expect(strategy.supportsIdentifier({ path: 'http://a.b.c.test.com/foo/bar' })).toBe(true);
});
it('does not support URLs outside of its domain.', async(): Promise<void> => {
expect(strategy.supportsIdentifier({ path: 'http://fake.com/http://test.com/foo/' })).toBe(false);
expect(strategy.supportsIdentifier({ path: 'http://fake.com/test.com/foo/' })).toBe(false);
expect(strategy.supportsIdentifier({ path: 'http://faketest.com/foo/' })).toBe(false);
expect(strategy.supportsIdentifier({ path: 'http://test.com/foo' })).toBe(false);
expect(strategy.supportsIdentifier({ path: 'ftp://test.com/foo/' })).toBe(false);
});
it('identifiers the base and all subdomains as root containers.', async(): Promise<void> => {
expect(strategy.isRootContainer({ path: 'http://test.com/foo/' })).toBe(true);
expect(strategy.isRootContainer({ path: 'http://alice.test.com/foo/' })).toBe(true);
expect(strategy.isRootContainer({ path: 'http://test.com/foo/bar' })).toBe(false);
expect(strategy.isRootContainer({ path: 'http://alice.test.com/foo/bar' })).toBe(false);
});
});