Skip to content

Commit

Permalink
Adding new error, currently broken
Browse files Browse the repository at this point in the history
  • Loading branch information
dubwub committed Nov 27, 2024
1 parent ca8ec6e commit 5d163a4
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 9 deletions.
4 changes: 4 additions & 0 deletions fern/apis/fdr/definition/commons.yml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ errors:
status-code: 403
type: string

InvalidURLError:
status-code: 400
type: string

InternalError:
status-code: 500
type: string
Expand Down
4 changes: 2 additions & 2 deletions servers/fdr/src/__test__/local/services/docs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,9 @@ it("test domain special character permissions", async () => {

// expecting an error, because adding // to the domain should not bypass domain check
expect((startDocsRegisterResponse2 as any).error.content).toEqual({
body: `The following domains belong to another organization: ${domain.replace("https://", "")}`,
body: 'Domain URL is malformed',

Check failure on line 122 in servers/fdr/src/__test__/local/services/docs.test.ts

View workflow job for this annotation

GitHub Actions / lint

Strings must use doublequote
reason: "status-code",
statusCode: 403,
statusCode: 400,
});
});

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion servers/fdr/src/controllers/docs/v2/getDocsWriteV2Service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { v4 as uuidv4 } from "uuid";
import { DocsV2WriteService } from "../../../api";
import { FernRegistry } from "../../../api/generated";
import { OrgId } from "../../../api/generated/api";
import { DomainBelongsToAnotherOrgError } from "../../../api/generated/api/resources/commons/errors";
import { DomainBelongsToAnotherOrgError, InvalidURLError } from "../../../api/generated/api/resources/commons/errors";
import { DocsRegistrationIdNotFound } from "../../../api/generated/api/resources/docs/resources/v1/resources/write/errors";
import { LoadDocsForUrlResponse } from "../../../api/generated/api/resources/docs/resources/v2/resources/read";
import {
Expand All @@ -41,8 +41,19 @@ export interface DocsRegistrationInfo {
authType: AuthType;
}

function pathnameIsMalformed(pathname: string): boolean {
if (pathname === "" || pathname === "/") { return false; }
if (!/^.*([a-z0-9]).*$/.test(pathname)) { // does the pathname only contain special characters?
return true;
}
return false;
}

function validateAndParseFernDomainUrl({ app, url }: { app: FdrApplication; url: string }): ParsedBaseUrl {
const baseUrl = ParsedBaseUrl.parse(url);
if (pathnameIsMalformed(baseUrl.path)) {
throw new InvalidURLError("Domain URL is malformed");
}
if (!baseUrl.hostname.endsWith(app.config.domainSuffix)) {
throw new InvalidDomainError();
}
Expand Down
6 changes: 0 additions & 6 deletions servers/fdr/src/util/ParsedBaseUrl.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
const HAS_HTTPS_REGEX = /^https?:\/\//i;

function checkPathNameContainsMoreThanSpecialChars(pathname: string): boolean {
return !/^.*([a-z0-9]).*$/.test(pathname);
}

export class ParsedBaseUrl {
public readonly hostname: string;
public readonly path: string | undefined;
Expand Down Expand Up @@ -33,9 +29,7 @@ export class ParsedBaseUrl {
const parsedURL = new URL(urlWithHttpsPrefix);
return new ParsedBaseUrl({
hostname: parsedURL.hostname,
// clean up any special-character-only (no alphanumeric) paths
path:
checkPathNameContainsMoreThanSpecialChars(parsedURL.pathname) ||
parsedURL.pathname === "/" ||
parsedURL.pathname === ""
? undefined
Expand Down

0 comments on commit 5d163a4

Please sign in to comment.