"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const uuid_1 = require("uuid");
const jose_1 = require("jose");
require("jest-extended");
const cactus_common_1 = require("@hyperledger/cactus-common");
const cactus_core_1 = require("@hyperledger/cactus-core");
const public_api_1 = require("../../../main/typescript/public-api");
const plugin_ledger_connector_stub_1 = require("../fixtures/plugin-ledger-connector-stub/plugin-ledger-connector-stub");
const unprotected_action_endpoint_1 = require("../fixtures/plugin-ledger-connector-stub/web-services/unprotected-action-endpoint");
const testCase = "block unprotected endpoint if not confirmed by ops via deploy-time configuration";
const logLevel = "TRACE";
const log = cactus_common_1.LoggerProvider.getOrCreate({
    level: logLevel,
    label: __filename,
});
test(testCase, async () => {
    try {
        const jwtKeyPair = await (0, jose_1.generateKeyPair)("RS256", { modulusLength: 4096 });
        const jwtPublicKey = await (0, jose_1.exportSPKI)(jwtKeyPair.publicKey);
        const expressJwtOptions = {
            algorithms: ["RS256"],
            secret: jwtPublicKey,
            audience: (0, uuid_1.v4)(),
            issuer: (0, uuid_1.v4)(),
        };
        expect(expressJwtOptions).toBeTruthy();
        const authorizationConfig = {
            unprotectedEndpointExemptions: [],
            expressJwtOptions,
            socketIoJwtOptions: { secret: jwtPublicKey },
        };
        const pluginRegistry = new cactus_core_1.PluginRegistry();
        const plugin = new plugin_ledger_connector_stub_1.PluginLedgerConnectorStub({
            logLevel,
            pluginRegistry,
            instanceId: (0, uuid_1.v4)(),
        });
        pluginRegistry.add(plugin);
        const configService = new public_api_1.ConfigService();
        const apiSrvOpts = await configService.newExampleConfig();
        apiSrvOpts.authorizationProtocol = public_api_1.AuthorizationProtocol.JSON_WEB_TOKEN;
        apiSrvOpts.authorizationConfigJson = authorizationConfig;
        apiSrvOpts.configFile = "";
        apiSrvOpts.apiCorsDomainCsv = "*";
        apiSrvOpts.apiPort = 0;
        apiSrvOpts.cockpitPort = 0;
        apiSrvOpts.grpcPort = 0;
        apiSrvOpts.crpcPort = 0;
        apiSrvOpts.apiTlsEnabled = false;
        apiSrvOpts.plugins = [];
        const config = await configService.newExampleConfigConvict(apiSrvOpts);
        const apiServer = new public_api_1.ApiServer({
            config: config.getProperties(),
            pluginRegistry,
        });
        const eps = await plugin.getOrCreateWebServices();
        const epCsv = eps
            .filter((ep) => ep instanceof unprotected_action_endpoint_1.UnprotectedActionEndpoint)
            .map((ep) => ep.getPath())
            .join(",");
        const expectedMsg = `${public_api_1.ApiServer.E_NON_EXEMPT_UNPROTECTED_ENDPOINTS} ${epCsv}`;
        const startPromise = apiServer.start();
        await expect(startPromise).rejects.toHaveProperty(["cause", "message"], expectedMsg);
    }
    catch (ex) {
        log.error(ex);
        fail("Exception thrown during test execution, see above for details!");
    }
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiand0LXVucHJvdGVjdGVkLWVuZHBvaW50LWF1dGh6LW9wcy1jb25maXJtLnRlc3QuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi9zcmMvdGVzdC90eXBlc2NyaXB0L2ludGVncmF0aW9uL2p3dC11bnByb3RlY3RlZC1lbmRwb2ludC1hdXRoei1vcHMtY29uZmlybS50ZXN0LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQUEsK0JBQW9DO0FBQ3BDLCtCQUFtRDtBQUNuRCx5QkFBdUI7QUFHdkIsOERBQTBFO0FBQzFFLDBEQUEwRDtBQUUxRCxvRUFLNkM7QUFFN0Msd0hBQWtIO0FBQ2xILG1JQUE4SDtBQUU5SCxNQUFNLFFBQVEsR0FDWixrRkFBa0YsQ0FBQztBQUNyRixNQUFNLFFBQVEsR0FBaUIsT0FBTyxDQUFDO0FBQ3ZDLE1BQU0sR0FBRyxHQUFHLDhCQUFjLENBQUMsV0FBVyxDQUFDO0lBQ3JDLEtBQUssRUFBRSxRQUFRO0lBQ2YsS0FBSyxFQUFFLFVBQVU7Q0FDbEIsQ0FBQyxDQUFDO0FBRUgsSUFBSSxDQU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