Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(binding-http): fill security scheme when baseURI defined #1244

Merged
merged 3 commits into from
Feb 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions packages/binding-http/src/http-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,12 @@ export default class HttpServer implements ProtocolServer {
debug(`HttpServer on port ${this.getPort()} exposes '${thing.title}' as unique '/${urlPath}'`);
this.things.set(urlPath, thing);

if (this.scheme === "http" && Object.keys(thing.securityDefinitions).length !== 0) {
warn(`HTTP Server will attempt to use your security schemes even if you are not using HTTPS.`);
}

this.fillSecurityScheme(thing);

if (this.baseUri !== undefined) {
const base: string = this.baseUri.concat("/", encodeURIComponent(urlPath));
info("HttpServer TD hrefs using baseUri " + this.baseUri);
Expand All @@ -288,14 +294,7 @@ export default class HttpServer implements ProtocolServer {
this.scheme + "://" + address + ":" + this.getPort() + "/" + encodeURIComponent(urlPath);

this.addEndpoint(thing, tdTemplate, base);
// media types
} // addresses

if (this.scheme === "http" && Object.keys(thing.securityDefinitions).length !== 0) {
warn(`HTTP Server will attempt to use your security schemes even if you are not using HTTPS.`);
}

this.fillSecurityScheme(thing);
}
}
}
Expand Down
15 changes: 15 additions & 0 deletions packages/binding-http/test/http-server-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,21 @@ class HttpServerTest {
expect(testThing.securityDefinitions.bearer).not.eql(undefined);
}

@test async "should fill default security scheme even with baseURI defined"() {
const httpServer = new HttpServer({
port: port2,
baseUri: "https://example.com",
});
await httpServer.start(new Servient());
const testThing = new ExposedThing(new Servient());
testThing.title = "Test";
httpServer.expose(testThing);
await httpServer.stop();

expect(testThing.securityDefinitions.nosec).to.not.eql(undefined);
expect(testThing.securityDefinitions.nosec.scheme).to.be.eql("nosec");
}

@test async "should not accept an unsupported scheme"() {
debug("START SHOULD");
const httpServer = new HttpServer({
Expand Down
Loading