File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -277,6 +277,12 @@ export default class HttpServer implements ProtocolServer {
277277 debug ( `HttpServer on port ${ this . getPort ( ) } exposes '${ thing . title } ' as unique '/${ urlPath } '` ) ;
278278 this . things . set ( urlPath , thing ) ;
279279
280+ if ( this . scheme === "http" && Object . keys ( thing . securityDefinitions ) . length !== 0 ) {
281+ warn ( `HTTP Server will attempt to use your security schemes even if you are not using HTTPS.` ) ;
282+ }
283+
284+ this . fillSecurityScheme ( thing ) ;
285+
280286 if ( this . baseUri !== undefined ) {
281287 const base : string = this . baseUri . concat ( "/" , encodeURIComponent ( urlPath ) ) ;
282288 info ( "HttpServer TD hrefs using baseUri " + this . baseUri ) ;
@@ -288,14 +294,7 @@ export default class HttpServer implements ProtocolServer {
288294 this . scheme + "://" + address + ":" + this . getPort ( ) + "/" + encodeURIComponent ( urlPath ) ;
289295
290296 this . addEndpoint ( thing , tdTemplate , base ) ;
291- // media types
292- } // addresses
293-
294- if ( this . scheme === "http" && Object . keys ( thing . securityDefinitions ) . length !== 0 ) {
295- warn ( `HTTP Server will attempt to use your security schemes even if you are not using HTTPS.` ) ;
296297 }
297-
298- this . fillSecurityScheme ( thing ) ;
299298 }
300299 }
301300 }
Original file line number Diff line number Diff line change @@ -438,6 +438,21 @@ class HttpServerTest {
438438 expect ( testThing . securityDefinitions . bearer ) . not . eql ( undefined ) ;
439439 }
440440
441+ @test async "should fill default security scheme even with baseURI defined" ( ) {
442+ const httpServer = new HttpServer ( {
443+ port : port2 ,
444+ baseUri : "https://example.com" ,
445+ } ) ;
446+ await httpServer . start ( new Servient ( ) ) ;
447+ const testThing = new ExposedThing ( new Servient ( ) ) ;
448+ testThing . title = "Test" ;
449+ httpServer . expose ( testThing ) ;
450+ await httpServer . stop ( ) ;
451+
452+ expect ( testThing . securityDefinitions . nosec ) . to . not . eql ( undefined ) ;
453+ expect ( testThing . securityDefinitions . nosec . scheme ) . to . be . eql ( "nosec" ) ;
454+ }
455+
441456 @test async "should not accept an unsupported scheme" ( ) {
442457 debug ( "START SHOULD" ) ;
443458 const httpServer = new HttpServer ( {
You can’t perform that action at this time.
0 commit comments