+Credential details
, + CredentialsStep: ({ onBack }: { onBack: () => void }) => ( + <> +Credential details
+ + > + ), })); vi.mock("./steps/test-connection-step", () => ({ TestConnectionStep: ({ @@ -73,7 +90,16 @@ vi.mock("./steps/test-connection-step", () => ({ > ), })); -vi.mock("./steps/launch-step", () => ({ LaunchStep: () => null })); +vi.mock("./steps/launch-step", () => ({ + LaunchStep: ({ onBack }: { onBack: () => void }) => ( + <> +Launch scan
+ + > + ), +})); vi.mock("../organizations/azure-org-setup-form", () => ({ AzureOrgSetupForm: () => null, })); @@ -128,6 +154,9 @@ describe("provider wizard account creation", () => { status: "ready", options: [{ type: "acme", label: "Acme Cloud" }], }); + testProviderConnection.mockResolvedValue({ connected: true, error: null }); + updateCredentialsProvider.mockResolvedValue({ data: { id: "secret-1" } }); + updateProvider.mockResolvedValue({ data: { id: "provider-1" } }); }); afterEach(() => { @@ -305,9 +334,11 @@ describe("provider wizard account creation", () => { await waitFor(() => expect(connect).toBeEnabled()); await user.click(connect); - // Then: the separate credentials step never shows up. - expect(await screen.findByText("Connection test")).toBeVisible(); + // Then: neither the credentials step nor the connection test shows up. + expect(await screen.findByText("Launch scan")).toBeVisible(); expect(screen.queryByText("Credential details")).not.toBeInTheDocument(); + expect(screen.queryByText("Connection test")).not.toBeInTheDocument(); + expect(testProviderConnection).toHaveBeenCalledWith("provider-1"); expect(useProviderWizardStore.getState()).toMatchObject({ providerId: "provider-1", secretId: "secret-1", @@ -315,7 +346,71 @@ describe("provider wizard account creation", () => { }); }); - it("returns to the one-step form when the connection test is stepped back from", async () => { + it("keeps the account on the one-step form when the connection is refused", async () => { + // Given + addProvider.mockResolvedValue({ data: { id: "provider-1" } }); + addCredentialsProvider.mockResolvedValue({ data: { id: "secret-1" } }); + testProviderConnection.mockResolvedValue({ + connected: false, + error: "The role could not be assumed.", + }); + const user = await pickAws(); + + // When + await user.type( + screen.getByRole("textbox", { name: /Role ARN/ }), + ROLE_ARN, + ); + const connect = screen.getByRole("button", { name: "Connect account" }); + await waitFor(() => expect(connect).toBeEnabled()); + await user.click(connect); + + // Then + expect( + await screen.findByText("The role could not be assumed."), + ).toBeVisible(); + expect(screen.queryByText("Launch scan")).not.toBeInTheDocument(); + expect(screen.getByRole("textbox", { name: /Role ARN/ })).toBeVisible(); + }); + + it("closes instead of launching a scan when AWS credentials are updated", async () => { + // Given: the row action opens an existing AWS provider's credentials. + addProvider.mockResolvedValue({ data: { id: "provider-1" } }); + addCredentialsProvider.mockResolvedValue({ data: { id: "secret-1" } }); + const onOpenChange = vi.fn(); + const user = userEvent.setup(); + render( +
+
+ {error} +
+