Skip to content

Commit

Permalink
fix: shutdown hook configuration is using wrong config key
Browse files Browse the repository at this point in the history
In the api-server constructor the evaluation for the activation /
deactivation of the shutdown hook is based on the wrong configuration
property so that it always is falling back to the default value and
pre-configured value is not taken.

Closes: hyperledger-cacti#1619
Signed-off-by: Michael Courtin <michael.courtin@accenture.com>
  • Loading branch information
m-courtin authored and petermetz committed Dec 15, 2021
1 parent 7deaa22 commit e760e04
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,10 @@ export class ApiServer {
throw new Error(`ApiServer#ctor options.config was falsy`);
}

this.enableShutdownHook = Bools.isBooleanStrict(options.enableShutdownHook)
? (options.enableShutdownHook as boolean)
this.enableShutdownHook = Bools.isBooleanStrict(
options.config.enableShutdownHook,
)
? (options.config.enableShutdownHook as boolean)
: true;

if (this.enableShutdownHook) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import "jest-extended";
import {
ApiServer,
// AuthorizationProtocol,
ConfigService,
} from "../../../../main/typescript/public-api";

describe("api-server shutdown-hook configuration tests", () => {
// create a config service as base for the following UTs
const configService = new ConfigService();

it("enables the shutdown hook based on schema-default", async () => {
const expectedResult = true;
const apiServerOptions = await configService.newExampleConfig();
const config = await configService.newExampleConfigConvict(
apiServerOptions,
);

const apiServer = new ApiServer({
config: config.getProperties(),
});

// check apiServerOptions
expect(apiServerOptions).not.toBeUndefined();
expect(apiServerOptions.enableShutdownHook).toBe(expectedResult);

// check apiServer
expect(apiServer).toBeTruthy();
const result = apiServer["enableShutdownHook"];
expect(result).toBe(expectedResult);
});

it("disables the shutdown hook based on the config value set to false", async () => {
const expectedResult = false;
const apiServerOptions = await configService.newExampleConfig();

// disable shutdown hook
apiServerOptions.enableShutdownHook = false;

const config = await configService.newExampleConfigConvict(
apiServerOptions,
true,
);

const apiServer = new ApiServer({
config: config.getProperties(),
});

// check apiServerOptions
expect(apiServerOptions).not.toBeUndefined();
expect(apiServerOptions.enableShutdownHook).toBe(expectedResult);

// check apiServer
expect(apiServer).toBeTruthy();
const result = apiServer["enableShutdownHook"];
expect(result).toBe(expectedResult);
});

it("enables the shutdown hook based on the config value set to true", async () => {
const expectedResult = true;
const apiServerOptions = await configService.newExampleConfig();

// disable shutdown hook
apiServerOptions.enableShutdownHook = true;

const config = await configService.newExampleConfigConvict(
apiServerOptions,
true,
);

const apiServer = new ApiServer({
config: config.getProperties(),
});

// check apiServerOptions
expect(apiServerOptions).not.toBeUndefined();
expect(apiServerOptions.enableShutdownHook).toBe(expectedResult);

// check apiServer
expect(apiServer).toBeTruthy();
const result = apiServer["enableShutdownHook"];
expect(result).toBe(expectedResult);
});
});

0 comments on commit e760e04

Please sign in to comment.