diff --git a/apps/draupnir/src/appservice/bot/ProvisionCommand.tsx b/apps/draupnir/src/appservice/bot/ProvisionCommand.tsx index 30a99132..1d1392a7 100644 --- a/apps/draupnir/src/appservice/bot/ProvisionCommand.tsx +++ b/apps/draupnir/src/appservice/bot/ProvisionCommand.tsx @@ -15,7 +15,8 @@ export const AppserviceProvisionForUserCommand = describeCommand({ parameters: tuple({ name: "user", acceptor: MatrixUserIDPresentationType, - description: "The user to provision a bot for, bypassing user allocation limit", + description: + "The user to provision a bot for, bypassing user allocation limit", }), summary: "Provision a new Draupnir for a user while bypassing the per-user allocation limit.", @@ -37,6 +38,9 @@ export const AppserviceProvisionForUserCommand = describeCommand({ }, }); -AppserviceBotInterfaceAdaptor.describeRenderer(AppserviceProvisionForUserCommand, { - isAlwaysSupposedToUseDefaultRenderer: true, -}); +AppserviceBotInterfaceAdaptor.describeRenderer( + AppserviceProvisionForUserCommand, + { + isAlwaysSupposedToUseDefaultRenderer: true, + } +); diff --git a/apps/draupnir/test/appservice/integration/provisionTest.ts b/apps/draupnir/test/appservice/integration/provisionTest.ts index fd90779c..f35af119 100644 --- a/apps/draupnir/test/appservice/integration/provisionTest.ts +++ b/apps/draupnir/test/appservice/integration/provisionTest.ts @@ -18,7 +18,7 @@ import { newTestUser } from "../../integration/clientHelper"; import { getFirstReply } from "../../integration/commands/commandUtils"; import { MatrixClient } from "@vector-im/matrix-bot-sdk"; import { MjolnirAppService } from "../../../src/appservice/AppService"; -import { isError } from "matrix-protection-suite"; +import { isError, isOk } from "matrix-protection-suite"; import { StringUserID } from "@the-draupnir-project/matrix-basic-types"; interface Context extends Mocha.Context { @@ -45,10 +45,10 @@ describe("Test that the app service can provision a draupnir on invite of the ap name: { contains: "test" }, }); const moderatorUserID = (await moderator.getUserId()) as StringUserID; - const allowResult = await appservice.accessControl.allow(moderatorUserID); - if (isError(allowResult)) { - throw allowResult.error; - } + (await appservice.accessControl.allow(moderatorUserID)).expect( + "Failed to allow moderator" + ); + const roomWeWantProtecting = await moderator.createRoom(); // have the moderator invite the appservice bot in order to request a new draupnir this.moderator = moderator; @@ -101,10 +101,9 @@ describe("Test that the app service can provision a draupnir on invite of the ap }); const allowedUserID = (await allowedUser.getUserId()) as StringUserID; const blockedUserID = (await blockedUser.getUserId()) as StringUserID; - const allowResult = await appservice.accessControl.allow(allowedUserID); - if (isError(allowResult)) { - throw allowResult.error; - } + (await appservice.accessControl.allow(allowedUserID)).expect( + "Failed to allow allowed user" + ); const blockedProvisionResult = await appservice.draupnirManager.provisionNewDraupnir(blockedUserID); @@ -114,11 +113,9 @@ describe("Test that the app service can provision a draupnir on invite of the ap ); } - const allowedProvisionResult = - await appservice.draupnirManager.provisionNewDraupnir(allowedUserID); - if (isError(allowedProvisionResult)) { - throw allowedProvisionResult.error; - } + ( + await appservice.draupnirManager.provisionNewDraupnir(allowedUserID) + ).expect("Failed to provision for allow-listed user"); allowedUser.stop(); blockedUser.stop(); @@ -133,26 +130,21 @@ describe("Test that the app service can provision a draupnir on invite of the ap name: { contains: "multi-allowed" }, }); const allowedUserID = (await allowedUser.getUserId()) as StringUserID; - const allowResult = await appservice.accessControl.allow(allowedUserID); - if (isError(allowResult)) { - throw allowResult.error; - } + (await appservice.accessControl.allow(allowedUserID)).expect( + "Failed to allow user to provision bot" + ); - const firstProvisionResult = - await appservice.draupnirManager.provisionNewDraupnir(allowedUserID); - if (isError(firstProvisionResult)) { - throw firstProvisionResult.error; - } + ( + await appservice.draupnirManager.provisionNewDraupnir(allowedUserID) + ).expect("Failed to provision first bot for user"); - const secondProvisionResult = - await appservice.draupnirManager.provisionNewDraupnir(allowedUserID); - if (isError(secondProvisionResult)) { - throw secondProvisionResult.error; - } + ( + await appservice.draupnirManager.provisionNewDraupnir(allowedUserID) + ).expect("Failed to provision second bot for user"); const thirdProvisionResult = await appservice.draupnirManager.provisionNewDraupnir(allowedUserID); - if (!isError(thirdProvisionResult)) { + if (isOk(thirdProvisionResult)) { throw new TypeError( `Expected provisioning to fail after reaching limit for user ${allowedUserID}` ); @@ -170,24 +162,19 @@ describe("Test that the app service can provision a draupnir on invite of the ap name: { contains: "admin-bypass-allowed" }, }); const allowedUserID = (await allowedUser.getUserId()) as StringUserID; - const allowResult = await appservice.accessControl.allow(allowedUserID); - if (isError(allowResult)) { - throw allowResult.error; - } + (await appservice.accessControl.allow(allowedUserID)).expect( + "Failed to allow admin bypass user" + ); - const firstProvisionResult = - await appservice.draupnirManager.provisionNewDraupnir(allowedUserID); - if (isError(firstProvisionResult)) { - throw firstProvisionResult.error; - } + ( + await appservice.draupnirManager.provisionNewDraupnir(allowedUserID) + ).expect("Failed to provision initial bot for admin bypass user"); - const secondProvisionResult = + ( await appservice.draupnirManager.provisionNewDraupnirBypassingUserLimit( allowedUserID - ); - if (isError(secondProvisionResult)) { - throw secondProvisionResult.error; - } + ) + ).expect("Failed to provision bot while bypassing user limit"); allowedUser.stop(); }); diff --git a/apps/draupnir/test/appservice/integration/safeModeRecoverTest.ts b/apps/draupnir/test/appservice/integration/safeModeRecoverTest.ts index 38e00aa2..899a69a7 100644 --- a/apps/draupnir/test/appservice/integration/safeModeRecoverTest.ts +++ b/apps/draupnir/test/appservice/integration/safeModeRecoverTest.ts @@ -9,7 +9,6 @@ import { newTestUser } from "../../integration/clientHelper"; import { StandardProvisionHelper } from "../utils/ProvisionHelper"; import { setupHarness } from "../utils/harness"; import { testRecoverAndRestart } from "../../integration/commands/recoverCommandDetail"; -import { isError } from "matrix-protection-suite"; interface Context extends Mocha.Context { appservice?: MjolnirAppService; @@ -37,10 +36,10 @@ describe("Test safe mode recovery on a provisioned Draupnir", function () { name: { contains: "moderator" }, }); const moderatorUserID = (await moderator.getUserId()) as StringUserID; - const allowResult = await appservice.accessControl.allow(moderatorUserID); - if (isError(allowResult)) { - throw allowResult.error; - } + (await appservice.accessControl.allow(moderatorUserID)).expect( + "Failed to allow moderator" + ); + const initialDraupnir = ( await provisionHelper.provisionDraupnir(moderatorUserID) ).expect("Failed to provision a draupnir for the test"); diff --git a/apps/draupnir/test/appservice/integration/safeModeToggleTest.ts b/apps/draupnir/test/appservice/integration/safeModeToggleTest.ts index 183e1fc6..ed75214b 100644 --- a/apps/draupnir/test/appservice/integration/safeModeToggleTest.ts +++ b/apps/draupnir/test/appservice/integration/safeModeToggleTest.ts @@ -9,7 +9,6 @@ import { newTestUser } from "../../integration/clientHelper"; import { StandardProvisionHelper } from "../utils/ProvisionHelper"; import { setupHarness } from "../utils/harness"; import { SafeModeDraupnir } from "../../../src/safemode/DraupnirSafeMode"; -import { isError } from "matrix-protection-suite"; interface Context extends Mocha.Context { appservice?: MjolnirAppService; @@ -37,10 +36,10 @@ describe("Test safe mode commands on a provisioned Draupnir", function () { name: { contains: "moderator" }, }); const moderatorUserID = (await moderator.getUserId()) as StringUserID; - const allowResult = await appservice.accessControl.allow(moderatorUserID); - if (isError(allowResult)) { - throw allowResult.error; - } + (await appservice.accessControl.allow(moderatorUserID)).expect( + "Failed to allow moderator" + ); + const initialDraupnir = ( await provisionHelper.provisionDraupnir(moderatorUserID) ).expect("Failed to provision a draupnir for the test");