forked from svrjs/svrjs
Lint out the codebase.
This commit is contained in:
parent
f48125f4f2
commit
f552b34878
7 changed files with 51 additions and 68 deletions
|
@ -464,20 +464,7 @@ module.exports = (req, res, logFacilities, config, next) => {
|
||||||
/{server}/g,
|
/{server}/g,
|
||||||
"" +
|
"" +
|
||||||
(
|
(
|
||||||
(config.exposeServerVersion
|
config.generateServerString() +
|
||||||
? "SVR.JS/" +
|
|
||||||
version +
|
|
||||||
" (" +
|
|
||||||
getOS() +
|
|
||||||
"; " +
|
|
||||||
(process.isBun
|
|
||||||
? "Bun/v" +
|
|
||||||
process.versions.bun +
|
|
||||||
"; like Node.JS/" +
|
|
||||||
process.version
|
|
||||||
: "Node.JS/" + process.version) +
|
|
||||||
")"
|
|
||||||
: "SVR.JS") +
|
|
||||||
(!config.exposeModsInErrorPages || extName == undefined
|
(!config.exposeModsInErrorPages || extName == undefined
|
||||||
? ""
|
? ""
|
||||||
: " " + extName)
|
: " " + extName)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
const svrjsInfo = require("../../svrjs.json");
|
const svrjsInfo = require("../../svrjs.json");
|
||||||
const {version, name} = svrjsInfo;
|
const { version, name } = svrjsInfo;
|
||||||
const getOS = require("./getOS.js");
|
const getOS = require("./getOS.js");
|
||||||
|
|
||||||
function generateServerString(exposeServerVersion) {
|
function generateServerString(exposeServerVersion) {
|
||||||
|
|
|
@ -1,11 +1,7 @@
|
||||||
function matchHostname(hostname, reqHostname) {
|
function matchHostname(hostname, reqHostname) {
|
||||||
if (typeof hostname == "undefined" || hostname == "*") {
|
if (typeof hostname == "undefined" || hostname == "*") {
|
||||||
return true;
|
return true;
|
||||||
} else if (
|
} else if (reqHostname && hostname.indexOf("*.") == 0 && hostname != "*.") {
|
||||||
reqHostname &&
|
|
||||||
hostname.indexOf("*.") == 0 &&
|
|
||||||
hostname != "*."
|
|
||||||
) {
|
|
||||||
const hostnamesRoot = hostname.substring(2);
|
const hostnamesRoot = hostname.substring(2);
|
||||||
if (
|
if (
|
||||||
reqHostname == hostnamesRoot ||
|
reqHostname == hostnamesRoot ||
|
||||||
|
@ -19,6 +15,6 @@ function matchHostname(hostname, reqHostname) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
};
|
}
|
||||||
|
|
||||||
module.exports = matchHostname;
|
module.exports = matchHostname;
|
|
@ -5,7 +5,7 @@ jest.mock("os", () => ({
|
||||||
platform: jest.fn(),
|
platform: jest.fn(),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe("createRegex", () => {
|
describe("Regular expression creation function", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
os.platform.mockReset();
|
os.platform.mockReset();
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
const generateErrorStack = require("../../src/utils/generateErrorStack");
|
const generateErrorStack = require("../../src/utils/generateErrorStack");
|
||||||
|
|
||||||
describe("generateErrorStack", () => {
|
describe("Error stack generation function", () => {
|
||||||
test("should return the original stack if it is V8-style", () => {
|
test("should return the original stack if it is V8-style", () => {
|
||||||
const error = new Error("Test error");
|
const error = new Error("Test error");
|
||||||
error.stack = `Error: Test error
|
error.stack = `Error: Test error
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
const ipMatch = require("../../src/utils/ipMatch");
|
const ipMatch = require("../../src/utils/ipMatch");
|
||||||
|
|
||||||
describe("ipMatch", () => {
|
describe("IP address matching function", () => {
|
||||||
test("should return true if IP1 is empty", () => {
|
test("should return true if IP1 is empty", () => {
|
||||||
expect(ipMatch("", "192.168.1.1")).toBe(true);
|
expect(ipMatch("", "192.168.1.1")).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,51 +1,51 @@
|
||||||
const matchHostname = require('../../src/utils/matchHostname');
|
const matchHostname = require("../../src/utils/matchHostname");
|
||||||
|
|
||||||
describe('matchHostname', () => {
|
describe("Hostname matching function", () => {
|
||||||
test('should return true if hostname is undefined', () => {
|
test("should return true if hostname is undefined", () => {
|
||||||
expect(matchHostname(undefined, 'example.com')).toBe(true);
|
expect(matchHostname(undefined, "example.com")).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should return true if hostname is "*"', () => {
|
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', () => {
|
test("should return true if reqHostname matches hostname exactly", () => {
|
||||||
expect(matchHostname('example.com', 'example.com')).toBe(true);
|
expect(matchHostname("example.com", "example.com")).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should return false if reqHostname does not match hostname exactly', () => {
|
test("should return false if reqHostname does not match hostname exactly", () => {
|
||||||
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 matches the root', () => {
|
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', () => {
|
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', () => {
|
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 "*."', () => {
|
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', () => {
|
test("should return false if reqHostname is undefined", () => {
|
||||||
expect(matchHostname('example.com', undefined)).toBe(false);
|
expect(matchHostname("example.com", undefined)).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should return false if hostname does not start with "*." and reqHostname does not match', () => {
|
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', () => {
|
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', () => {
|
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);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Reference in a new issue