Skip to content

Commit e39642a

Browse files
authored
Use the capability name and not the interface name in capability provider set. (#1015)
The keys on the capability provider set are arbritrary property names set by the protection, not the interface names as there can be multiple capabilities that share the same interface.
1 parent 785f4df commit e39642a

File tree

2 files changed

+16
-20
lines changed

2 files changed

+16
-20
lines changed

src/protections/ConfigMigration/CapabilitySetProviderMigration.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,24 +26,24 @@ export async function serverBanSynchronisationCapabilityRename(
2626
`The data for the capability provider config is corrupted.`
2727
);
2828
}
29-
const oldServerConsequencesInterfaceName = "serverConsequences";
29+
const protectionCapabilityName = "serverConsequences";
3030
const oldSimulatedServerConsequencesName = "SimulatedServerConsequences";
3131
const oldServerACLConsequencesName = "ServerACLConsequences";
32-
const oldServerConsequencesSet = input[oldServerConsequencesInterfaceName];
32+
const oldServerConsequencesSet = input[protectionCapabilityName];
3333
if (oldServerConsequencesSet === undefined) {
3434
return Ok({
3535
...input,
3636
[DRAUPNIR_SCHEMA_VERSION_KEY]: toVersion,
3737
} as unknown as CapabilityProviderConfig);
3838
}
3939
log.debug(
40-
`Migrating capability provider from ${oldServerConsequencesInterfaceName} to ServerBanSynchronisationCapability`
40+
`Migrating capability provider from ${protectionCapabilityName} to ServerBanSynchronisationCapability`
4141
);
4242
const makeProviderSet = (
4343
capabilityName: string
4444
): CapabilityProviderConfig => {
4545
return {
46-
["ServerBanSynchronisationCapability"]: {
46+
[protectionCapabilityName]: {
4747
capability_provider_name: capabilityName,
4848
},
4949
[DRAUPNIR_SCHEMA_VERSION_KEY]: toVersion,

test/unit/protections/serverBanSynchronisationCapabilityRenameTest.ts

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import {
1313
SimulatedServerBanSynchronisationCapability,
1414
} from "matrix-protection-suite";
1515

16+
const serverBanCapabilityName = "serverConsequences";
17+
1618
const serverBanSynchronisationCapabilityRenameSemanticType = SemanticType<
1719
typeof serverBanSynchronisationCapabilityRename
1820
>("serverBanSynchronisationCapabilityRename").Law({
@@ -25,20 +27,17 @@ const serverBanSynchronisationCapabilityRenameSemanticType = SemanticType<
2527
"Should be able to make the subject"
2628
);
2729
const input = {
28-
serverConsequences: {
30+
[serverBanCapabilityName]: {
2931
capability_provider_name: "SimulatedServerConsequences",
3032
},
3133
} as unknown as CapabilityProviderConfig;
3234
const toVersion = 1;
3335
const output = (await migration(input, toVersion)).expect(
3436
"Migration should succeed for SimulatedServerConsequences"
3537
);
36-
expect(
37-
output.ServerBanSynchronisationCapability?.capability_provider_name
38-
).toBe(SimulatedServerBanSynchronisationCapability.name);
39-
expect(
40-
(output as Record<string, unknown>).ServerConsequences
41-
).toBeUndefined();
38+
expect(output[serverBanCapabilityName]?.capability_provider_name).toBe(
39+
SimulatedServerBanSynchronisationCapability.name
40+
);
4241
},
4342
},
4443
updateServerACLConsequences: {
@@ -50,7 +49,7 @@ const serverBanSynchronisationCapabilityRenameSemanticType = SemanticType<
5049
"Should be able to make the subject"
5150
);
5251
const input = {
53-
serverConsequences: {
52+
[serverBanCapabilityName]: {
5453
capability_provider_name: "ServerACLConsequences",
5554
},
5655
} as unknown as CapabilityProviderConfig;
@@ -60,12 +59,9 @@ const serverBanSynchronisationCapabilityRenameSemanticType = SemanticType<
6059
);
6160

6261
expect(output[DRAUPNIR_SCHEMA_VERSION_KEY]).toBe(toVersion);
63-
expect(
64-
output.ServerBanSynchronisationCapability?.capability_provider_name
65-
).toBe(ServerACLSynchronisationCapability.name);
66-
expect(
67-
(output as Record<string, unknown>).ServerConsequences
68-
).toBeUndefined();
62+
expect(output[serverBanCapabilityName]?.capability_provider_name).toBe(
63+
ServerACLSynchronisationCapability.name
64+
);
6965
},
7066
},
7167
maintainOtherConfigs: {
@@ -91,7 +87,7 @@ const serverBanSynchronisationCapabilityRenameSemanticType = SemanticType<
9187
"SomeOtherProvider"
9288
);
9389
expect(
94-
(output as Record<string, unknown>).ServerBanSynchronisationCapability
90+
(output as Record<string, unknown>)[serverBanCapabilityName]
9591
).toBeUndefined();
9692
},
9793
},
@@ -104,7 +100,7 @@ const serverBanSynchronisationCapabilityRenameSemanticType = SemanticType<
104100
"Should be able to make the subject"
105101
);
106102
const input = {
107-
serverConsequences: {
103+
[serverBanCapabilityName]: {
108104
capability_provider_name: "CustomServerConsequences",
109105
},
110106
} as unknown as CapabilityProviderConfig;

0 commit comments

Comments
 (0)