Skip to content
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
6 changes: 5 additions & 1 deletion packages/core/src/thing-description.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,13 @@ export interface NullSchema extends BaseSchema {
type: "null";
}

// TODO AutoSecurityScheme
/**
* @deprecated This type is deprecated and will be removed in a future release.
*/
export type SecurityType =
| NoSecurityScheme
| BasicSecurityScheme
| AutoSecurityScheme
| DigestSecurityScheme
| BearerSecurityScheme
| APIKeySecurityScheme
Expand All @@ -165,6 +165,10 @@ export interface BasicSecurityScheme extends SecurityScheme, TDT.BasicSecuritySc
scheme: "basic";
}

export interface AutoSecurityScheme extends SecurityScheme, TDT.AutoSecurityScheme {
scheme: "auto";
}

export interface DigestSecurityScheme extends SecurityScheme, TDT.DigestSecurityScheme {
scheme: "digest";
}
Expand Down
31 changes: 30 additions & 1 deletion packages/core/test/ClientTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@ import { Subscription } from "rxjs/Subscription";

import Servient from "../src/servient";
import ConsumedThing from "../src/consumed-thing";
import { AllOfSecurityScheme, Form, OneOfSecurityScheme, SecurityScheme } from "../src/thing-description";
import {
AllOfSecurityScheme,
AutoSecurityScheme,
Form,
OneOfSecurityScheme,
SecurityScheme,
} from "../src/thing-description";
import { ProtocolClient, ProtocolClientFactory } from "../src/protocol-interfaces";
import { Content } from "../src/content";
import { ContentSerdes } from "../src/content-serdes";
Expand Down Expand Up @@ -1045,4 +1051,27 @@ class WoTClientTest {
ct.ensureClientSecurity(pc, form);
}, /Combo SecurityScheme 'combo_without_oneOf_and_without_allof' is invalid/);
}

@test "with auto security scheme selection"() {
const ct = new ConsumedThing(WoTClientTest.servient);
ct.securityDefinitions = {
auto_sc: {
scheme: "auto",
},
};
ct.security = ["auto_sc"];
const pc = new TestProtocolClient();
const form: Form = {
href: "https://example.com/",
};
ct.ensureClientSecurity(pc, form);
expect(pc.securitySchemes.length).equals(1);
expect(pc.securitySchemes[0].scheme).equal("auto");

if (pc.securitySchemes[0].scheme === "auto") {
// casting to AutoSecurityScheme should not bother the IDE.
const autoScheme = pc.securitySchemes[0] as AutoSecurityScheme;
expect(autoScheme.scheme).to.equal("auto");
}
}
}
Loading