"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const tape_1 = __importDefault(require("tape-promise/tape"));
const uuid_1 = require("uuid");
const public_api_1 = require("../../../main/typescript/public-api");
const cactus_test_tooling_1 = require("@hyperledger/cactus-test-tooling");
const cactus_plugin_keychain_vault_1 = require("@hyperledger/cactus-plugin-keychain-vault");
const cactus_core_api_1 = require("@hyperledger/cactus-core-api");
const path_1 = __importDefault(require("path"));
(0, tape_1.default)("NodeJS API server + Rust plugin work together", async (t) => {
    const vaultTestContainer = new cactus_test_tooling_1.VaultTestServer({});
    await vaultTestContainer.start();
    const ci = await cactus_test_tooling_1.Containers.getById(vaultTestContainer.containerId);
    const vaultIpAddr = await cactus_test_tooling_1.Containers.getContainerInternalIp(ci);
    t.comment(`Container VaultTestServer has IPv4: ${vaultIpAddr}`);
    tape_1.default.onFinish(async () => {
        await vaultTestContainer.stop();
        await vaultTestContainer.destroy();
    });
    const hostPortVault = await vaultTestContainer.getHostPortHttp();
    t.comment(`Container VaultTestServer (Port=${hostPortVault}) started OK`);
    const vaultHost = `http://${vaultIpAddr}:${cactus_test_tooling_1.K_DEFAULT_VAULT_HTTP_PORT}`;
    const pluginContainer = new cactus_test_tooling_1.CactusKeychainVaultServer({
        envVars: [
            `VAULT_HOST=${vaultHost}`,
            `VAULT_TOKEN=${cactus_test_tooling_1.K_DEFAULT_VAULT_DEV_ROOT_TOKEN}`,
            "HOST=0.0.0.0:8080",
        ],
    });
    await pluginContainer.start();
    tape_1.default.onFinish(async () => {
        await pluginContainer.stop();
        await pluginContainer.destroy();
    });
    const hostPort = await pluginContainer.getHostPortHttp();
    t.comment(`CactusKeychainVaultServer (Port=${hostPort}) started OK`);
    const configuration = new cactus_core_api_1.Configuration({
        basePath: `http://127.0.0.1:${hostPort}`,
    });
    const apiClient = new cactus_plugin_keychain_vault_1.DefaultApi(configuration);
    const pluginsPath = path_1.default.join(__dirname, // start at the current file's path
    "../../../../../../", // walk back up to the project root
    ".tmp/test/cmd-api-server/remote-plugin-imports_test", // the dir path from the root
    (0, uuid_1.v4)());
    const pluginManagerOptionsJson = JSON.stringify({ pluginsPath });
    const configService = new public_api_1.ConfigService();
    const apiServerOptions = await configService.newExampleConfig();
    apiServerOptions.authorizationProtocol = public_api_1.AuthorizationProtocol.NONE;
    apiServerOptions.pluginManagerOptionsJson = pluginManagerOptionsJson;
    apiServerOptions.configFile = "";
    apiServerOptions.apiCorsDomainCsv = "*";
    apiServerOptions.apiPort = 0;
    apiServerOptions.cockpitPort = 0;
    apiServerOptions.grpcPort = 0;
    apiServerOptions.crpcPort = 0;
    apiServerOptions.apiTlsEnabled = false;
    apiServerOptions.plugins = [
        {
            packageName: "@hyperledger/cactus-plugin-keychain-vault",
            type: cactus_core_api_1.PluginImportType.Remote,
            action: cactus_core_api_1.PluginImportAction.Install,
            options: {
                keychainId: "_keychainId_",
                instanceId: "_instanceId_",
                remoteConfig: configuration,
            },
        },
    ];
    const config = await configService.newExampleConfigConvict(apiServerOptions);
    const apiServer = new public_api_1.ApiServer({
        config: config.getProperties(),
    });
    await t.doesNotReject(apiServer.start(), "Started API server OK");
    tape_1.default.onFinish(() => apiServer.shutdown());
    const key = (0, uuid_1.v4)();
    const expected = (0, uuid_1.v4)();
    await apiClient.setKeychainEntryV1({ key, value: expected });
    const { data: { value: actual }, } = await apiClient.getKeychainEntryV1({ key });
    t.equal(actual, expected, "Keychain stored value matches input OK");
    t.end();
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmVtb3RlLXBsdWdpbi1pbXBvcnRzLnRlc3QuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi9zcmMvdGVzdC90eXBlc2NyaXB0L2ludGVncmF0aW9uL3JlbW90ZS1wbHVnaW4taW1wb3J0cy50ZXN0LnRzIl0sIm5hbWVzIjpbXSwibWF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