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,
|
||||
"" +
|
||||
(
|
||||
(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)
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
const svrjsInfo = require("../../svrjs.json");
|
||||
const {version, name} = svrjsInfo;
|
||||
const { version, name } = svrjsInfo;
|
||||
const getOS = require("./getOS.js");
|
||||
|
||||
function generateServerString(exposeServerVersion) {
|
||||
return exposeServerVersion
|
||||
? name +
|
||||
"/" +
|
||||
version +
|
||||
" (" +
|
||||
getOS() +
|
||||
"; " +
|
||||
(process.isBun
|
||||
? "Bun/v" + process.versions.bun + "; like Node.JS/" + process.version
|
||||
: "Node.JS/" + process.version) +
|
||||
")"
|
||||
: name;
|
||||
? name +
|
||||
"/" +
|
||||
version +
|
||||
" (" +
|
||||
getOS() +
|
||||
"; " +
|
||||
(process.isBun
|
||||
? "Bun/v" + process.versions.bun + "; like Node.JS/" + process.version
|
||||
: "Node.JS/" + process.version) +
|
||||
")"
|
||||
: name;
|
||||
}
|
||||
|
||||
module.exports = generateServerString;
|
||||
module.exports = generateServerString;
|
||||
|
|
|
@ -1,24 +1,20 @@
|
|||
function matchHostname(hostname, reqHostname) {
|
||||
if (typeof hostname == "undefined" || hostname == "*") {
|
||||
return true;
|
||||
} else if (
|
||||
reqHostname &&
|
||||
hostname.indexOf("*.") == 0 &&
|
||||
hostname != "*."
|
||||
if (typeof hostname == "undefined" || hostname == "*") {
|
||||
return true;
|
||||
} else if (reqHostname && hostname.indexOf("*.") == 0 && hostname != "*.") {
|
||||
const hostnamesRoot = hostname.substring(2);
|
||||
if (
|
||||
reqHostname == hostnamesRoot ||
|
||||
(reqHostname.length > hostnamesRoot.length &&
|
||||
reqHostname.indexOf("." + hostnamesRoot) ==
|
||||
reqHostname.length - hostnamesRoot.length - 1)
|
||||
) {
|
||||
const hostnamesRoot = hostname.substring(2);
|
||||
if (
|
||||
reqHostname == hostnamesRoot ||
|
||||
(reqHostname.length > hostnamesRoot.length &&
|
||||
reqHostname.indexOf("." + hostnamesRoot) ==
|
||||
reqHostname.length - hostnamesRoot.length - 1)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
} else if (reqHostname && reqHostname == hostname) {
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
} else if (reqHostname && reqHostname == hostname) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
module.exports = matchHostname;
|
||||
module.exports = matchHostname;
|
||||
|
|
|
@ -5,7 +5,7 @@ jest.mock("os", () => ({
|
|||
platform: jest.fn(),
|
||||
}));
|
||||
|
||||
describe("createRegex", () => {
|
||||
describe("Regular expression creation function", () => {
|
||||
beforeEach(() => {
|
||||
os.platform.mockReset();
|
||||
});
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
|
Reference in a new issue