-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: introduce sso secret templating #276
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
c8ccd9c
feat: introduce sso secret templating
jeff-mccoy d7c0440
unit tests for generateSecretData()
TristanHoladay ea3c4b7
Merge branch 'main' into sso-client-templating
TristanHoladay b6fb5af
pepr 0.28.5
jeff-mccoy 222e2f6
use data vs stringData due to k8s oddities
jeff-mccoy 125180f
more logging for skipping CRs
jeff-mccoy ad638d5
re-add debug logging
jeff-mccoy 931df64
more logs
jeff-mccoy d67b1f2
update tests
jeff-mccoy 93f162d
fix cleanup issues
jeff-mccoy 8ecdfbf
Merge branch 'main' into sso-client-templating
TristanHoladay File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
99 changes: 99 additions & 0 deletions
99
src/pepr/operator/controllers/keycloak/client-sync.spec.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,99 @@ | ||
import { describe, expect, it } from "@jest/globals"; | ||
import { generateSecretData } from "./client-sync"; | ||
import { Client } from "./types"; | ||
|
||
const mockClient: Client = { | ||
alwaysDisplayInConsole: true, | ||
attributes: { first: "attribute" }, | ||
authenticationFlowBindingOverrides: {}, | ||
bearerOnly: true, | ||
clientAuthenticatorType: "", | ||
clientId: "testId", | ||
consentRequired: true, | ||
defaultClientScopes: [], | ||
defaultRoles: [], | ||
directAccessGrantsEnabled: true, | ||
enabled: true, | ||
frontchannelLogout: true, | ||
fullScopeAllowed: true, | ||
implicitFlowEnabled: true, | ||
nodeReRegistrationTimeout: 1, | ||
notBefore: 1, | ||
optionalClientScopes: [], | ||
protocol: "", | ||
publicClient: true, | ||
secret: "", | ||
redirectUris: ["https://demo.uds.dev/login"], | ||
registrationAccessToken: "", | ||
surrogateAuthRequired: true, | ||
serviceAccountsEnabled: true, | ||
webOrigins: [], | ||
standardFlowEnabled: true, | ||
}; | ||
|
||
const mockClientStringified: Record<string, string> = { | ||
alwaysDisplayInConsole: "true", | ||
attributes: '{"first":"attribute"}', | ||
authenticationFlowBindingOverrides: "{}", | ||
bearerOnly: "true", | ||
clientAuthenticatorType: "", | ||
clientId: "testId", | ||
consentRequired: "true", | ||
defaultClientScopes: "[]", | ||
defaultRoles: "[]", | ||
directAccessGrantsEnabled: "true", | ||
enabled: "true", | ||
frontchannelLogout: "true", | ||
fullScopeAllowed: "true", | ||
implicitFlowEnabled: "true", | ||
nodeReRegistrationTimeout: "1", | ||
notBefore: "1", | ||
optionalClientScopes: "[]", | ||
protocol: "", | ||
publicClient: "true", | ||
secret: "", | ||
redirectUris: '["https://demo.uds.dev/login"]', | ||
registrationAccessToken: "", | ||
surrogateAuthRequired: "true", | ||
serviceAccountsEnabled: "true", | ||
webOrigins: "[]", | ||
standardFlowEnabled: "true", | ||
}; | ||
|
||
describe("Test Secret & Template Data Generation", () => { | ||
it("generates data without template", async () => { | ||
const expected: Record<string, string> = {}; | ||
|
||
for (const key in mockClientStringified) { | ||
expected[key] = Buffer.from(mockClientStringified[key]).toString("base64"); | ||
} | ||
expect(generateSecretData(mockClient)).toEqual(expected); | ||
}); | ||
|
||
it("generates data from template: no key or .json()", () => { | ||
const mockTemplate = { | ||
"auth.json": JSON.stringify({ client_id: "clientField(clientId)" }), | ||
}; | ||
expect(generateSecretData(mockClient, mockTemplate)).toEqual({ | ||
"auth.json": Buffer.from('{"client_id":"testId"}').toString("base64"), | ||
}); | ||
}); | ||
|
||
it("generates data from template: has key", () => { | ||
const mockTemplate = { | ||
"auth.json": JSON.stringify({ redirect_uri: "clientField(redirectUris)[0]" }), | ||
}; | ||
expect(generateSecretData(mockClient, mockTemplate)).toEqual({ | ||
"auth.json": Buffer.from('{"redirect_uri":"https://demo.uds.dev/login"}').toString("base64"), | ||
}); | ||
}); | ||
|
||
it("generates data from template: has .json()", () => { | ||
const mockTemplate = { | ||
"auth.json": JSON.stringify({ defaultScopes: "clientField(attributes).json()" }), | ||
}; | ||
expect(generateSecretData(mockClient, mockTemplate)).toEqual({ | ||
"auth.json": Buffer.from('{"defaultScopes":"{"first":"attribute"}"}').toString("base64"), | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure which order of these is best, I think I would put
Store.removeItem(ref);
afterawait apiCall()
and wrap both of these in a try/catch. It looks like there's no error handling at the moment and the error won't be caught.Need to decide what behavior you want in case of Keycloak API errors. My suggestion would be to not drop the client from the store unless the DELETE succeeds. Unsure what's best, if it goes wrong someone may need to manually drop the item and I don't think it's really possible to hack the Pepr store directly. Deleting an item from the
.spec
manually is possible though, I don't think the client names are stored there though?