Skip to content

Commit

Permalink
Add test cases for getTopLevelDomainForSameSiteResolution function
Browse files Browse the repository at this point in the history
  • Loading branch information
deepjyoti30-st committed Sep 30, 2024
1 parent e08f011 commit 99c3044
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion test/utils.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const assert = require("assert");
const { getFromObjectCaseInsensitive } = require("../lib/build/utils");
const { getFromObjectCaseInsensitive, getTopLevelDomainForSameSiteResolution } = require("../lib/build/utils");

describe("SuperTokens utils test", () => {
it("Test getFromObjectCaseInsensitive", () => {
Expand All @@ -18,3 +18,39 @@ describe("SuperTokens utils test", () => {
assert.equal(getFromObjectCaseInsensitive("authoriZation", testObj), "test");
});
});

describe("getTopLevelDomainForSameSiteResolution test", () => {
it('should return "localhost" for localhost URLs', () => {
assert.equal(getTopLevelDomainForSameSiteResolution("http://localhost:3000"), "localhost");
assert.equal(getTopLevelDomainForSameSiteResolution("https://localhost"), "localhost");
});

it('should return "localhost" for localhost.org URLs', () => {
assert.equal(getTopLevelDomainForSameSiteResolution("http://localhost.org"), "localhost");
assert.equal(getTopLevelDomainForSameSiteResolution("https://localhost.org/test-path"), "localhost");
});

it('should return "localhost" for IP addresses', () => {
assert.equal(getTopLevelDomainForSameSiteResolution("http://127.0.0.1"), "localhost");
assert.equal(getTopLevelDomainForSameSiteResolution("https://192.168.1.1"), "localhost");
});

it("should return the correct domain for normal URLs", () => {
assert.equal(getTopLevelDomainForSameSiteResolution("https://www.example.com"), "example.com");
assert.equal(getTopLevelDomainForSameSiteResolution("http://sub.domain.co.uk"), "domain.co.uk");
});

it("should handle .amazonaws.com domains correctly", () => {
assert.equal(getTopLevelDomainForSameSiteResolution("https://my-instance.amazonaws.com"), "amazonaws.com");
});

it("should handle .local domains correctly", () => {
assert.equal(getTopLevelDomainForSameSiteResolution("http://myserver.local"), "myserver.local");
});

it("should throw an error for invalid domains", () => {
assert.throws(() => {
getTopLevelDomainForSameSiteResolution("http://invalid..com");
}, Error);
});
});

0 comments on commit 99c3044

Please sign in to comment.