"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 jose_1 = require("jose");
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 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,
});
tape_1.default(testCase, async (t) => {
    try {
        const jwtKeyPair = await jose_1.JWK.generate("RSA", 4096);
        const jwtPublicKey = jwtKeyPair.toPEM(false);
        const expressJwtOptions = {
            algorithms: ["RS256"],
            secret: jwtPublicKey,
            audience: uuid_1.v4(),
            issuer: uuid_1.v4(),
        };
        t.ok(expressJwtOptions, "Express JWT config truthy OK");
        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: uuid_1.v4(),
        });
        pluginRegistry.add(plugin);
        const configService = new public_api_1.ConfigService();
        const apiSrvOpts = 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.apiTlsEnabled = false;
        apiSrvOpts.plugins = [];
        const config = configService.newExampleConfigConvict(apiSrvOpts);
        const apiServer = new public_api_1.ApiServer({
            config: config.getProperties(),
            pluginRegistry,
        });
        const mainAssertion = "API server refuses to start when non-exempt unprotected endpoints are present OK";
        await t.rejects(apiServer.start(), new RegExp(public_api_1.ApiServer.E_NON_EXEMPT_UNPROTECTED_ENDPOINTS), mainAssertion);
        t.end();
    }
    catch (ex) {
        log.error(ex);
        t.fail("Exception thrown during test execution, see above for details!");
        throw ex;
    }
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiand0LXVucHJvdGVjdGVkLWVuZHBvaW50LWF1dGh6LW9wcy1jb25maXJtLnRlc3QuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi9zcmMvdGVzdC90eXBlc2NyaXB0L2ludGVncmF0aW9uL2p3dC11bnByb3RlY3RlZC1lbmRwb2ludC1hdXRoei1vcHMtY29uZmlybS50ZXN0LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7Ozs7O0FBQUEsNkRBQStDO0FBQy9DLCtCQUFvQztBQUNwQywrQkFBMkI7QUFHM0IsOERBQTBFO0FBQzFFLDBEQUEwRDtBQUUxRCxvRUFLNkM7QUFFN0Msd0hBQWtIO0FBRWxILE1BQU0sUUFBUSxHQUNaLGtGQUFrRixDQUFDO0FBQ3JGLE1BQU0sUUFBUSxHQUFpQixPQUFPLENBQUM7QUFDdkMsTUFBTSxHQUFHLEdBQUcsOEJBQWMsQ0FBQyxXQUFXLENBQUM7SUFDckMsS0FBSyxFQUFFLFFBQVE7SUFDZixLQUFLLEVBQUUsVUFBVTtDQUNsQixDQUFDLENBQUM7QUFFSCxjQUFJLENBQUMsUUFBUSxFQUFFLEtBQUssRUFBRSxDQUFPLEVBQUUsRUFBRTtJQUMvQixJQUFJO1FBQ0YsTUFBTSxVQUFVLEdBQUcsTUFBTSxVQUFHLENBQUMsUUFBUSxDQUFDLEtBQUssRUFBRSxJQUFJLENBQUMsQ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