1
0
Fork 0
forked from svrjs/svrjs

Lint out the codebase.

This commit is contained in:
Dorian Niemiec 2024-08-24 17:23:06 +02:00
parent f48125f4f2
commit f552b34878
7 changed files with 51 additions and 68 deletions

View file

@ -464,20 +464,7 @@ module.exports = (req, res, logFacilities, config, next) => {
/{server}/g,
"" +
(
(config.exposeServerVersion
? "SVR.JS/" +
version +
" (" +
getOS() +
"; " +
(process.isBun
? "Bun/v" +
process.versions.bun +
"; like Node.JS/" +
process.version
: "Node.JS/" + process.version) +
")"
: "SVR.JS") +
config.generateServerString() +
(!config.exposeModsInErrorPages || extName == undefined
? ""
: " " + extName)

View file

@ -1,11 +1,7 @@
function matchHostname(hostname, reqHostname) {
if (typeof hostname == "undefined" || hostname == "*") {
return true;
} else if (
reqHostname &&
hostname.indexOf("*.") == 0 &&
hostname != "*."
) {
} else if (reqHostname && hostname.indexOf("*.") == 0 && hostname != "*.") {
const hostnamesRoot = hostname.substring(2);
if (
reqHostname == hostnamesRoot ||
@ -19,6 +15,6 @@ function matchHostname(hostname, reqHostname) {
return true;
}
return false;
};
}
module.exports = matchHostname;

View file

@ -5,7 +5,7 @@ jest.mock("os", () => ({
platform: jest.fn(),
}));
describe("createRegex", () => {
describe("Regular expression creation function", () => {
beforeEach(() => {
os.platform.mockReset();
});

View file

@ -1,6 +1,6 @@
const generateErrorStack = require("../../src/utils/generateErrorStack");
describe("generateErrorStack", () => {
describe("Error stack generation function", () => {
test("should return the original stack if it is V8-style", () => {
const error = new Error("Test error");
error.stack = `Error: Test error

View file

@ -1,6 +1,6 @@
const ipMatch = require("../../src/utils/ipMatch");
describe("ipMatch", () => {
describe("IP address matching function", () => {
test("should return true if IP1 is empty", () => {
expect(ipMatch("", "192.168.1.1")).toBe(true);
});

View file

@ -1,51 +1,51 @@
const matchHostname = require('../../src/utils/matchHostname');
const matchHostname = require("../../src/utils/matchHostname");
describe('matchHostname', () => {
test('should return true if hostname is undefined', () => {
expect(matchHostname(undefined, 'example.com')).toBe(true);
describe("Hostname matching function", () => {
test("should return true if hostname is undefined", () => {
expect(matchHostname(undefined, "example.com")).toBe(true);
});
test('should return true if hostname is "*"', () => {
expect(matchHostname('*', 'example.com')).toBe(true);
expect(matchHostname("*", "example.com")).toBe(true);
});
test('should return true if reqHostname matches hostname exactly', () => {
expect(matchHostname('example.com', 'example.com')).toBe(true);
test("should return true if reqHostname matches hostname exactly", () => {
expect(matchHostname("example.com", "example.com")).toBe(true);
});
test('should return false if reqHostname does not match hostname exactly', () => {
expect(matchHostname('example.com', 'example.org')).toBe(false);
test("should return false if reqHostname does not match hostname exactly", () => {
expect(matchHostname("example.com", "example.org")).toBe(false);
});
test('should return true if hostname starts with "*." and reqHostname matches the root', () => {
expect(matchHostname('*.example.com', 'sub.example.com')).toBe(true);
expect(matchHostname("*.example.com", "sub.example.com")).toBe(true);
});
test('should return false if hostname starts with "*." and reqHostname does not match the root', () => {
expect(matchHostname('*.example.com', 'example.org')).toBe(false);
expect(matchHostname("*.example.com", "example.org")).toBe(false);
});
test('should return true if hostname starts with "*." and reqHostname is the root', () => {
expect(matchHostname('*.example.com', 'example.com')).toBe(true);
expect(matchHostname("*.example.com", "example.com")).toBe(true);
});
test('should return false if hostname is "*."', () => {
expect(matchHostname('*.', 'example.com')).toBe(false);
expect(matchHostname("*.", "example.com")).toBe(false);
});
test('should return false if reqHostname is undefined', () => {
expect(matchHostname('example.com', undefined)).toBe(false);
test("should return false if reqHostname is undefined", () => {
expect(matchHostname("example.com", undefined)).toBe(false);
});
test('should return false if hostname does not start with "*." and reqHostname does not match', () => {
expect(matchHostname('sub.example.com', 'example.com')).toBe(false);
expect(matchHostname("sub.example.com", "example.com")).toBe(false);
});
test('should return true if hostname starts with "*." and reqHostname matches the root with additional subdomains', () => {
expect(matchHostname('*.example.com', 'sub.sub.example.com')).toBe(true);
expect(matchHostname("*.example.com", "sub.sub.example.com")).toBe(true);
});
test('should return false if hostname starts with "*." and reqHostname does not match the root with additional subdomains', () => {
expect(matchHostname('*.example.com', 'sub.sub.example.org')).toBe(false);
expect(matchHostname("*.example.com", "sub.sub.example.org")).toBe(false);
});
});