Skip to content

Commit

Permalink
refactor: add plugin factory keychain test file
Browse files Browse the repository at this point in the history
Fixes hyperledger-cacti#967

Signed-off-by: Youngone Lee <youngone.lee@accenture.com>
  • Loading branch information
Leeyoungone committed Aug 5, 2021
1 parent 71e1588 commit 45d721e
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { PluginRegistry } from "@hyperledger/cactus-core";
import {
Configuration,
IPluginFactoryOptions,
PluginImportType,
} from "@hyperledger/cactus-core-api";
import test, { Test } from "tape-promise/tape";
import { PluginFactoryKeychain } from "../../../main/typescript/plugin-factory-keychain";
import {
AwsCredentialType,
PluginKeychainAwsSm,
} from "../../../main/typescript/plugin-keychain-aws-sm";
import { v4 as uuidv4 } from "uuid";
import { PluginKeychainAwsSmRemoteAdapter } from "../../../main/typescript/plugin-keychain-aws-sm-remote-adapter";

test("get,set,has,delete alters state as expected", async (t: Test) => {
const iPluginFactoryOptions1: IPluginFactoryOptions = {
pluginImportType: PluginImportType.Local,
};

const iPluginFactoryOptions2: IPluginFactoryOptions = {
pluginImportType: PluginImportType.Remote,
};

const invalid: IPluginFactoryOptions = {
pluginImportType: (null as unknown) as PluginImportType,
};

const pluginRegistry = new PluginRegistry();
const iPluginKeychainAwsSmOptions = {
pluginRegistry,
instanceId: uuidv4(),
keychainId: uuidv4(),
logLevel: "TRACE",
awsProfile: "true",
awsRegion: "true",
awsEndpoint: "true",
awsAccessKeyId: "true",
awsSecretAccessKey: "true",
awsCredentialType: AwsCredentialType.InMemory,
};

const pluginFactoryKeychain1 = new PluginFactoryKeychain(
iPluginFactoryOptions1,
);

const pluginFactoryKeychain2 = new PluginFactoryKeychain(
iPluginFactoryOptions2,
);

const pluginFactoryKeychain3 = new PluginFactoryKeychain(invalid);

const pluginKeychainAwsSm = await pluginFactoryKeychain1.create(
iPluginKeychainAwsSmOptions,
);

const pluginKeychainAwsSmRemoteAdapter = await pluginFactoryKeychain2.create({
...iPluginKeychainAwsSmOptions,
remoteConfig: new Configuration({ basePath: "true" }),
});

t.true(
pluginKeychainAwsSm instanceof PluginKeychainAwsSm,
"pluginImportType.Local results in pluginKeychainAwsSm",
);

t.true(
pluginKeychainAwsSmRemoteAdapter instanceof
PluginKeychainAwsSmRemoteAdapter,
"pluginImportType.Remote results in pluginKeychainAwsSm",
);

await t.rejects(
pluginFactoryKeychain3.create({
invalid,
}),
);

t.end();
});
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { BASE_PATH, COLLECTION_FORMATS, RequestArgs, BaseAPI, RequiredError } fr
*/
export interface GetKeychainEntryRequest {
/**
* The key for the entry to get from the keychain.
* The key for the entry to delete from the keychain.
* @type {string}
* @memberof GetKeychainEntryRequest
*/
Expand Down Expand Up @@ -60,7 +60,7 @@ export interface GetKeychainEntryResponse {
*/
export interface SetKeychainEntryRequest {
/**
* The key for the entry to set on the keychain.
* The key for the entry to check on the keychain.
* @type {string}
* @memberof SetKeychainEntryRequest
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { BASE_PATH, COLLECTION_FORMATS, RequestArgs, BaseAPI, RequiredError } fr
*/
export interface GetKeychainEntryRequest {
/**
* The key for the entry to get from the keychain.
* The key for the entry to delete from the keychain.
* @type {string}
* @memberof GetKeychainEntryRequest
*/
Expand Down Expand Up @@ -60,7 +60,7 @@ export interface GetKeychainEntryResponse {
*/
export interface SetKeychainEntryRequest {
/**
* The key for the entry to set on the keychain.
* The key for the entry to check on the keychain.
* @type {string}
* @memberof SetKeychainEntryRequest
*/
Expand Down

0 comments on commit 45d721e

Please sign in to comment.