Use the capability name and not the interface name in capability provider set. (#1015)
Some checks failed
Tests / Build & Lint (push) Has been cancelled
Tests / Unit tests (push) Has been cancelled
Tests / Integration tests (push) Has been cancelled
Tests / Application Service Integration tests (push) Has been cancelled
Docker Hub - Develop / docker-latest (push) Has been cancelled

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.
This commit is contained in:
Gnuxie
2025-12-12 14:14:25 +00:00
committed by GitHub
parent 785f4df264
commit e39642a19d
2 changed files with 16 additions and 20 deletions

View File

@@ -26,10 +26,10 @@ export async function serverBanSynchronisationCapabilityRename(
`The data for the capability provider config is corrupted.`
);
}
const oldServerConsequencesInterfaceName = "serverConsequences";
const protectionCapabilityName = "serverConsequences";
const oldSimulatedServerConsequencesName = "SimulatedServerConsequences";
const oldServerACLConsequencesName = "ServerACLConsequences";
const oldServerConsequencesSet = input[oldServerConsequencesInterfaceName];
const oldServerConsequencesSet = input[protectionCapabilityName];
if (oldServerConsequencesSet === undefined) {
return Ok({
...input,
@@ -37,13 +37,13 @@ export async function serverBanSynchronisationCapabilityRename(
} as unknown as CapabilityProviderConfig);
}
log.debug(
`Migrating capability provider from ${oldServerConsequencesInterfaceName} to ServerBanSynchronisationCapability`
`Migrating capability provider from ${protectionCapabilityName} to ServerBanSynchronisationCapability`
);
const makeProviderSet = (
capabilityName: string
): CapabilityProviderConfig => {
return {
["ServerBanSynchronisationCapability"]: {
[protectionCapabilityName]: {
capability_provider_name: capabilityName,
},
[DRAUPNIR_SCHEMA_VERSION_KEY]: toVersion,

View File

@@ -13,6 +13,8 @@ import {
SimulatedServerBanSynchronisationCapability,
} from "matrix-protection-suite";
const serverBanCapabilityName = "serverConsequences";
const serverBanSynchronisationCapabilityRenameSemanticType = SemanticType<
typeof serverBanSynchronisationCapabilityRename
>("serverBanSynchronisationCapabilityRename").Law({
@@ -25,7 +27,7 @@ const serverBanSynchronisationCapabilityRenameSemanticType = SemanticType<
"Should be able to make the subject"
);
const input = {
serverConsequences: {
[serverBanCapabilityName]: {
capability_provider_name: "SimulatedServerConsequences",
},
} as unknown as CapabilityProviderConfig;
@@ -33,12 +35,9 @@ const serverBanSynchronisationCapabilityRenameSemanticType = SemanticType<
const output = (await migration(input, toVersion)).expect(
"Migration should succeed for SimulatedServerConsequences"
);
expect(
output.ServerBanSynchronisationCapability?.capability_provider_name
).toBe(SimulatedServerBanSynchronisationCapability.name);
expect(
(output as Record<string, unknown>).ServerConsequences
).toBeUndefined();
expect(output[serverBanCapabilityName]?.capability_provider_name).toBe(
SimulatedServerBanSynchronisationCapability.name
);
},
},
updateServerACLConsequences: {
@@ -50,7 +49,7 @@ const serverBanSynchronisationCapabilityRenameSemanticType = SemanticType<
"Should be able to make the subject"
);
const input = {
serverConsequences: {
[serverBanCapabilityName]: {
capability_provider_name: "ServerACLConsequences",
},
} as unknown as CapabilityProviderConfig;
@@ -60,12 +59,9 @@ const serverBanSynchronisationCapabilityRenameSemanticType = SemanticType<
);
expect(output[DRAUPNIR_SCHEMA_VERSION_KEY]).toBe(toVersion);
expect(
output.ServerBanSynchronisationCapability?.capability_provider_name
).toBe(ServerACLSynchronisationCapability.name);
expect(
(output as Record<string, unknown>).ServerConsequences
).toBeUndefined();
expect(output[serverBanCapabilityName]?.capability_provider_name).toBe(
ServerACLSynchronisationCapability.name
);
},
},
maintainOtherConfigs: {
@@ -91,7 +87,7 @@ const serverBanSynchronisationCapabilityRenameSemanticType = SemanticType<
"SomeOtherProvider"
);
expect(
(output as Record<string, unknown>).ServerBanSynchronisationCapability
(output as Record<string, unknown>)[serverBanCapabilityName]
).toBeUndefined();
},
},
@@ -104,7 +100,7 @@ const serverBanSynchronisationCapabilityRenameSemanticType = SemanticType<
"Should be able to make the subject"
);
const input = {
serverConsequences: {
[serverBanCapabilityName]: {
capability_provider_name: "CustomServerConsequences",
},
} as unknown as CapabilityProviderConfig;