Skip to content

Commit

Permalink
test(cmd-api-server): fix expected Non-exempt unprotected got Failed …
Browse files Browse the repository at this point in the history
…to start

1. Refactored the assertion to inspect the nested inner exception's message
instead of the outer, more generic one.
2. Also fixed a bug in the ApiServer class where it was constructing a comma
seperated list of unprotected endpoints incorrectly and ended up with
[object object] as the CSV instead of a list of the HTTP URLs of the endpoints.

Fixes #2711

[skip ci]

Signed-off-by: Peter Somogyvari <[email protected]>
  • Loading branch information
petermetz committed Oct 11, 2023
1 parent cda279f commit da47e3c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -783,7 +783,7 @@ export class ApiServer {
!unprotectedEndpointExemptions.some((pt) => nse.getPath().match(pt)),
);
if (nonExempts.length > 0) {
const csv = nonExempts.join(", ");
const csv = nonExempts.map((ep) => ep.getPath()).join(", ");
const { E_NON_EXEMPT_UNPROTECTED_ENDPOINTS } = ApiServer;
throw new Error(`${E_NON_EXEMPT_UNPROTECTED_ENDPOINTS} ${csv}`);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
} from "../../../main/typescript/public-api";

import { PluginLedgerConnectorStub } from "../fixtures/plugin-ledger-connector-stub/plugin-ledger-connector-stub";
import { UnprotectedActionEndpoint } from "../fixtures/plugin-ledger-connector-stub/web-services/unprotected-action-endpoint";

const testCase =
"block unprotected endpoint if not confirmed by ops via deploy-time configuration";
Expand Down Expand Up @@ -67,10 +68,18 @@ test(testCase, async () => {
pluginRegistry,
});

const eps = await plugin.getOrCreateWebServices();
const epCsv = eps
.filter((ep) => ep instanceof UnprotectedActionEndpoint)
.map((ep) => ep.getPath())
.join(",");
const expectedMsg = `${ApiServer.E_NON_EXEMPT_UNPROTECTED_ENDPOINTS} ${epCsv}`;

const startPromise = apiServer.start();

await expect(startPromise).rejects.toThrow(
ApiServer.E_NON_EXEMPT_UNPROTECTED_ENDPOINTS,
await expect(startPromise).rejects.toHaveProperty(
["cause", "message"],
expectedMsg,
);
} catch (ex) {
log.error(ex);
Expand Down

0 comments on commit da47e3c

Please sign in to comment.