-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Case Wylie <cmwylie19@defenseunicorns.com>
- Loading branch information
Showing
9 changed files
with
79 additions
and
79 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
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
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 |
---|---|---|
@@ -1,16 +1,32 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: 2023-Present The Pepr Authors | ||
|
||
import { describe, jest } from "@jest/globals"; | ||
|
||
import { beforeAll, describe, jest } from "@jest/globals"; | ||
import { promises as fs } from "fs"; | ||
import { peprBuild } from "./pepr-build-wasm"; | ||
|
||
import { resolve } from "path"; | ||
import { cwd } from "./entrypoint.test"; | ||
|
||
// Unmock unit test things | ||
jest.deepUnmock("pino"); | ||
|
||
|
||
// Allow 5 minutes for the tests to run | ||
jest.setTimeout(1000 * 60 * 5); | ||
export const outputDir = "dist/pepr-test-module/child/folder"; | ||
beforeAll(async () => { | ||
await fs.mkdir(outputDir, { recursive: true }); | ||
await addScopedRbacMode(); | ||
}); | ||
describe( | ||
"Journey: `npx pepr build -r gchr.io/defenseunicorns -o dist/pepr-test-module/child/folder`", | ||
peprBuild, | ||
); | ||
|
||
describe("Journey: `npx pepr build -r gchr.io/defenseunicorns --rbac-mode scoped -o dist/pepr-test-module/child/folder`", peprBuild); | ||
// Set rbacMode in the Pepr Module Config and write it back to disk | ||
async function addScopedRbacMode() { | ||
const packageJson = await fs.readFile(resolve(cwd, "package.json"), "utf8"); | ||
const packageJsonObj = JSON.parse(packageJson); | ||
console.log(JSON.stringify(packageJsonObj.pepr)); | ||
packageJsonObj.pepr.rbacMode = "scoped"; | ||
await fs.writeFile(resolve(cwd, "package.json"), JSON.stringify(packageJsonObj, null, 2)); | ||
} |
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
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
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,36 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: 2023-Present The Pepr Authors | ||
|
||
import { determineRbacMode } from "./build"; | ||
|
||
import { expect, describe, test } from "@jest/globals"; | ||
|
||
describe("determineRbacMode", () => { | ||
test("should allow CLI options to overwrite module config", () => { | ||
const opts = { rbacMode: "admin" }; | ||
const cfg = { pepr: { rbacMode: "scoped" } }; | ||
const result = determineRbacMode(opts, cfg); | ||
expect(result).toBe("admin"); | ||
}); | ||
|
||
test('should return "admin" when cfg.pepr.rbacMode is provided and not "scoped"', () => { | ||
const opts = {}; | ||
const cfg = { pepr: { rbacMode: "admin" } }; | ||
const result = determineRbacMode(opts, cfg); | ||
expect(result).toBe("admin"); | ||
}); | ||
|
||
test('should return "scoped" when cfg.pepr.rbacMode is "scoped"', () => { | ||
const opts = {}; | ||
const cfg = { pepr: { rbacMode: "scoped" } }; | ||
const result = determineRbacMode(opts, cfg); | ||
expect(result).toBe("scoped"); | ||
}); | ||
|
||
test("should default to admin when neither option is provided", () => { | ||
const opts = {}; | ||
const cfg = { pepr: {} }; | ||
const result = determineRbacMode(opts, cfg); | ||
expect(result).toBe("admin"); | ||
}); | ||
}); |
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,15 @@ | ||
// determineRbacMode determines the RBAC mode to use based on the cli and the module's config | ||
export function determineRbacMode(opts: { rbacMode?: string }, cfg: { pepr: { rbacMode?: string } }): string { | ||
// CLI overrides the module's config | ||
if (opts.rbacMode) { | ||
return opts.rbacMode; | ||
} | ||
|
||
// if rbacMode is defined and not scoped, return admin | ||
if (cfg.pepr.rbacMode && cfg.pepr.rbacMode !== "scoped") { | ||
return "admin"; | ||
} | ||
|
||
// if nothing is defined return admin, else return scoped | ||
return cfg.pepr.rbacMode || "admin"; | ||
} |
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
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