Add unit tests for server names with colons

This commit is contained in:
Christian Paul 2022-12-30 14:03:56 +01:00
parent 5354a5d67b
commit 671dfa9d71

View File

@ -37,10 +37,32 @@ describe("Config/BridgePermissions", () => {
const bridgePermissions = genBridgePermissions('@foo:bar', 'my-service', 'login');
expect(bridgePermissions.checkAction("@foo:bar", "my-service", "login")).to.be.true;
});
it("will return true for a matching actor domain", () => {
it("will return true for a matching actor server name", () => {
const bridgePermissions = genBridgePermissions('bar', 'my-service', 'login');
expect(bridgePermissions.checkAction("@foo:bar", "my-service", "login")).to.be.true;
});
describe("test various valid server names", () => {
it("will return true for a matching actor server name with an explicit port", () => {
const bridgePermissions = genBridgePermissions('bar:1234', 'my-service', 'login');
expect(bridgePermissions.checkAction("@foo:bar:1234", "my-service", "login")).to.be.true;
});
it("will return true for a matching actor server name with an IPv4 address", () => {
const bridgePermissions = genBridgePermissions('1.2.3.4', 'my-service', 'login');
expect(bridgePermissions.checkAction("@foo:1.2.3.4", "my-service", "login")).to.be.true;
});
it("will return true for a matching actor server name with an IPv4 address and an explicit port", () => {
const bridgePermissions = genBridgePermissions('1.2.3.4:1234', 'my-service', 'login');
expect(bridgePermissions.checkAction("@foo:1.2.3.4:1234", "my-service", "login")).to.be.true;
});
it("will return true for a matching actor server name with an IPv6 address", () => {
const bridgePermissions = genBridgePermissions('[1234:5678::abcd]', 'my-service', 'login');
expect(bridgePermissions.checkAction("@foo:[1234:5678::abcd]", "my-service", "login")).to.be.true;
});
it("will return true for a matching actor server name with an IPv6 address and an explicit port", () => {
const bridgePermissions = genBridgePermissions('[1234:5678::abcd]:5678', 'my-service', 'login');
expect(bridgePermissions.checkAction("@foo:[1234:5678::abcd]:5678", "my-service", "login")).to.be.true;
});
});
it("will return true for a wildcard actor", () => {
const bridgePermissions = genBridgePermissions('*', 'my-service', 'login');
expect(bridgePermissions.checkAction("@foo:bar", "my-service", "login")).to.be.true;
@ -119,5 +141,14 @@ describe("Config/BridgePermissions", () => {
).to.be.true;
});
});
it(`will return true when the server name is an IPv6 with an explicit port`, () => {
const bridgePermissions = genBridgePermissions("[1234:5678::abcd]:5678", "fake-service", "commands");
expect(
bridgePermissions.checkActionAny(
"@foo:[1234:5678::abcd]:5678",
"commands"
)
).to.be.true;
});
})
})