2024-08-24 17:23:06 +02:00
|
|
|
const matchHostname = require("../../src/utils/matchHostname");
|
2024-08-24 17:21:09 +02:00
|
|
|
|
2024-08-24 17:23:06 +02:00
|
|
|
describe("Hostname matching function", () => {
|
|
|
|
test("should return true if hostname is undefined", () => {
|
|
|
|
expect(matchHostname(undefined, "example.com")).toBe(true);
|
2024-08-24 17:21:09 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
test('should return true if hostname is "*"', () => {
|
2024-08-24 17:23:06 +02:00
|
|
|
expect(matchHostname("*", "example.com")).toBe(true);
|
2024-08-24 17:21:09 +02:00
|
|
|
});
|
|
|
|
|
2024-08-24 17:23:06 +02:00
|
|
|
test("should return true if reqHostname matches hostname exactly", () => {
|
|
|
|
expect(matchHostname("example.com", "example.com")).toBe(true);
|
2024-08-24 17:21:09 +02:00
|
|
|
});
|
|
|
|
|
2024-08-24 17:23:06 +02:00
|
|
|
test("should return false if reqHostname does not match hostname exactly", () => {
|
|
|
|
expect(matchHostname("example.com", "example.org")).toBe(false);
|
2024-08-24 17:21:09 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
test('should return true if hostname starts with "*." and reqHostname matches the root', () => {
|
2024-08-24 17:23:06 +02:00
|
|
|
expect(matchHostname("*.example.com", "sub.example.com")).toBe(true);
|
2024-08-24 17:21:09 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
test('should return false if hostname starts with "*." and reqHostname does not match the root', () => {
|
2024-08-24 17:23:06 +02:00
|
|
|
expect(matchHostname("*.example.com", "example.org")).toBe(false);
|
2024-08-24 17:21:09 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
test('should return true if hostname starts with "*." and reqHostname is the root', () => {
|
2024-08-24 17:23:06 +02:00
|
|
|
expect(matchHostname("*.example.com", "example.com")).toBe(true);
|
2024-08-24 17:21:09 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
test('should return false if hostname is "*."', () => {
|
2024-08-24 17:23:06 +02:00
|
|
|
expect(matchHostname("*.", "example.com")).toBe(false);
|
2024-08-24 17:21:09 +02:00
|
|
|
});
|
|
|
|
|
2024-08-24 17:23:06 +02:00
|
|
|
test("should return false if reqHostname is undefined", () => {
|
|
|
|
expect(matchHostname("example.com", undefined)).toBe(false);
|
2024-08-24 17:21:09 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
test('should return false if hostname does not start with "*." and reqHostname does not match', () => {
|
2024-08-24 17:23:06 +02:00
|
|
|
expect(matchHostname("sub.example.com", "example.com")).toBe(false);
|
2024-08-24 17:21:09 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
test('should return true if hostname starts with "*." and reqHostname matches the root with additional subdomains', () => {
|
2024-08-24 17:23:06 +02:00
|
|
|
expect(matchHostname("*.example.com", "sub.sub.example.com")).toBe(true);
|
2024-08-24 17:21:09 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
test('should return false if hostname starts with "*." and reqHostname does not match the root with additional subdomains', () => {
|
2024-08-24 17:23:06 +02:00
|
|
|
expect(matchHostname("*.example.com", "sub.sub.example.org")).toBe(false);
|
2024-08-24 17:21:09 +02:00
|
|
|
});
|
|
|
|
});
|