-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: env var authorities config (#63)
* feat: env var authorities config * chore: unit tests for getRoles * refactor: rename env config
- Loading branch information
Showing
7 changed files
with
134 additions
and
34 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
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,82 @@ | ||
import { test } from "node:test"; | ||
import assert from "node:assert"; | ||
import { getRoles } from "./utils"; | ||
|
||
test("getRoles with roles and permissions", () => { | ||
process.env.AUTHORITIES = "$.realm_access.roles,$.resource_access.*.roles"; | ||
|
||
const testObj = { | ||
realm_access: { | ||
roles: ["admin", "editor"], | ||
}, | ||
resource_access: { | ||
admin: { | ||
roles: ["read", "write"], | ||
}, | ||
}, | ||
}; | ||
|
||
const expectedRoles = ["admin", "editor", "read", "write"]; | ||
const result = getRoles(testObj); | ||
assert.deepStrictEqual( | ||
result, | ||
expectedRoles, | ||
"Should return all roles and permissions", | ||
); | ||
}); | ||
|
||
test("getRoles with one matching path (no wildcard)", () => { | ||
process.env.AUTHORITIES = "$.realm_access.roles,$.resource_access.*.roles"; | ||
|
||
const testObj = { | ||
realm_access: { | ||
roles: ["admin", "editor"], | ||
}, | ||
}; | ||
|
||
const expectedRoles = ["admin", "editor"]; | ||
const result = getRoles(testObj); | ||
assert.deepStrictEqual( | ||
result, | ||
expectedRoles, | ||
"Should return roles from the matching path", | ||
); | ||
}); | ||
|
||
test("getRoles with one matching path (with wildcard)", () => { | ||
process.env.AUTHORITIES = "$.realm_access.roles,$.resource_access.*.roles"; | ||
|
||
const testObj = { | ||
resource_access: { | ||
admin: { | ||
roles: ["read", "write"], | ||
}, | ||
}, | ||
}; | ||
|
||
const expectedRoles = ["read", "write"]; | ||
const result = getRoles(testObj); | ||
assert.deepStrictEqual( | ||
result, | ||
expectedRoles, | ||
"Should return roles from the matching path", | ||
); | ||
}); | ||
|
||
test("getRoles with no matching paths", () => { | ||
process.env.AUTHORITIES = "$.realm_access.roles,$.resource_access.*.roles"; | ||
|
||
const obj = { | ||
guest: { | ||
access: ["view"], | ||
}, | ||
}; | ||
|
||
const expectedRoles: any[] = []; | ||
const result = getRoles(obj); | ||
assert.deepStrictEqual( | ||
result, | ||
expectedRoles, | ||
"Should return an empty array for no matching paths", | ||
); | ||
}); |
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