Made user ids case insensitive

This commit is contained in:
Cooldude2606 authored and Daniel committed 2024-11-22 04:06:34 -08:00
1 parent 41d76ff757
commit bdf02a5ea2
15 files changed
+130 -45

No files matched your search

+1 -1
View File
@@ -8,7 +8,7 @@ describe("controller/src/UserManager", function() {
const userManager = new UserManager({});
it("should track online users", function() {
let user = ControllerUser.fromJSON({ name: "admin", roles: [1] });
userManager.users.set(user.name, user);
userManager.users.set(user.id, user);
assert(!userManager.onlineUsers.has(user));
assert.deepEqual(user.instances, new Set());
+1 -1
View File
@@ -104,7 +104,7 @@ describe("controller/src/routes", function() {
data: "totally a zip file",
});
assert.equal(response.statusCode, 401);
controller.userManager.users.get("test").tokenValidAfter = Math.floor((Date.now() + 60e3) / 1000);
controller.userManager.getByName("test").tokenValidAfter = Math.floor((Date.now() + 60e3) / 1000);
response = await phin({
url: `http://localhost:${port}/api/upload-save?instance_id=123&filename=file.zip`, method: "POST",
headers: {
+20 -5
View File
@@ -97,7 +97,7 @@ async function deleteSave(instanceId, save) {
async function getUsers() {
let users = await getControl().send(new lib.UserListRequest());
return new Map(users.map(user => [user.name, user]));
return new Map(users.map(user => [user.id, user]));
}
function jsonArg(value) {
@@ -663,6 +663,11 @@ describe("Integration of Clusterio", function() {
const removeCommandStateUpper = await sendRcon(44, "/banlist get test_RCON_ban");
assert.equal(removeCommandStateLower, "test_rcon_ban is not banned.\n", "User is banned");
assert.equal(removeCommandStateUpper, "test_RCON_ban is not banned.\n", "User is banned");
// Check it is case insensitive by checking it was converted correctly
const users = await getUsers();
assert(users.has("test_rcon_ban"), "User ID was not lowercase");
assert(!users.has("test_RCON_ban"), "Username was not converted to User ID");
});
it("should send whitelist commands to running instances", async function() {
slowTest(this);
@@ -691,6 +696,11 @@ describe("Integration of Clusterio", function() {
"test_rcon_whitelist is not whitelisted.\n", "User is whitelisted");
assert.equal(removeCommandStateUpper,
"test_RCON_whitelist is not whitelisted.\n", "User is whitelisted");
// Check it is case insensitive by checking it was converted correctly
const users = await getUsers();
assert(users.has("test_rcon_whitelist"), "User ID was not lowercase");
assert(!users.has("test_RCON_whitelist"), "Username was not converted to User ID");
});
it("should send admin list commands to running instances", async function() {
this.skip(); // It is not currently possible to get admin state without the player joining the game
@@ -714,6 +724,11 @@ describe("Integration of Clusterio", function() {
const removeCommandStateUpper = await sendRcon(44, "/admins get test_RCON_admin");
assert.equal(removeCommandStateLower, "test_rcon_admin is not admin.\n", "User is admin");
assert.equal(removeCommandStateUpper, "test_RCON_admin is not admin.\n", "User is admin");
// Check it is case insensitive by checking it was converted correctly
const users = await getUsers();
assert(users.has("test_rcon_admin"), "User ID was not lowercase");
assert(!users.has("test_RCON_admin"), "Username was not converted to User ID");
});
});
@@ -1278,10 +1293,10 @@ describe("Integration of Clusterio", function() {
getControl().userUpdates = [];
await execCtl("user create temp");
let users = await getControl().send(new lib.UserListRequest());
let tempUser = users.find(user => user.name === "temp");
let tempUser = users.find(user => user.id === "temp");
assert(tempUser, "user was not created");
assert.equal(getControl().userUpdates.length, 1);
assert.equal(getControl().userUpdates[0].name, "temp");
assert.equal(getControl().userUpdates[0].id, "temp");
});
});
@@ -1310,7 +1325,7 @@ describe("Integration of Clusterio", function() {
getControl().userUpdates = [];
await execCtl('user set-roles temp "Cluster Admin"');
let users = await getControl().send(new lib.UserListRequest());
let tempUser = users.find(user => user.name === "temp");
let tempUser = users.find(user => user.id === "temp");
assert.deepEqual(tempUser.roleIds, new Set([0]));
assert.equal(getControl().userUpdates.length, 1);
});
@@ -1346,7 +1361,7 @@ describe("Integration of Clusterio", function() {
getControl().userUpdates = [];
await execCtl("user delete temp");
let users = await getControl().send(new lib.UserListRequest());
let tempUser = users.find(user => user.name === "temp");
let tempUser = users.find(user => user.id === "temp");
assert(!tempUser, "user was note deleted");
assert.equal(getControl().userUpdates.length, 1);
assert.equal(getControl().userUpdates[0].isDeleted, true);
+1 -1
View File
@@ -53,7 +53,7 @@ function connectInstance(controller, host, instanceId) {
function connectControl(controller, controlId) {
const [controllerSide, controlSide] = lib.VirtualConnector.makePair(addr("controller"), addr({ controlId }));
const registerData = new lib.RegisterControlData("", "0.0.0");
let user = controller.userManager.users.get("test");
let user = controller.userManager.getByName("test");
if (!user) {
user = controller.userManager.createUser("test");
}