Skip to content

Commit

Permalink
fix: Extract root as possible pod when using subdomains
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimvh committed Feb 27, 2024
1 parent 5086f22 commit 03f318a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/pods/generate/SubdomainIdentifierGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import type { IdentifierGenerator } from './IdentifierGenerator';
/**
* Generates identifiers by using the name as a subdomain on the base URL.
* Non-alphanumeric characters will be replaced with `-`.
*
* When extracting the pod, the base URl is also seen as a pod as there is no issue of nested containers here.
*/
export class SubdomainIdentifierGenerator implements IdentifierGenerator {
private readonly baseParts: { scheme: string; rest: string };
Expand All @@ -32,8 +34,8 @@ export class SubdomainIdentifierGenerator implements IdentifierGenerator {

const idx = path.indexOf(this.baseParts.rest);

// If the idx is smaller than this, either there was no match, or there is no subdomain
if (idx <= this.baseParts.scheme.length) {
// If the idx is smaller than this, there was no match
if (idx < 0) {
throw new BadRequestHttpError(`Invalid identifier ${path}`);
}

Expand Down
5 changes: 5 additions & 0 deletions test/unit/pods/generate/SubdomainIdentifierGenerator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ describe('A SubdomainIdentifierGenerator', (): void => {

it('errors when extracting if there is no pod.', async(): Promise<void> => {
const identifier = { path: 'http://example.com/bar/baz' };
expect(generator.extractPod(identifier)).toEqual({ path: 'http://example.com/' });
});

it('errors when extracting if the domain is wrong.', async(): Promise<void> => {
const identifier = { path: 'http://foo.example.org/bar/baz' };
expect((): any => generator.extractPod(identifier)).toThrow(BadRequestHttpError);
});
});

0 comments on commit 03f318a

Please sign in to comment.