mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-12 07:04:52 +09:00
Error responses now carry the registered name of the thrown error's class, and the requester rejects with an instance of that class instead of a generic RequestError. Error classes are registered like message classes, and plugins list their own in `errors`. RequestError is replaced by a hierarchy following the HTTP status codes: ClientError (ValidationError, ForbiddenError, NotFoundError, TimeoutError, ConflictError) and ServerError (InternalServerError). PermissionError is PermissionDeniedError and the config errors InvalidValue, InvalidField and InvalidAccess gain an Error suffix. Link logs only errors whose class is not registered. These arrive on the other side as InternalServerError with the original message and stack, so an error forwarded through the controller is logged once, where it was thrown. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
28 lines
975 B
JavaScript
28 lines
975 B
JavaScript
import assert from "node:assert/strict";
|
|
import * as lib from "@clusterio/lib";
|
|
|
|
describe("lib/data/messages_user", function() {
|
|
describe("UserBulkImportRequest", function() {
|
|
// A user that grants every permission, so only the importType switch
|
|
// can reject the request.
|
|
function grantAllUser() {
|
|
const checked = [];
|
|
return { checked, checkPermission(permission) { checked.push(permission); } };
|
|
}
|
|
|
|
it("should deny an unknown importType with a ValidationError", function() {
|
|
const user = grantAllUser();
|
|
assert.throws(
|
|
() => lib.UserBulkImportRequest.permission(user, { data: { importType: "foo", users: [] } }),
|
|
lib.ValidationError,
|
|
);
|
|
});
|
|
|
|
it("should check permissions for a known importType", function() {
|
|
const user = grantAllUser();
|
|
lib.UserBulkImportRequest.permission(user, { data: { importType: "admins", users: [] } });
|
|
assert.deepEqual(user.checked, ["core.user.bulk_import", "core.user.set_admin"]);
|
|
});
|
|
});
|
|
});
|