-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: remove trailing slash in origins; add unit test framework (#356)
- Loading branch information
Showing
6 changed files
with
1,651 additions
and
42 deletions.
There are no files selected for viewing
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,5 @@ | ||
module.exports = { | ||
preset: "ts-jest", | ||
testEnvironment: "node", | ||
// Add any other Jest configuration options here | ||
}; |
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
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
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,24 @@ | ||
import { sanitizeOrigin } from "../server/middleware/cors"; | ||
|
||
describe("sanitizeOrigin", () => { | ||
it("with leading and trailing slashes", () => { | ||
expect(sanitizeOrigin("/foobar/")).toEqual(RegExp("foobar")); | ||
}); | ||
it("with leading wildcard", () => { | ||
expect(sanitizeOrigin("*.foobar.com")).toEqual(RegExp(".*.foobar.com")); | ||
}); | ||
it("with thirdweb domains", () => { | ||
expect(sanitizeOrigin("https://thirdweb-preview.com")).toEqual( | ||
new RegExp(/^https?:\/\/.*\.thirdweb-preview\.com$/), | ||
); | ||
expect(sanitizeOrigin("https://thirdweb-dev.com")).toEqual( | ||
new RegExp(/^https?:\/\/.*\.thirdweb-dev\.com$/), | ||
); | ||
}); | ||
it("with trailing slashes", () => { | ||
expect(sanitizeOrigin("https://foobar.com/")).toEqual("https://foobar.com"); | ||
}); | ||
it("fallback: don't change origin", () => { | ||
expect(sanitizeOrigin("https://foobar.com")).toEqual("https://foobar.com"); | ||
}); | ||
}); |
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
Oops, something went wrong.