|
| 1 | +import { PluginRegistry } from "@hyperledger/cactus-core"; |
| 2 | +import { |
| 3 | + Configuration, |
| 4 | + IPluginFactoryOptions, |
| 5 | + PluginImportType, |
| 6 | +} from "@hyperledger/cactus-core-api"; |
| 7 | +import test, { Test } from "tape-promise/tape"; |
| 8 | +import { PluginFactoryKeychain } from "../../../main/typescript/plugin-factory-keychain"; |
| 9 | +import { |
| 10 | + AwsCredentialType, |
| 11 | + PluginKeychainAwsSm, |
| 12 | +} from "../../../main/typescript/plugin-keychain-aws-sm"; |
| 13 | +import { v4 as uuidv4 } from "uuid"; |
| 14 | +import { PluginKeychainAwsSmRemoteAdapter } from "../../../main/typescript/plugin-keychain-aws-sm-remote-adapter"; |
| 15 | + |
| 16 | +test("get,set,has,delete alters state as expected", async (t: Test) => { |
| 17 | + const iPluginFactoryOptions1: IPluginFactoryOptions = { |
| 18 | + pluginImportType: PluginImportType.Local, |
| 19 | + }; |
| 20 | + |
| 21 | + const iPluginFactoryOptions2: IPluginFactoryOptions = { |
| 22 | + pluginImportType: PluginImportType.Remote, |
| 23 | + }; |
| 24 | + |
| 25 | + const invalid: IPluginFactoryOptions = { |
| 26 | + pluginImportType: (null as unknown) as PluginImportType, |
| 27 | + }; |
| 28 | + |
| 29 | + const pluginRegistry = new PluginRegistry(); |
| 30 | + const iPluginKeychainAwsSmOptions = { |
| 31 | + pluginRegistry, |
| 32 | + instanceId: uuidv4(), |
| 33 | + keychainId: uuidv4(), |
| 34 | + logLevel: "TRACE", |
| 35 | + awsProfile: "true", |
| 36 | + awsRegion: "true", |
| 37 | + awsEndpoint: "true", |
| 38 | + awsAccessKeyId: "true", |
| 39 | + awsSecretAccessKey: "true", |
| 40 | + awsCredentialType: AwsCredentialType.InMemory, |
| 41 | + }; |
| 42 | + |
| 43 | + const pluginFactoryKeychain1 = new PluginFactoryKeychain( |
| 44 | + iPluginFactoryOptions1, |
| 45 | + ); |
| 46 | + |
| 47 | + const pluginFactoryKeychain2 = new PluginFactoryKeychain( |
| 48 | + iPluginFactoryOptions2, |
| 49 | + ); |
| 50 | + |
| 51 | + const pluginFactoryKeychain3 = new PluginFactoryKeychain(invalid); |
| 52 | + |
| 53 | + const pluginKeychainAwsSm = await pluginFactoryKeychain1.create( |
| 54 | + iPluginKeychainAwsSmOptions, |
| 55 | + ); |
| 56 | + |
| 57 | + const pluginKeychainAwsSmRemoteAdapter = await pluginFactoryKeychain2.create({ |
| 58 | + ...iPluginKeychainAwsSmOptions, |
| 59 | + remoteConfig: new Configuration({ basePath: "true" }), |
| 60 | + }); |
| 61 | + |
| 62 | + t.true( |
| 63 | + pluginKeychainAwsSm instanceof PluginKeychainAwsSm, |
| 64 | + "pluginImportType.Local results in pluginKeychainAwsSm", |
| 65 | + ); |
| 66 | + |
| 67 | + t.true( |
| 68 | + pluginKeychainAwsSmRemoteAdapter instanceof |
| 69 | + PluginKeychainAwsSmRemoteAdapter, |
| 70 | + "pluginImportType.Remote results in pluginKeychainAwsSm", |
| 71 | + ); |
| 72 | + |
| 73 | + await t.rejects( |
| 74 | + pluginFactoryKeychain3.create({ |
| 75 | + invalid, |
| 76 | + }), |
| 77 | + ); |
| 78 | + |
| 79 | + t.end(); |
| 80 | +}); |
0 commit comments