diff --git a/packages/cactus-core-api/src/main/json/openapi.json b/packages/cactus-core-api/src/main/json/openapi.json index a2d06a46d2..4df9109377 100644 --- a/packages/cactus-core-api/src/main/json/openapi.json +++ b/packages/cactus-core-api/src/main/json/openapi.json @@ -444,7 +444,7 @@ "properties": { "key": { "type": "string", - "description": "The key for the entry to get from the keychain.", + "description": "The key for the entry to delete from the keychain.", "minLength": 1, "maxLength": 1024, "nullable": false @@ -512,7 +512,22 @@ } } }, - "DeleteKeychainEntryResponse": { + "HasKeychainEntryRequest": { + "type": "object", + "required": [ + "key" + ], + "properties": { + "key": { + "type": "string", + "description": "The key for the entry to set on the keychain.", + "minLength": 1, + "maxLength": 1024, + "nullable": false + } + } + }, + "HasKeychainEntryResponse": { "type": "object", "required": [ "key" @@ -526,6 +541,21 @@ "nullable": false } } + }, + "DeleteKeychainEntryResponse": { + "type": "object", + "required": [ + "key" + ], + "properties": { + "key": { + "type": "string", + "description": "The key that was used to delete the value on the keychain.", + "minLength": 1, + "maxLength": 1024, + "nullable": false + } + } } }, "requestBodies": { @@ -561,6 +591,17 @@ } } } + }, + "keychain_has_entry_request_body": { + "description": "Request body for a keychain entry via its key", + "required": true, + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HasKeychainEntryRequest" + } + } + } } }, "responses": { @@ -623,6 +664,25 @@ }, "keychain_delete_entry_500": { "description": "Unexpected error." + }, + "keychain_has_entry_200": { + "description": "OK", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/HasKeychainEntryResponse" + } + } + } + }, + "keychain_has_entry_400": { + "description": "Bad request. Key must be a string and longer than 0, shorter than 1024 characters." + }, + "keychain_has_entry_401": { + "description": "Authorization information is missing or invalid." + }, + "keychain_has_entry_500": { + "description": "Unexpected error." } } }, diff --git a/packages/cactus-core-api/src/main/typescript/generated/openapi/typescript-axios/api.ts b/packages/cactus-core-api/src/main/typescript/generated/openapi/typescript-axios/api.ts index c460b618fc..cffcdde4af 100644 --- a/packages/cactus-core-api/src/main/typescript/generated/openapi/typescript-axios/api.ts +++ b/packages/cactus-core-api/src/main/typescript/generated/openapi/typescript-axios/api.ts @@ -316,6 +316,32 @@ export interface GetKeychainEntryResponse { */ value: string; } +/** + * + * @export + * @interface HasKeychainEntryRequest + */ +export interface HasKeychainEntryRequest { + /** + * The key for the entry to set on the keychain. + * @type {string} + * @memberof HasKeychainEntryRequest + */ + key: string; +} +/** + * + * @export + * @interface HasKeychainEntryResponse + */ +export interface HasKeychainEntryResponse { + /** + * The key that was used to set the value on the keychain. + * @type {string} + * @memberof HasKeychainEntryResponse + */ + key: string; +} /** * * @export diff --git a/packages/cactus-plugin-keychain-aws-sm/src/main/json/openapi.json b/packages/cactus-plugin-keychain-aws-sm/src/main/json/openapi.json index 925edb49c1..678e833d6b 100644 --- a/packages/cactus-plugin-keychain-aws-sm/src/main/json/openapi.json +++ b/packages/cactus-plugin-keychain-aws-sm/src/main/json/openapi.json @@ -94,7 +94,7 @@ } }, "operationId": "deleteKeychainEntry", - "summary": "Deletes a value under a key on the keychain backend.", + "summary": "Deletes an entry under a key on the keychain backend.", "parameters": [], "requestBody": { "$ref": "../../../../cactus-core-api/src/main/json/openapi.json#/components/requestBodies/keychain_delete_entry_request_body" @@ -114,6 +114,36 @@ } } } + }, + "/api/v1/plugins/@hyperledger/cactus-plugin-keychain-aws-sm/has-keychain-entry": { + "post": { + "x-hyperledger-cactus": { + "http": { + "path": "/api/v1/plugins/@hyperledger/cactus-plugin-keychain-aws-sm/has-keychain-entry", + "verbLowerCase": "post" + } + }, + "operationId": "hasKeychainEntry", + "summary": "Checks that an entry exists under a key on the keychain backend", + "parameters": [], + "requestBody": { + "$ref": "../../../../cactus-core-api/src/main/json/openapi.json#/components/requestBodies/keychain_has_entry_request_body" + }, + "responses": { + "200": { + "$ref": "../../../../cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_has_entry_200" + }, + "400": { + "$ref": "../../../../cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_has_entry_400" + }, + "401": { + "$ref": "../../../../cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_has_entry_401" + }, + "500": { + "$ref": "../../../../cactus-core-api/src/main/json/openapi.json#/components/responses/keychain_has_entry_500" + } + } + } } } -} \ No newline at end of file +} diff --git a/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/generated/openapi/typescript-axios/api.ts b/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/generated/openapi/typescript-axios/api.ts index b74aaddf72..08ee075de7 100644 --- a/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/generated/openapi/typescript-axios/api.ts +++ b/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/generated/openapi/typescript-axios/api.ts @@ -79,6 +79,32 @@ export interface GetKeychainEntryResponse { */ value: string; } +/** + * + * @export + * @interface HasKeychainEntryRequest + */ +export interface HasKeychainEntryRequest { + /** + * The key for the entry to set on the keychain. + * @type {string} + * @memberof HasKeychainEntryRequest + */ + key: string; +} +/** + * + * @export + * @interface HasKeychainEntryResponse + */ +export interface HasKeychainEntryResponse { + /** + * The key that was used to set the value on the keychain. + * @type {string} + * @memberof HasKeychainEntryResponse + */ + key: string; +} /** * * @export @@ -120,7 +146,7 @@ export const DefaultApiAxiosParamCreator = function (configuration?: Configurati return { /** * - * @summary Deletes a value under a key on the keychain backend. + * @summary Deletes an entry under a key on the keychain backend. * @param {DeleteKeychainEntryRequest} deleteKeychainEntryRequest Request body to delete a keychain entry via its key * @param {*} [options] Override http request option. * @throws {RequiredError} @@ -190,6 +216,42 @@ export const DefaultApiAxiosParamCreator = function (configuration?: Configurati options: localVarRequestOptions, }; }, + /** + * + * @summary Checks that an entry exists under a key on the keychain backend + * @param {HasKeychainEntryRequest} hasKeychainEntryRequest Request body for a keychain entry via its key + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + hasKeychainEntry: async (hasKeychainEntryRequest: HasKeychainEntryRequest, options: any = {}): Promise => { + // verify required parameter 'hasKeychainEntryRequest' is not null or undefined + assertParamExists('hasKeychainEntry', 'hasKeychainEntryRequest', hasKeychainEntryRequest) + const localVarPath = `/api/v1/plugins/@hyperledger/cactus-plugin-keychain-aws-sm/has-keychain-entry`; + // use dummy base URL string because the URL constructor only accepts absolute URLs. + const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL); + let baseOptions; + if (configuration) { + baseOptions = configuration.baseOptions; + } + + const localVarRequestOptions = { method: 'POST', ...baseOptions, ...options}; + const localVarHeaderParameter = {} as any; + const localVarQueryParameter = {} as any; + + + + localVarHeaderParameter['Content-Type'] = 'application/json'; + + setSearchParams(localVarUrlObj, localVarQueryParameter, options.query); + let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {}; + localVarRequestOptions.headers = {...localVarHeaderParameter, ...headersFromBaseOptions, ...options.headers}; + localVarRequestOptions.data = serializeDataIfNeeded(hasKeychainEntryRequest, localVarRequestOptions, configuration) + + return { + url: toPathString(localVarUrlObj), + options: localVarRequestOptions, + }; + }, /** * * @summary Sets a value under a key on the keychain backend. @@ -238,7 +300,7 @@ export const DefaultApiFp = function(configuration?: Configuration) { return { /** * - * @summary Deletes a value under a key on the keychain backend. + * @summary Deletes an entry under a key on the keychain backend. * @param {DeleteKeychainEntryRequest} deleteKeychainEntryRequest Request body to delete a keychain entry via its key * @param {*} [options] Override http request option. * @throws {RequiredError} @@ -258,6 +320,17 @@ export const DefaultApiFp = function(configuration?: Configuration) { const localVarAxiosArgs = await localVarAxiosParamCreator.getKeychainEntry(getKeychainEntryRequest, options); return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); }, + /** + * + * @summary Checks that an entry exists under a key on the keychain backend + * @param {HasKeychainEntryRequest} hasKeychainEntryRequest Request body for a keychain entry via its key + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + async hasKeychainEntry(hasKeychainEntryRequest: HasKeychainEntryRequest, options?: any): Promise<(axios?: AxiosInstance, basePath?: string) => AxiosPromise> { + const localVarAxiosArgs = await localVarAxiosParamCreator.hasKeychainEntry(hasKeychainEntryRequest, options); + return createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration); + }, /** * * @summary Sets a value under a key on the keychain backend. @@ -281,7 +354,7 @@ export const DefaultApiFactory = function (configuration?: Configuration, basePa return { /** * - * @summary Deletes a value under a key on the keychain backend. + * @summary Deletes an entry under a key on the keychain backend. * @param {DeleteKeychainEntryRequest} deleteKeychainEntryRequest Request body to delete a keychain entry via its key * @param {*} [options] Override http request option. * @throws {RequiredError} @@ -299,6 +372,16 @@ export const DefaultApiFactory = function (configuration?: Configuration, basePa getKeychainEntry(getKeychainEntryRequest: GetKeychainEntryRequest, options?: any): AxiosPromise { return localVarFp.getKeychainEntry(getKeychainEntryRequest, options).then((request) => request(axios, basePath)); }, + /** + * + * @summary Checks that an entry exists under a key on the keychain backend + * @param {HasKeychainEntryRequest} hasKeychainEntryRequest Request body for a keychain entry via its key + * @param {*} [options] Override http request option. + * @throws {RequiredError} + */ + hasKeychainEntry(hasKeychainEntryRequest: HasKeychainEntryRequest, options?: any): AxiosPromise { + return localVarFp.hasKeychainEntry(hasKeychainEntryRequest, options).then((request) => request(axios, basePath)); + }, /** * * @summary Sets a value under a key on the keychain backend. @@ -321,7 +404,7 @@ export const DefaultApiFactory = function (configuration?: Configuration, basePa export class DefaultApi extends BaseAPI { /** * - * @summary Deletes a value under a key on the keychain backend. + * @summary Deletes an entry under a key on the keychain backend. * @param {DeleteKeychainEntryRequest} deleteKeychainEntryRequest Request body to delete a keychain entry via its key * @param {*} [options] Override http request option. * @throws {RequiredError} @@ -343,6 +426,18 @@ export class DefaultApi extends BaseAPI { return DefaultApiFp(this.configuration).getKeychainEntry(getKeychainEntryRequest, options).then((request) => request(this.axios, this.basePath)); } + /** + * + * @summary Checks that an entry exists under a key on the keychain backend + * @param {HasKeychainEntryRequest} hasKeychainEntryRequest Request body for a keychain entry via its key + * @param {*} [options] Override http request option. + * @throws {RequiredError} + * @memberof DefaultApi + */ + public hasKeychainEntry(hasKeychainEntryRequest: HasKeychainEntryRequest, options?: any) { + return DefaultApiFp(this.configuration).hasKeychainEntry(hasKeychainEntryRequest, options).then((request) => request(this.axios, this.basePath)); + } + /** * * @summary Sets a value under a key on the keychain backend. diff --git a/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/plugin-keychain-aws-sm.ts b/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/plugin-keychain-aws-sm.ts index 1fb7911bdd..371e1f0966 100644 --- a/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/plugin-keychain-aws-sm.ts +++ b/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/plugin-keychain-aws-sm.ts @@ -28,6 +28,9 @@ import { import { homedir } from "os"; import { PluginRegistry } from "../../../../cactus-core/dist/types/main/typescript/plugin-registry"; import { SetKeychainEntryV1Endpoint } from "./webservices/set-keychain-entry-endpoint-v1"; +import { GetKeychainEntryV1Endpoint } from "./webservices/get-keychain-entry-endpoint-v1"; +import { DeleteKeychainEntryV1Endpoint } from "./webservices/delete-keychain-entry-endpoint-v1"; +import { HasKeychainEntryV1Endpoint } from "./webservices/has-keychain-entry-endpoint-v1"; export enum AwsCredentialType { LocalFile = "LOCAL_FILE", @@ -164,6 +167,18 @@ export class PluginKeychainAwsSm connector: this, logLevel: this.opts.logLevel, }), + new GetKeychainEntryV1Endpoint({ + connector: this, + logLevel: this.opts.logLevel, + }), + new DeleteKeychainEntryV1Endpoint({ + connector: this, + logLevel: this.opts.logLevel, + }), + new HasKeychainEntryV1Endpoint({ + connector: this, + logLevel: this.opts.logLevel, + }), ]; this.endpoints = endpoints; diff --git a/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/webservices/delete-keychain-entry-endpoint-v1.ts b/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/webservices/delete-keychain-entry-endpoint-v1.ts index f8e6436cba..acea3380a5 100644 --- a/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/webservices/delete-keychain-entry-endpoint-v1.ts +++ b/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/webservices/delete-keychain-entry-endpoint-v1.ts @@ -22,13 +22,13 @@ export interface IDeleteKeychainEntryEndpointOptions { connector: PluginKeychainAwsSm; } -export class DeleteKeychainEntryEndpoint implements IWebServiceEndpoint { - public static readonly CLASS_NAME = "DeleteKeychainEntryEndpoint"; +export class DeleteKeychainEntryV1Endpoint implements IWebServiceEndpoint { + public static readonly CLASS_NAME = "DeleteKeychainEntryV1Endpoint"; private readonly log: Logger; public get className(): string { - return DeleteKeychainEntryEndpoint.CLASS_NAME; + return DeleteKeychainEntryV1Endpoint.CLASS_NAME; } constructor(public readonly options: IDeleteKeychainEntryEndpointOptions) { diff --git a/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/webservices/get-keychain-entry-endpoint-v1.ts b/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/webservices/get-keychain-entry-endpoint-v1.ts index 691fa36f29..2087ecbb39 100644 --- a/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/webservices/get-keychain-entry-endpoint-v1.ts +++ b/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/webservices/get-keychain-entry-endpoint-v1.ts @@ -22,13 +22,13 @@ export interface IGetKeychainEntryEndpointOptions { connector: PluginKeychainAwsSm; } -export class GetKeychainEntryEndpoint implements IWebServiceEndpoint { - public static readonly CLASS_NAME = "GetKeychainEntryEndpoint"; +export class GetKeychainEntryV1Endpoint implements IWebServiceEndpoint { + public static readonly CLASS_NAME = "GetKeychainEntryV1Endpoint"; private readonly log: Logger; public get className(): string { - return GetKeychainEntryEndpoint.CLASS_NAME; + return GetKeychainEntryV1Endpoint.CLASS_NAME; } constructor(public readonly options: IGetKeychainEntryEndpointOptions) { diff --git a/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/webservices/has-keychain-entry-endpoint-v1.ts b/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/webservices/has-keychain-entry-endpoint-v1.ts new file mode 100644 index 0000000000..79c7c795f9 --- /dev/null +++ b/packages/cactus-plugin-keychain-aws-sm/src/main/typescript/webservices/has-keychain-entry-endpoint-v1.ts @@ -0,0 +1,100 @@ +import { Express, Request, Response } from "express"; + +import { + Logger, + Checks, + LogLevelDesc, + LoggerProvider, + IAsyncProvider, +} from "@hyperledger/cactus-common"; +import { + IEndpointAuthzOptions, + IExpressRequestHandler, + IWebServiceEndpoint, +} from "@hyperledger/cactus-core-api"; +import { registerWebServiceEndpoint } from "@hyperledger/cactus-core"; + +import OAS from "../../json/openapi.json"; +import { PluginKeychainAwsSm } from "../plugin-keychain-aws-sm"; + +export interface IHasKeychainEntryEndpointOptions { + logLevel?: LogLevelDesc; + connector: PluginKeychainAwsSm; +} + +export class HasKeychainEntryV1Endpoint implements IWebServiceEndpoint { + public static readonly CLASS_NAME = "HasKeychainEntryV1Endpoint"; + + private readonly log: Logger; + + public get className(): string { + return HasKeychainEntryV1Endpoint.CLASS_NAME; + } + + constructor(public readonly options: IHasKeychainEntryEndpointOptions) { + const fnTag = `${this.className}#constructor()`; + Checks.truthy(options, `${fnTag} arg options`); + Checks.truthy(options.connector, `${fnTag} arg options.connector`); + + const level = this.options.logLevel || "INFO"; + const label = this.className; + this.log = LoggerProvider.getOrCreate({ level, label }); + } + + public getOasPath() { + return OAS.paths[ + "/api/v1/plugins/@hyperledger/cactus-plugin-keychain-aws-sm/has-keychain-entry" + ]; + } + + public getPath(): string { + const apiPath = this.getOasPath(); + return apiPath.post["x-hyperledger-cactus"].http.path; + } + + public getVerbLowerCase(): string { + const apiPath = this.getOasPath(); + return apiPath.post["x-hyperledger-cactus"].http.verbLowerCase; + } + + public getOperationId(): string { + return this.getOasPath().post.operationId; + } + + getAuthorizationOptionsProvider(): IAsyncProvider { + // TODO: make this an injectable dependency in the constructor + return { + get: async () => ({ + isProtected: true, + requiredRoles: [], + }), + }; + } + + public async registerExpress( + expressApp: Express, + ): Promise { + await registerWebServiceEndpoint(expressApp, this); + return this; + } + + public getExpressRequestHandler(): IExpressRequestHandler { + return this.handleRequest.bind(this); + } + + public async handleRequest(req: Request, res: Response): Promise { + const reqTag = `${this.getVerbLowerCase()} - ${this.getPath()}`; + this.log.debug(reqTag); + const reqBody = req.body; + try { + const resBody = await this.options.connector.has(reqBody.key); + res.json(resBody); + } catch (ex) { + this.log.error(`Crash while serving ${reqTag}`, ex); + res.status(500).json({ + message: "Internal Server Error", + error: ex?.stack || ex?.message, + }); + } + } +} diff --git a/packages/cactus-plugin-keychain-aws-sm/src/test/typescript/integration/all-da-tests.test.ts b/packages/cactus-plugin-keychain-aws-sm/src/test/typescript/integration/all-da-tests.test.ts deleted file mode 100644 index 0a3e93c562..0000000000 --- a/packages/cactus-plugin-keychain-aws-sm/src/test/typescript/integration/all-da-tests.test.ts +++ /dev/null @@ -1,202 +0,0 @@ -import test, { Test } from "tape-promise/tape"; - -import { v4 as internalIpV4 } from "internal-ip"; -import { v4 as uuidv4 } from "uuid"; -import { createServer } from "http"; -import KeyEncoder from "key-encoder"; -import { AddressInfo } from "net"; -import Web3 from "web3"; -import EEAClient, { IWeb3InstanceExtended } from "web3-eea"; - -import { - ApiServer, - AuthorizationProtocol, - ConfigService, -} from "@hyperledger/cactus-cmd-api-server"; -import { - Secp256k1Keys, - KeyFormat, - LogLevelDesc, -} from "@hyperledger/cactus-common"; - -import { - BesuTestLedger, - Containers, - K_DEFAULT_LOCALSTACK_HTTP_PORT, - LocalStackContainer, - pruneDockerAllIfGithubAction, -} from "@hyperledger/cactus-test-tooling"; - -import { PluginLedgerConnectorBesu } from "@hyperledger/cactus-plugin-ledger-connector-besu"; - -import { PluginRegistry } from "@hyperledger/cactus-core"; - -import { PluginKeychainMemory } from "@hyperledger/cactus-plugin-keychain-memory"; -import { - AwsCredentialType, - GetKeychainEntryRequest, - IPluginKeychainAwsSmOptions, - PluginKeychainAwsSm, -} from "../../../main/typescript"; -import { GetKeychainEntryResponse } from "../../../../../cactus-core-api/dist/types/main/typescript/public-api"; - -const testCase = "API Client can call get via network"; -const logLevel: LogLevelDesc = "TRACE"; - -test("BEFORE " + testCase, async (t: Test) => { - const pruning = pruneDockerAllIfGithubAction({ logLevel }); - await t.doesNotReject(pruning, "Pruning didn't throw OK"); - t.end(); -}); - -test(testCase, async (t: Test) => { - const localStackContainer = new LocalStackContainer({ - logLevel: logLevel, - }); - await localStackContainer.start(); - - const ci = await Containers.getById(localStackContainer.containerId); - const localstackIpAddr = await internalIpV4(); - const hostPort = await Containers.getPublicPort( - K_DEFAULT_LOCALSTACK_HTTP_PORT, - ci, - ); - const localstackHost = `http://${localstackIpAddr}:${hostPort}`; - const keyEncoder: KeyEncoder = new KeyEncoder("secp256k1"); - const keychainId = uuidv4(); - const keychainRef = uuidv4(); - - const { privateKey } = Secp256k1Keys.generateKeyPairsBuffer(); - const keyHex = privateKey.toString("hex"); - const pem = keyEncoder.encodePrivate(keyHex, KeyFormat.Raw, KeyFormat.PEM); - - const keychain = new PluginKeychainMemory({ - backend: new Map([[keychainRef, pem]]), - keychainId, - logLevel, - instanceId: uuidv4(), - }); - - const httpServer1 = createServer(); - await new Promise((resolve, reject) => { - httpServer1.once("error", reject); - httpServer1.once("listening", resolve); - httpServer1.listen(0, "127.0.0.1"); - }); - const addressInfo1 = httpServer1.address() as AddressInfo; - t.comment(`HttpServer1 AddressInfo: ${JSON.stringify(addressInfo1)}`); - const node1Host = `http://${addressInfo1.address}:${addressInfo1.port}`; - t.comment(`Cactus Node 1 Host: ${node1Host}`); - - const besuTestLedger = new BesuTestLedger(); - await besuTestLedger.start(); - - const tearDown = async () => { - await besuTestLedger.stop(); - await besuTestLedger.destroy(); - }; - - test.onFinish(tearDown); - //const testAccount = await besuTestLedger.createEthTestAccount(); - const rpcApiHttpHost = await besuTestLedger.getRpcApiHttpHost(); - const rpcApiWsHost = await besuTestLedger.getRpcApiWsHost(); - - // 2. Instantiate plugin registry which will provide the web service plugin with the key value storage plugin - const pluginRegistry = new PluginRegistry({ plugins: [keychain] }); - - // 3. Instantiate the web service consortium plugin - const options: IPluginKeychainAwsSmOptions = { - instanceId: uuidv4(), - keychainId: uuidv4(), - rpcApiHttpHost, - rpcApiWsHost, - pluginRegistry, - awsEndpoint: localstackHost, - awsRegion: "us-east-1", - awsProfile: "default", - awsCredentialType: AwsCredentialType.LocalFile, - awsCredentialFilePath: `tmpDirPath/credentials`, - logLevel, - }; - const pluginValidatorBesu = new PluginLedgerConnectorBesu(options); - - // 4. Create the API Server object that we embed in this test - const configService = new ConfigService(); - const apiServerOptions = configService.newExampleConfig(); - apiServerOptions.authorizationProtocol = AuthorizationProtocol.NONE; - apiServerOptions.configFile = ""; - apiServerOptions.apiCorsDomainCsv = "*"; - apiServerOptions.apiPort = addressInfo1.port; - apiServerOptions.cockpitPort = 0; - apiServerOptions.apiTlsEnabled = false; - const config = configService.newExampleConfigConvict(apiServerOptions); - - pluginRegistry.add(pluginValidatorBesu); - - const apiServer = new ApiServer({ - httpServerApi: httpServer1, - config: config.getProperties(), - pluginRegistry, - }); - - // 5. make sure the API server is shut down when the testing if finished. - test.onFinish(() => apiServer.shutdown()); - - // 6. Start the API server which is now listening on port A and it's healthcheck works through the main SDK - await apiServer.start(); - - // 7. Instantiate the main SDK dynamically with whatever port the API server ended up bound to (port 0) - t.comment(`AddressInfo: ${JSON.stringify(addressInfo1)}`); - - const web3Provider = new Web3.providers.HttpProvider(rpcApiHttpHost); - const web3 = new Web3(web3Provider); - const web3Eea: IWeb3InstanceExtended = EEAClient(web3, 2018); - - const orionKeyPair = await besuTestLedger.getOrionKeyPair(); - const besuKeyPair = await besuTestLedger.getBesuKeyPair(); - - const besuPrivateKey = besuKeyPair.privateKey.toLowerCase().startsWith("0x") - ? besuKeyPair.privateKey.substring(2) - : besuKeyPair.privateKey; // besu node's private key - - const contractOptions = { - data: `0x123`, - // privateFrom : Orion public key of the sender. - privateFrom: orionKeyPair.publicKey, - // privateFor : Orion public keys of recipients or privacyGroupId: Privacy group to receive the transaction - privateFor: [orionKeyPair.publicKey], - // privateKey: Ethereum private key with which to sign the transaction. - privateKey: besuPrivateKey, - }; - - const transactionHash = await web3Eea.eea.sendRawTransaction(contractOptions); - await web3.eth.getTransaction(transactionHash); - - /* - const transaction = await web3.eth.getTransaction(transactionHash); - const singData = jsObjectSigner.sign(transaction.input); - const signDataHex = Buffer.from(singData).toString("hex"); - */ - - const request: GetKeychainEntryRequest = { - key: "whatswefsd", - //What is the key for the test - }; - - const api = new PluginKeychainAwsSm(options); - - // Test for 200 valid response test case - const res = await api.get(request.key); - t.ok(res, "API response object is truthy"); - t.true( - typeof (res as GetKeychainEntryResponse).key === "string", - "Response is String ok", - ); - //.data.key -}); - -test("AFTER " + testCase, async (t: Test) => { - const pruning = pruneDockerAllIfGithubAction({ logLevel }); - await t.doesNotReject(pruning, "Pruning didn't throw OK"); - t.end(); -}); diff --git a/packages/cactus-plugin-keychain-aws-sm/src/test/typescript/integration/plugin-keychain-aws-sm.test.ts b/packages/cactus-plugin-keychain-aws-sm/src/test/typescript/integration/plugin-keychain-aws-sm.test.ts index f79e1dbbf2..47e1e7a462 100644 --- a/packages/cactus-plugin-keychain-aws-sm/src/test/typescript/integration/plugin-keychain-aws-sm.test.ts +++ b/packages/cactus-plugin-keychain-aws-sm/src/test/typescript/integration/plugin-keychain-aws-sm.test.ts @@ -113,6 +113,14 @@ test("get,set,has,delete alters state as expected", async (t: Test) => { value: value1, }); + await apiClient.getKeychainEntry({ + key: key1, + }); + + await apiClient.hasKeychainEntry({ + key: key1, + }); + const hasAfter1 = await plugin1.has(key1); t.true(hasAfter1, "hasAfter1 === true OK"); @@ -120,7 +128,9 @@ test("get,set,has,delete alters state as expected", async (t: Test) => { t.ok(valueAfter1, "valueAfter1 truthy OK"); t.equal(valueAfter1, value1, "valueAfter1 === value OK"); - await plugin1.delete(key1); + await apiClient.deleteKeychainEntry({ + key: key1, + }); const hasAfterDelete1 = await plugin1.has(key1); t.false(hasAfterDelete1, "hasAfterDelete1 === false OK"); @@ -152,6 +162,23 @@ test("get,set,has,delete alters state as expected", async (t: Test) => { }; const plugin2 = new PluginKeychainAwsSm(options2); + const expressApp = express(); + expressApp.use(bodyParser.json({ limit: "250mb" })); + const server = http.createServer(expressApp); + const listenOptions: IListenOptions = { + hostname: "0.0.0.0", + port: 0, + server, + }; + const addressInfo = (await Servers.listen(listenOptions)) as AddressInfo; + test.onFinish(async () => await Servers.shutdown(server)); + const { address, port } = addressInfo; + const apiHost = `http://${address}:${port}`; + const config = new Configuration({ basePath: apiHost }); + const apiClient = new KeychainAwsSmApi(config); + + await plugin2.registerWebServices(expressApp); + t.equal(plugin2.getKeychainId(), options2.keychainId, "Keychain ID set OK"); t.equal(plugin2.getInstanceId(), options2.instanceId, "Instance ID set OK"); @@ -162,7 +189,11 @@ test("get,set,has,delete alters state as expected", async (t: Test) => { t.false(hasPrior2, "hasPrior2 === false OK"); - await plugin2.set(key2, value2); + //await plugin2.set(key2, value2); + await apiClient.setKeychainEntry({ + key: key2, + value: value2, + }); const hasAfter2 = await plugin2.has(key2); t.true(hasAfter2, "hasAfter2 === true OK"); @@ -171,7 +202,10 @@ test("get,set,has,delete alters state as expected", async (t: Test) => { t.ok(valueAfter2, "valueAfter2 truthy OK"); t.equal(valueAfter2, value2, "valueAfter2 === value OK"); - await plugin2.delete(key2); + //await plugin2.delete(key2); + await apiClient.deleteKeychainEntry({ + key: key2, + }); const hasAfterDelete2 = await plugin2.has(key2); t.false(hasAfterDelete2, "hasAfterDelete2 === false OK");