-
Notifications
You must be signed in to change notification settings - Fork 887
chore: add e2e test against an external auth provider during workspace creation #12985
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
Changes from 1 commit
638ce38
e150061
eb40352
5a9ddaf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Signed-off-by: Danny Kopping <danny@coder.com>
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ import { | |
type Resource, | ||
Response, | ||
type RichParameter, | ||
type ExternalAuthProviderResource, | ||
} from "./provisionerGenerated"; | ||
|
||
// requiresEnterpriseLicense will skip the test if we're not running with an enterprise license | ||
|
@@ -49,6 +50,7 @@ export const createWorkspace = async ( | |
templateName: string, | ||
richParameters: RichParameter[] = [], | ||
buildParameters: WorkspaceBuildParameter[] = [], | ||
useExternalAuthProvider: string | undefined = undefined, | ||
): Promise<string> => { | ||
await page.goto(`/templates/${templateName}/workspace`, { | ||
waitUntil: "domcontentloaded", | ||
|
@@ -59,6 +61,25 @@ export const createWorkspace = async ( | |
await page.getByLabel("name").fill(name); | ||
|
||
await fillParameters(page, richParameters, buildParameters); | ||
|
||
if (useExternalAuthProvider !== undefined) { | ||
// Create a new context for the popup which will be created when clicking the button | ||
const popupPromise = page.waitForEvent("popup"); | ||
|
||
// Find the "Login with <Provider>" button | ||
const externalAuthLoginButton = page.locator( | ||
"#external-auth-" + useExternalAuthProvider, | ||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Regardless of the main way we end up selecting the element, I would recommend making sure the selector asserts that the element we're grabbing is actually exposed to the user as a button (ideally through something like It's possible to add click behavior to non-button elements, but that can get janky quick. Changing the selector would add an extra security net to ensure that users can use all the behavior that buttons bake in automatically |
||
await expect(externalAuthLoginButton).toBeVisible(); | ||
|
||
// Click it | ||
await externalAuthLoginButton.click(); | ||
|
||
// Wait for authentication to occur | ||
const popup = await popupPromise; | ||
await popup.waitForSelector("text=You are now authenticated."); | ||
} | ||
|
||
await page.getByTestId("form-submit").click(); | ||
|
||
await expectUrl(page).toHavePathName("/@admin/" + name); | ||
|
@@ -648,6 +669,37 @@ export const echoResponsesWithParameters = ( | |
}; | ||
}; | ||
|
||
export const echoResponsesWithExternalAuth = ( | ||
providers: ExternalAuthProviderResource[], | ||
): EchoProvisionerResponses => { | ||
return { | ||
parse: [ | ||
{ | ||
parse: {}, | ||
}, | ||
], | ||
plan: [ | ||
{ | ||
plan: { | ||
externalAuthProviders: providers, | ||
}, | ||
}, | ||
], | ||
apply: [ | ||
{ | ||
apply: { | ||
externalAuthProviders: providers, | ||
resources: [ | ||
{ | ||
name: "example", | ||
}, | ||
], | ||
}, | ||
}, | ||
], | ||
}; | ||
}; | ||
|
||
export const fillParameters = async ( | ||
page: Page, | ||
richParameters: RichParameter[] = [], | ||
|
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.
I think that with the new parameter, the function is getting a little unwieldy, and if you're looking at things from the consumer side, it's hard to tell which of the five arguments correspond to what
Maybe this could be refactored to an object, so that we have sort of have named arguments?
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.
I agree in principle, but I think 5 params is still manageable and not worth refactoring the 26 usages of this function IMHO. Happy to discuss.