Skip to content

Commit

Permalink
Adding http post method config (#217)
Browse files Browse the repository at this point in the history
* adding the new fields

* adding tests

* address review comments about test case locations

* more review comments

* adding JSDocs
  • Loading branch information
uhunnyslack authored Sep 21, 2023
1 parent 2c47acc commit c8b372f
Show file tree
Hide file tree
Showing 3 changed files with 402 additions and 263 deletions.
263 changes: 1 addition & 262 deletions src/manifest/manifest_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
DefineDatastore,
DefineEvent,
DefineFunction,
DefineOAuth2Provider,
DefineType,
DefineWorkflow,
Schema,
Expand All @@ -26,11 +25,7 @@ import {
} from "../dev_deps.ts";
import { DefineConnector } from "../functions/mod.ts";
import { InternalSlackTypes } from "../schema/slack/types/custom/mod.ts";
import {
DuplicateCallbackIdError,
DuplicateNameError,
DuplicateProviderKeyError,
} from "./errors.ts";
import { DuplicateCallbackIdError, DuplicateNameError } from "./errors.ts";

Deno.test("SlackManifestType correctly resolves to a Hosted App when runOnSlack = true", () => {
const definition: SlackManifestType = {
Expand Down Expand Up @@ -944,140 +939,6 @@ Deno.test("SlackManifest.export() allows overriding app home features", () => {
);
});

Deno.test("SlackManifest() oauth2 providers get set properly", () => {
const providerKey = "test_provider";

const Provider = DefineOAuth2Provider({
provider_key: providerKey,
provider_type: Schema.providers.oauth2.CUSTOM,
options: {
"client_id": "123.456",
"scope": ["scope_a", "scope_b"],
},
});

const definition: SlackManifestType = {
name: "Name",
description: "Description",
icon: "icon.png",
botScopes: [],
externalAuthProviders: [Provider],
};

const Manifest = new SlackManifest(definition);
const exportedManifest = Manifest.export();
assertEquals(definition.externalAuthProviders, [Provider]);
assertEquals(exportedManifest.external_auth_providers, {
"oauth2": { "test_provider": Provider.export() },
});
});

Deno.test("SlackManifest() oauth2 providers get set properly with use_pkce", () => {
const providerKey1 = "test_provider_with_with_pkce_true";
const providerKey2 = "test_provider_with_with_pkce_false";
const providerKey3 = "test_provider_with_with_pkce_unset";

const Provider1 = DefineOAuth2Provider({
provider_key: providerKey1,
provider_type: Schema.providers.oauth2.CUSTOM,
options: {
"client_id": "123.456",
"scope": ["scope_a", "scope_b"],
"use_pkce": true,
},
});

const Provider2 = DefineOAuth2Provider({
provider_key: providerKey2,
provider_type: Schema.providers.oauth2.CUSTOM,
options: {
"client_id": "123.456",
"scope": ["scope_a", "scope_b"],
"use_pkce": false,
},
});

const Provider3 = DefineOAuth2Provider({
provider_key: providerKey3,
provider_type: Schema.providers.oauth2.CUSTOM,
options: {
"client_id": "123.456",
"scope": ["scope_a", "scope_b"],
},
});

const definition: SlackManifestType = {
name: "Name",
description: "Description",
icon: "icon.png",
botScopes: [],
externalAuthProviders: [Provider1, Provider2, Provider3],
};
assertEquals(definition.externalAuthProviders, [
Provider1,
Provider2,
Provider3,
]);
const Manifest = new SlackManifest(definition);
const exportedManifest = Manifest.export();

assertEquals(exportedManifest.external_auth_providers, {
"oauth2": {
"test_provider_with_with_pkce_true": Provider1.export(),
"test_provider_with_with_pkce_false": Provider2.export(),
"test_provider_with_with_pkce_unset": Provider3.export(),
},
});
assertStrictEquals(
exportedManifest.external_auth_providers?.oauth2
?.test_provider_with_with_pkce_true?.options?.use_pkce,
true,
);
assertStrictEquals(
exportedManifest.external_auth_providers?.oauth2
?.test_provider_with_with_pkce_false?.options?.use_pkce,
false,
);
assertStrictEquals(
exportedManifest.external_auth_providers?.oauth2
?.test_provider_with_with_pkce_unset?.options?.use_pkce,
undefined,
);
});

Deno.test("SlackManifest() oauth2 providers are undefined when not configured", () => {
const definition: SlackManifestType = {
name: "Name",
description: "Description",
icon: "icon.png",
botScopes: [],
};

const Manifest = new SlackManifest(definition);

const exportedManifest = Manifest.export();

assertEquals(definition.externalAuthProviders, undefined);
assertEquals(exportedManifest.external_auth_providers, undefined);
});

Deno.test("SlackManifest() oauth2 providers are undefined when set to the empty array", () => {
const definition: SlackManifestType = {
name: "Name",
description: "Description",
icon: "icon.png",
botScopes: [],
externalAuthProviders: [],
};

const Manifest = new SlackManifest(definition);

const exportedManifest = Manifest.export();

assertEquals(definition.externalAuthProviders, []);
assertEquals(exportedManifest.external_auth_providers, undefined);
});

Deno.test("Manifest supports multiple workflows with parameters", () => {
const workflow1 = DefineWorkflow({
callback_id: "test",
Expand Down Expand Up @@ -1311,125 +1172,3 @@ Deno.test("Manifest throws error when CustomEvents with duplicate name are added
assertStringIncludes(error.message, "CustomEvent");
}
});

Deno.test("Manifest throws error when Providers with duplicate provider_keys are added", () => {
const provider1 = DefineOAuth2Provider({
provider_key: "test",
provider_type: Schema.providers.oauth2.CUSTOM,
options: {
"client_id": "123.456",
"scope": ["scope_a"],
},
});

const provider2 = DefineOAuth2Provider({
provider_key: "test",
provider_type: Schema.providers.oauth2.CUSTOM,
options: {
"client_id": "123.456",
"scope": ["scope_a"],
},
});

try {
Manifest({
name: "Name",
description: "Description",
botScopes: [],
icon: "icon.png",
externalAuthProviders: [provider1, provider2],
});
fail("Manifest() should have thrown an error");
} catch (error) {
if (error instanceof AssertionError) throw error;
assertInstanceOf(error, DuplicateProviderKeyError);
assertStringIncludes(error.message, "OAuth2Provider");
}
});

Deno.test("SlackManifest() oauth2 providers get set properly with token_url_config", () => {
// test with token_url_config unset
const providerKey1 = "test_provider_with_token_url_config_unset";
const Provider1 = DefineOAuth2Provider({
provider_key: providerKey1,
provider_type: Schema.providers.oauth2.CUSTOM,
options: {
"client_id": "123.456",
"scope": ["scope_a", "scope_b"],
"token_url_config": {},
},
});
// test with use_basic_authentication_scheme false
const providerKey2 =
"test_provider_with_use_basic_authentication_scheme_false";
const Provider2 = DefineOAuth2Provider({
provider_key: providerKey2,
provider_type: Schema.providers.oauth2.CUSTOM,
options: {
"client_id": "123.456",
"scope": ["scope_a", "scope_b"],
"token_url_config": {
"use_basic_authentication_scheme": false,
},
},
});
// test with use_basic_authentication_scheme true
const providerKey3 =
"test_provider_with_use_basic_authentication_scheme_true";
const Provider3 = DefineOAuth2Provider({
provider_key: providerKey3,
provider_type: Schema.providers.oauth2.CUSTOM,
options: {
"client_id": "123.456",
"scope": ["scope_a", "scope_b"],
"token_url_config": {
"use_basic_authentication_scheme": true,
},
},
});
const definition: SlackManifestType = {
name: "Name",
description: "Description",
icon: "icon.png",
botScopes: [],
externalAuthProviders: [Provider1, Provider2, Provider3],
};
assertEquals(definition.externalAuthProviders, [
Provider1,
Provider2,
Provider3,
]);
const Manifest = new SlackManifest(definition);
const exportedManifest = Manifest.export();

assertEquals(exportedManifest.external_auth_providers, {
"oauth2": {
"test_provider_with_token_url_config_unset": Provider1.export(),
"test_provider_with_use_basic_authentication_scheme_false": Provider2
.export(),
"test_provider_with_use_basic_authentication_scheme_true": Provider3
.export(),
},
});
// test with use_basic_authentication_scheme unset
assertStrictEquals(
exportedManifest.external_auth_providers?.oauth2
?.test_provider_with_token_url_config_unset?.options
?.token_url_config?.use_basic_authentication_scheme,
undefined,
);
// test with use_basic_authentication_scheme false
assertStrictEquals(
exportedManifest.external_auth_providers?.oauth2
?.test_provider_with_use_basic_authentication_scheme_false?.options
?.token_url_config?.use_basic_authentication_scheme,
false,
);
// test with use_basic_authentication_scheme true
assertStrictEquals(
exportedManifest.external_auth_providers?.oauth2
?.test_provider_with_use_basic_authentication_scheme_true?.options
?.token_url_config?.use_basic_authentication_scheme,
true,
);
});
Loading

0 comments on commit c8b372f

Please sign in to comment.