-
Notifications
You must be signed in to change notification settings - Fork 277
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🪟 🎉 Cloud SSO: add frontend support for multiple keycloak realms (#8855)
Co-authored-by: Tim Roes <[email protected]>
- Loading branch information
Showing
12 changed files
with
517 additions
and
62 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
103 changes: 103 additions & 0 deletions
103
airbyte-webapp/src/packages/cloud/services/auth/KeycloakService/KeycloakService.test.tsx
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,103 @@ | ||
import { renderHook, waitFor } from "@testing-library/react"; | ||
import { PropsWithChildren } from "react"; | ||
|
||
import { KeycloakService, initializeUserManager, useKeycloakService } from "./KeycloakService"; | ||
|
||
let windowSearchSpy: jest.SpyInstance; | ||
|
||
describe(`${initializeUserManager.name}()`, () => { | ||
beforeEach(() => { | ||
windowSearchSpy = jest.spyOn(window, "location", "get"); | ||
}); | ||
|
||
afterEach(() => { | ||
windowSearchSpy.mockRestore(); | ||
}); | ||
|
||
it("should initialize with the correct default realm", () => { | ||
const userManager = initializeUserManager(); | ||
expect(userManager.settings.authority).toMatch(/auth\/realms\/airbyte/); | ||
}); | ||
|
||
it("should initialize realm from query params", () => { | ||
windowSearchSpy.mockImplementation(() => ({ | ||
search: "?realm=another-realm", | ||
})); | ||
const userManager = initializeUserManager(); | ||
expect(userManager.settings.authority).toMatch(/auth\/realms\/another-realm/); | ||
}); | ||
|
||
it("should initialize realm based on local storage", () => { | ||
const mockKey = "oidc.user:https://example.com/auth/realms/local-storage-realm:local-storage-client-id"; | ||
window.localStorage.setItem(mockKey, "no need to populate the value for this test"); | ||
const userManager = initializeUserManager(); | ||
expect(userManager.settings.authority).toMatch(/auth\/realms\/local-storage-realm/); | ||
window.localStorage.removeItem(mockKey); | ||
}); | ||
}); | ||
|
||
describe(`${KeycloakService.name}`, () => { | ||
const wrapper: React.FC<PropsWithChildren> = ({ children }) => <KeycloakService>{children}</KeycloakService>; | ||
|
||
it("should initialize with the correct default realm", async () => { | ||
const { result } = renderHook(() => useKeycloakService(), { wrapper }); | ||
await waitFor(() => { | ||
expect(result?.current.userManager.settings.authority).toMatch(/auth\/realms\/airbyte/); | ||
}); | ||
}); | ||
|
||
it("should initialize realm from query params", async () => { | ||
windowSearchSpy = jest.spyOn(window, "location", "get"); | ||
windowSearchSpy.mockImplementation(() => ({ | ||
search: "?realm=another-realm", | ||
})); | ||
|
||
const { result } = renderHook(() => useKeycloakService(), { wrapper }); | ||
|
||
await waitFor(() => { | ||
expect(result?.current.userManager.settings.authority).toMatch(/auth\/realms\/another-realm/); | ||
}); | ||
|
||
windowSearchSpy.mockRestore(); | ||
}); | ||
|
||
it("should initialize realm based on local storage", async () => { | ||
window.localStorage.setItem( | ||
"oidc.user:https://example.com/auth/realms/local-storage-realm:local-storage-client-id", | ||
JSON.stringify({ | ||
id_token: | ||
"eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICIxOXpGOG5CVWNJcDNPMTBTQVZvUE1oYnhocThsbmVnRnJaNXBZcEtzT3NzIn0.eyJleHAiOjE2OTU2ODIzMjIsImlh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S5jb20vYXV0aC9yZWFsbXMvdGVzdC1jb21wYW55LTEiLCJzdWIiOiIwYWEzYmVhYi02MDU3LTQ4NjEtYWQ5MS0wNWZlM2U3NmJhMjIiLCJ0eXAiOiJSZWZyZXNoIiwiYXpwIjoiYWlyYnl0ZS13ZWJhcHAiLCJzZXNzaW9uX3N0YXRlIjoiZDBkMGU3YWEtYTVjOC00ODA2LTkzMDgtNDZlYTk4NGRmYTlkIiwic2NvcGUiOiJvcGVuaWQgZW1haWwgcHJvZmlsZSIsInNpZCI6ImQwZDBlN2FhLWE1YzgtNDgwNi05MzA4LTQ2ZWE5ODRkZmE5ZCJ9.WRqTUNC6eY00zkYbK3GGy-wbvON47rWJu6TgXGG1QvA", | ||
token_type: "Bearer", | ||
scope: "openid email profile", | ||
profile: { | ||
exp: 1695682322, | ||
iat: 1695682022, | ||
iss: "https://dev-2-cloud.airbyte.com/auth/realms/test-company-1", | ||
aud: "airbyte-webapp", | ||
sub: "0aa3beab-6057-4861-ad91-05fe3e76ba22", | ||
typ: "ID", | ||
session_state: "d0d0e7aa-a5c8-4806-9308-46ea984dfa9d", | ||
sid: "d0d0e7aa-a5c8-4806-9308-46ea984dfa9d", | ||
email_verified: true, | ||
name: "Joey Marshment-Howell", | ||
preferred_username: "admin-company-1", | ||
given_name: "Joey", | ||
family_name: "Marshment-Howell", | ||
email: "[email protected]", | ||
}, | ||
expires_at: 1695682322, | ||
}) | ||
); | ||
|
||
const { result } = renderHook(() => useKeycloakService(), { wrapper }); | ||
|
||
await waitFor(() => { | ||
expect(result?.current.userManager.settings.authority).toMatch(/auth\/realms\/local-storage-realm/); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.