@@ -27,7 +27,7 @@ import { Subscription } from "rxjs/Subscription";
2727
2828import Servient from "../src/servient" ;
2929import ConsumedThing from "../src/consumed-thing" ;
30- import { Form , SecurityScheme } from "../src/thing-description" ;
30+ import { AllOfSecurityScheme , Form , OneOfSecurityScheme , SecurityScheme } from "../src/thing-description" ;
3131import { ProtocolClient , ProtocolClientFactory } from "../src/protocol-interfaces" ;
3232import { Content } from "../src/content" ;
3333import { ContentSerdes } from "../src/content-serdes" ;
@@ -37,6 +37,7 @@ import { createLoggers, ProtocolHelpers } from "../src/core";
3737import { ThingDescription } from "wot-typescript-definitions" ;
3838import chaiAsPromised from "chai-as-promised" ;
3939import { fail } from "assert" ;
40+ import { ComboSecurityScheme } from "wot-thing-description-types" ;
4041
4142const { debug } = createLoggers ( "core" , "ClientTest" ) ;
4243
@@ -806,7 +807,7 @@ class WoTClientTest {
806807 expect ( WoTClientTest . servient . hasClientFor ( tcf2 . scheme ) ) . to . be . not . true ;
807808 }
808809
809- @test "ensure combo security" ( ) {
810+ @test "ensure combo security - allOf " ( ) {
810811 const ct = new ConsumedThing ( WoTClientTest . servient ) ;
811812 ct . securityDefinitions = {
812813 basic_sc : {
@@ -829,12 +830,69 @@ class WoTClientTest {
829830 href : "https://example.com/" ,
830831 } ;
831832 ct . ensureClientSecurity ( pc , form ) ;
832- expect ( pc . securitySchemes . length ) . equals ( 2 ) ;
833- expect ( pc . securitySchemes [ 0 ] . scheme ) . equals ( "opcua-channel-security" ) ;
834- expect ( pc . securitySchemes [ 1 ] . scheme ) . equals ( "opcua-authentication" ) ;
833+ expect ( pc . securitySchemes . length ) . equals ( 1 ) ;
834+ expect ( pc . securitySchemes [ 0 ] . scheme ) . equals ( "combo" ) ;
835+
836+ const comboScheme = pc . securitySchemes [ 0 ] as AllOfSecurityScheme ;
837+ expect ( comboScheme . allOf ) . instanceOf ( Array ) ;
838+ expect ( comboScheme . allOf . length ) . equal ( 2 ) ;
839+ expect ( comboScheme . allOf [ 0 ] . scheme ) . equals ( "opcua-channel-security" ) ;
840+ expect ( comboScheme . allOf [ 1 ] . scheme ) . equals ( "opcua-authentication" ) ;
841+ }
842+
843+ @test "ensure combo security - oneOf" ( ) {
844+ const ct = new ConsumedThing ( WoTClientTest . servient ) ;
845+ ct . securityDefinitions = {
846+ basic_sc : {
847+ scheme : "basic" ,
848+ } ,
849+ opcua_secure_channel_encrypt_sc : {
850+ scheme : "opcua-channel-security" ,
851+ mode : "encrypt" ,
852+ } ,
853+ opcua_secure_channel_sign_sc : {
854+ scheme : "opcua-channel-security" ,
855+ mode : "sign" ,
856+ } ,
857+ opcua_authetication_sc : {
858+ scheme : "opcua-authentication" ,
859+ } ,
860+ comob_opcua_secure_channel : {
861+ scheme : "combo" ,
862+ oneOf : [ "opcua_secure_channel_encrypt_sc" , "opcua_secure_channel_sign_sc" ] ,
863+ } ,
864+ combo_sc : {
865+ scheme : "combo" ,
866+ allOf : [ "comob_opcua_secure_channel" , "opcua_authetication_sc" ] ,
867+ } ,
868+ } ;
869+ ct . security = [ "combo_sc" ] ;
870+ const pc = new TestProtocolClient ( ) ;
871+ const form : Form = {
872+ href : "https://example.com/" ,
873+ } ;
874+ ct . ensureClientSecurity ( pc , form ) ;
875+ expect ( pc . securitySchemes . length ) . equals ( 1 ) ;
876+ expect ( pc . securitySchemes [ 0 ] . scheme ) . equals ( "combo" ) ;
877+
878+ const comboScheme = pc . securitySchemes [ 0 ] as AllOfSecurityScheme ;
879+
880+ expect ( comboScheme . allOf ) . instanceOf ( Array ) ;
881+ expect ( comboScheme . allOf . length ) . equal ( 2 ) ;
882+ expect ( comboScheme . allOf [ 0 ] . scheme ) . equals ( "combo" ) ;
883+ expect ( comboScheme . allOf [ 1 ] . scheme ) . equals ( "opcua-authentication" ) ;
884+
885+ //
886+ const comob_opcua_secure_channel = comboScheme . allOf [ 0 ] as OneOfSecurityScheme ;
887+ expect ( comob_opcua_secure_channel . scheme ) . equal ( "combo" ) ;
888+ expect ( comob_opcua_secure_channel . oneOf ) . instanceOf ( Array ) ;
889+
890+ expect ( comob_opcua_secure_channel . oneOf . length ) . equal ( 2 ) ;
891+ expect ( comob_opcua_secure_channel . oneOf [ 0 ] . scheme ) . equal ( "opcua-channel-security" ) ;
892+ expect ( comob_opcua_secure_channel . oneOf [ 0 ] . scheme ) . equal ( "opcua-channel-security" ) ;
835893 }
836894
837- @test "ensure combo security in form" ( ) {
895+ @test "ensure combo security in form - allOf " ( ) {
838896 const ct = new ConsumedThing ( WoTClientTest . servient ) ;
839897 ct . securityDefinitions = {
840898 basic_sc : {
@@ -858,9 +916,11 @@ class WoTClientTest {
858916 security : [ "combo_sc" ] ,
859917 } ;
860918 ct . ensureClientSecurity ( pc , form ) ;
861- expect ( pc . securitySchemes . length ) . equals ( 2 ) ;
862- expect ( pc . securitySchemes [ 0 ] . scheme ) . equals ( "opcua-channel-security" ) ;
863- expect ( pc . securitySchemes [ 1 ] . scheme ) . equals ( "opcua-authentication" ) ;
919+ expect ( pc . securitySchemes . length ) . equals ( 1 ) ;
920+ const comboScheme = pc . securitySchemes [ 0 ] as AllOfSecurityScheme ;
921+
922+ expect ( comboScheme . allOf [ 0 ] . scheme ) . equals ( "opcua-channel-security" ) ;
923+ expect ( comboScheme . allOf [ 1 ] . scheme ) . equals ( "opcua-authentication" ) ;
864924 }
865925
866926 @test "ensure no infinite loop with recursive combo security" ( ) {
@@ -879,6 +939,6 @@ class WoTClientTest {
879939 security : [ "combo_sc" ] ,
880940 } ;
881941 ct . ensureClientSecurity ( pc , form ) ;
882- expect ( pc . securitySchemes . length ) . equals ( 0 ) ;
942+ expect ( pc . securitySchemes . length ) . equals ( 1 ) ;
883943 }
884944}
0 commit comments