Skip to content

Commit 6b333d6

Browse files
authored
fix(binding-http): fill security scheme when baseURI defined (#1244)
* fix(binding-http): fill security scheme when baseURI defined * refactor(binding-http/http-server): move warning near fillSecurityScheme * docs(binding-http/http-server): remove outdated code comment
1 parent ad76c37 commit 6b333d6

2 files changed

Lines changed: 21 additions & 7 deletions

File tree

packages/binding-http/src/http-server.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff 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
}

packages/binding-http/test/http-server-test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff 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({

0 commit comments

Comments
 (0)