@@ -27,7 +27,13 @@ import { Subscription } from "rxjs/Subscription";
2727
2828import Servient from "../src/servient" ;
2929import ConsumedThing from "../src/consumed-thing" ;
30- import { AllOfSecurityScheme , Form , OneOfSecurityScheme , SecurityScheme } from "../src/thing-description" ;
30+ import {
31+ AllOfSecurityScheme ,
32+ AutoSecurityScheme ,
33+ Form ,
34+ OneOfSecurityScheme ,
35+ SecurityScheme ,
36+ } from "../src/thing-description" ;
3137import { ProtocolClient , ProtocolClientFactory } from "../src/protocol-interfaces" ;
3238import { Content } from "../src/content" ;
3339import { ContentSerdes } from "../src/content-serdes" ;
@@ -1045,4 +1051,27 @@ class WoTClientTest {
10451051 ct . ensureClientSecurity ( pc , form ) ;
10461052 } , / C o m b o S e c u r i t y S c h e m e ' c o m b o _ w i t h o u t _ o n e O f _ a n d _ w i t h o u t _ a l l o f ' i s i n v a l i d / ) ;
10471053 }
1054+
1055+ @test "with auto security scheme selection" ( ) {
1056+ const ct = new ConsumedThing ( WoTClientTest . servient ) ;
1057+ ct . securityDefinitions = {
1058+ auto_sc : {
1059+ scheme : "auto" ,
1060+ } ,
1061+ } ;
1062+ ct . security = [ "auto_sc" ] ;
1063+ const pc = new TestProtocolClient ( ) ;
1064+ const form : Form = {
1065+ href : "https://example.com/" ,
1066+ } ;
1067+ ct . ensureClientSecurity ( pc , form ) ;
1068+ expect ( pc . securitySchemes . length ) . equals ( 1 ) ;
1069+ expect ( pc . securitySchemes [ 0 ] . scheme ) . equal ( "auto" ) ;
1070+
1071+ if ( pc . securitySchemes [ 0 ] . scheme === "auto" ) {
1072+ // casting to AutoSecurityScheme should not bother the IDE.
1073+ const autoScheme = pc . securitySchemes [ 0 ] as AutoSecurityScheme ;
1074+ expect ( autoScheme . scheme ) . to . equal ( "auto" ) ;
1075+ }
1076+ }
10481077}
0 commit comments