@@ -27,7 +27,14 @@ 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+ OAuth2SecurityScheme ,
35+ OneOfSecurityScheme ,
36+ SecurityScheme ,
37+ } from "../src/thing-description" ;
3138import { ProtocolClient , ProtocolClientFactory } from "../src/protocol-interfaces" ;
3239import { Content } from "../src/content" ;
3340import { ContentSerdes } from "../src/content-serdes" ;
@@ -1045,4 +1052,27 @@ class WoTClientTest {
10451052 ct . ensureClientSecurity ( pc , form ) ;
10461053 } , / 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 / ) ;
10471054 }
1055+
1056+ @test "with auto security scheme selection" ( ) {
1057+ const ct = new ConsumedThing ( WoTClientTest . servient ) ;
1058+ ct . securityDefinitions = {
1059+ auto_sc : {
1060+ scheme : "auto" ,
1061+ } ,
1062+ } ;
1063+ ct . security = [ "auto_sc" ] ;
1064+ const pc = new TestProtocolClient ( ) ;
1065+ const form : Form = {
1066+ href : "https://example.com/" ,
1067+ } ;
1068+ ct . ensureClientSecurity ( pc , form ) ;
1069+ expect ( pc . securitySchemes . length ) . equals ( 1 ) ;
1070+ expect ( pc . securitySchemes [ 0 ] . scheme ) . equal ( "auto" ) ;
1071+
1072+ if ( pc . securitySchemes [ 0 ] . scheme === "auto" ) {
1073+ // casting to AutoSecurityScheme should not bother the IDE.
1074+ const autoScheme = pc . securitySchemes [ 0 ] as AutoSecurityScheme ;
1075+ expect ( autoScheme . scheme ) . to . equal ( "auto" ) ;
1076+ }
1077+ }
10481078}
0 commit comments