Skip to content

Commit 1c93b9a

Browse files
committed
feat(core): add support for combo security ComboSecurityScheme #1416
1 parent f5bdf6e commit 1c93b9a

2 files changed

Lines changed: 76 additions & 1 deletion

File tree

packages/core/src/consumed-thing.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import UriTemplate = require("uritemplate");
4141
import { InteractionOutput, ActionInteractionOutput } from "./interaction-output";
4242
import {
4343
ActionElement,
44+
ComboSecurityScheme,
4445
EventElement,
4546
FormElementEvent,
4647
FormElementProperty,
@@ -449,7 +450,13 @@ export default class ConsumedThing extends Thing implements IConsumedThing {
449450
const ws = this.securityDefinitions[s + ""]; // String vs. string (fix wot-typescript-definitions?)
450451
// also push nosec in case of proxy
451452
if (ws != null) {
452-
scs.push(ws);
453+
if (ws.scheme === "combo") {
454+
const combo = ws as ComboSecurityScheme;
455+
const schemes = this.getSecuritySchemes(combo.allOf as string[]);
456+
scs.push(...schemes);
457+
} else {
458+
scs.push(ws);
459+
}
453460
}
454461
}
455462
return scs;

packages/core/test/ClientTest.ts

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,4 +805,72 @@ class WoTClientTest {
805805
// eslint-disable-next-line no-unused-expressions
806806
expect(WoTClientTest.servient.hasClientFor(tcf2.scheme)).to.be.not.true;
807807
}
808+
809+
@test "ensure combo security "(done: Mocha.Done) {
810+
try {
811+
const ct = new ConsumedThing(WoTClientTest.servient);
812+
ct.securityDefinitions = {
813+
basic_sc: {
814+
scheme: "basic",
815+
},
816+
opcua_secure_channel_sc: {
817+
scheme: "opcua-channel-security",
818+
},
819+
opcua_authetication_sc: {
820+
scheme: "opcua-authentication",
821+
},
822+
combo_sc: {
823+
scheme: "combo",
824+
allOf: ["opcua_secure_channel_sc", "opcua_authetication_sc"],
825+
},
826+
};
827+
ct.security = ["combo_sc"];
828+
const pc = new TestProtocolClient();
829+
const form: Form = {
830+
href: "https://example.com/",
831+
// security: ["apikey_sc"],
832+
};
833+
ct.ensureClientSecurity(pc, form);
834+
expect(pc.securitySchemes.length).equals(2);
835+
expect(pc.securitySchemes[0].scheme).equals("opcua-channel-security");
836+
expect(pc.securitySchemes[1].scheme).equals("opcua-authentication");
837+
done();
838+
} catch (err) {
839+
done(err);
840+
}
841+
}
842+
843+
@test "ensure combo security in form"(done: Mocha.Done) {
844+
try {
845+
const ct = new ConsumedThing(WoTClientTest.servient);
846+
ct.securityDefinitions = {
847+
basic_sc: {
848+
scheme: "basic",
849+
},
850+
opcua_secure_channel_sc: {
851+
scheme: "opcua-channel-security",
852+
},
853+
opcua_authetication_sc: {
854+
scheme: "opcua-authentication",
855+
},
856+
combo_sc: {
857+
scheme: "combo",
858+
allOf: ["opcua_secure_channel_sc", "opcua_authetication_sc"],
859+
},
860+
};
861+
ct.security = "basic";
862+
const pc = new TestProtocolClient();
863+
const form: Form = {
864+
href: "https://example.com/",
865+
security: ["combo_sc"],
866+
};
867+
ct.ensureClientSecurity(pc, form);
868+
expect(pc.securitySchemes.length).equals(2);
869+
expect(pc.securitySchemes[0].scheme).equals("opcua-channel-security");
870+
expect(pc.securitySchemes[1].scheme).equals("opcua-authentication");
871+
done();
872+
} catch (err) {
873+
done(err);
874+
}
875+
}
808876
}

0 commit comments

Comments
 (0)