-
Notifications
You must be signed in to change notification settings - Fork 294
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(cmd-api-server): config-service example - authorization JSON
The custom formatter that was introduced the parse the JSON config for the authorizer was causing problems. This was overlooked at the time of the implementation of the authz feature because Peter (yours truly) is an idiot but also to a smaller extent because there was no automated test coverage for this specific issue which this commit is now rectifying by adding a new test case. Longer term we should look into using a different configuration parsing library that has more flexibility on how to handle JSON and validations around it. There was a second bug masked by the first which is that the "algorithms" array property of the express-jwt middleware options was also not being used correctly, but to get to that first the initial bug with the parsing had to be fixed. Signed-off-by: Peter Somogyvari <[email protected]>
- Loading branch information
Showing
2 changed files
with
53 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...api-server/src/test/typescript/unit/config/config-service-example-config-validity.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { LoggerProvider } from "@hyperledger/cactus-common"; | ||
import test, { Test } from "tape-promise/tape"; | ||
|
||
import { IAuthorizationConfig } from "../../../../main/typescript/public-api"; | ||
import { ApiServer } from "../../../../main/typescript/public-api"; | ||
import { ConfigService } from "../../../../main/typescript/public-api"; | ||
|
||
test("Generates valid example config for the API server", async (t: Test) => { | ||
const configService = new ConfigService(); | ||
t.ok(configService, "Instantiated ConfigService truthy OK"); | ||
|
||
const exampleConfig = configService.newExampleConfig(); | ||
t.ok(exampleConfig, "configService.newExampleConfig() truthy OK"); | ||
|
||
// FIXME - this hack should not be necessary, we need to re-think how we | ||
// do configuration parsing. The convict library may not be the path forward. | ||
exampleConfig.authorizationConfigJson = (JSON.stringify( | ||
exampleConfig.authorizationConfigJson, | ||
) as unknown) as IAuthorizationConfig; | ||
|
||
exampleConfig.configFile = ""; | ||
|
||
const convictConfig = configService.newExampleConfigConvict(exampleConfig); | ||
t.ok(convictConfig, "configService.newExampleConfigConvict() truthy OK"); | ||
|
||
const config = convictConfig.getProperties(); | ||
t.ok(config, "convictConfig.getProperties() truthy OK"); | ||
|
||
LoggerProvider.setLogLevel(config.logLevel); | ||
const apiServer = new ApiServer({ config }); | ||
await apiServer.start(); | ||
test.onFinish(() => apiServer.shutdown()); | ||
t.end(); | ||
}); |