"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"));
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://localhost:${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
    uuid_1.v4());
    const pluginManagerOptionsJson = JSON.stringify({ pluginsPath });
    const configService = new public_api_1.ConfigService();
    const apiServerOptions = 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.apiTlsEnabled = false;
    apiServerOptions.plugins = [
        {
            packageName: "@hyperledger/cactus-plugin-keychain-vault",
            type: cactus_core_api_1.PluginImportType.Remote,
            options: {
                keychainId: "_keychainId_",
                instanceId: "_instanceId_",
                remoteConfig: configuration,
            },
        },
    ];
    const config = 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 = uuid_1.v4();
    const expected = 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,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmVtb3RlLXBsdWdpbi1pbXBvcnRzLnRlc3QuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi9zcmMvdGVzdC90eXBlc2NyaXB0L2ludGVncmF0aW9uL3JlbW90ZS1wbHVnaW4taW1wb3J0cy50ZXN0LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7O0FBQUEsNkRBQStDO0FBQy9DLCtCQUFvQztBQUVwQyxvRUFJNk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