mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-23 16:23:12 +09:00
Fix tests relating to permissions
This commit is contained in:
4 files changed
+19
-15
No files matched your search
@@ -8,16 +8,17 @@ export default class Permission {
|
|||||||
public name: string,
|
public name: string,
|
||||||
public title: string,
|
public title: string,
|
||||||
public description: string,
|
public description: string,
|
||||||
public grantByDefault?: boolean,
|
public grantByDefault: boolean = false,
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
static jsonSchema = Type.Object({
|
static jsonSchema = Type.Object({
|
||||||
name: Type.String(),
|
name: Type.String(),
|
||||||
title: Type.String(),
|
title: Type.String(),
|
||||||
description: Type.String(),
|
description: Type.String(),
|
||||||
|
grantByDefault: Type.Optional(Type.Boolean()),
|
||||||
});
|
});
|
||||||
|
|
||||||
static fromJSON(json: Static<typeof this.jsonSchema>) {
|
static fromJSON(json: Static<typeof this.jsonSchema>) {
|
||||||
return new this(json.name, json.title, json.description);
|
return new this(json.name, json.title, json.description, Boolean(json.grantByDefault));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1655,12 +1655,13 @@ describe("Integration of Clusterio", function() {
|
|||||||
});
|
});
|
||||||
it("should grant default permissions with --grant-default", async function() {
|
it("should grant default permissions with --grant-default", async function() {
|
||||||
await execCtl("role edit new --grant-default");
|
await execCtl("role edit new --grant-default");
|
||||||
let roles = await getControl().send(new lib.RoleListRequest());
|
const control = getControl();
|
||||||
|
let roles = await control.send(new lib.RoleListRequest());
|
||||||
let newRole = roles.find(role => role.name === "new");
|
let newRole = roles.find(role => role.name === "new");
|
||||||
let defaultPermissions = [...lib.permissions.values()]
|
const permissions = await control.send(new lib.PermissionListRequest());
|
||||||
|
const defaultPermissions = permissions
|
||||||
.filter(p => p.grantByDefault)
|
.filter(p => p.grantByDefault)
|
||||||
.map(p => p.name)
|
.map(p => p.name);
|
||||||
;
|
|
||||||
assert.deepEqual(new Set(newRole.permissions), new Set(defaultPermissions));
|
assert.deepEqual(new Set(newRole.permissions), new Set(defaultPermissions));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -240,14 +240,16 @@ describe("lib/config/definitions/validators", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("plugin.load_plugin", function() {
|
describe("plugin.load_plugin", function() {
|
||||||
const initialConfigFields = {
|
const initialConfigFields = {};
|
||||||
"global_chat.load_plugin": false,
|
|
||||||
"inventory_sync.load_plugin": false,
|
before(function() {
|
||||||
"player_auth.load_plugin": false,
|
for (const fieldName of Object.keys(InstanceConfig.fieldDefinitions)) {
|
||||||
"research_sync.load_plugin": false,
|
if (fieldName.endsWith("load_plugin")) {
|
||||||
"statistics_exporter.load_plugin": false,
|
initialConfigFields[fieldName] = false;
|
||||||
"subspace_storage.load_plugin": false,
|
}
|
||||||
};
|
}
|
||||||
|
});
|
||||||
|
|
||||||
it("should validate against factorio.enable_save_patching", function() {
|
it("should validate against factorio.enable_save_patching", function() {
|
||||||
class TestInstanceConfig extends InstanceConfig {
|
class TestInstanceConfig extends InstanceConfig {
|
||||||
static fieldDefinitions = { ...InstanceConfig.fieldDefinitions };
|
static fieldDefinitions = { ...InstanceConfig.fieldDefinitions };
|
||||||
|
|||||||
@@ -586,7 +586,7 @@ describe("lib/subscriptions", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("should throw if action is not supported", async function() {
|
it("should throw if action is not supported", async function() {
|
||||||
const request = new lib.SubscriptionRequest(StringPermissionEvent.name, "invalid action");
|
const request = new lib.SubscriptionRequest(RegisteredEvent.name, "invalid action");
|
||||||
await assert.rejects(subscriptions.handleRequest(
|
await assert.rejects(subscriptions.handleRequest(
|
||||||
getLink(0), request, connectorSetupDate[0].dst, connectorSetupDate[0].src
|
getLink(0), request, connectorSetupDate[0].dst, connectorSetupDate[0].src
|
||||||
), /unreachable case: invalid action/);
|
), /unreachable case: invalid action/);
|
||||||
|
|||||||
Reference in new issue
Block a user