Add signing-in tests
Fixes: #21245 Signed-off-by: Hynek Mlnarik <hmlnarik@redhat.com>
This commit is contained in:
parent
ba91f2aacc
commit
2914c5821d
5 changed files with 136 additions and 4 deletions
|
@ -34,9 +34,10 @@ import { useEnvironment } from "../root/KeycloakContext";
|
|||
type MobileLinkProps = {
|
||||
title: string;
|
||||
onClick: () => void;
|
||||
testid?: string;
|
||||
};
|
||||
|
||||
const MobileLink = ({ title, onClick }: MobileLinkProps) => {
|
||||
const MobileLink = ({ title, onClick, testid }: MobileLinkProps) => {
|
||||
const [open, setOpen] = useState(false);
|
||||
return (
|
||||
<>
|
||||
|
@ -56,6 +57,7 @@ const MobileLink = ({ title, onClick }: MobileLinkProps) => {
|
|||
variant="link"
|
||||
onClick={onClick}
|
||||
className="pf-u-display-none pf-u-display-inline-flex-on-lg"
|
||||
data-testid={testid}
|
||||
>
|
||||
{title}
|
||||
</Button>
|
||||
|
@ -145,13 +147,18 @@ export const SigningIn = () => {
|
|||
title={t("setUpNew", {
|
||||
name: t(container.displayName as TFuncKey),
|
||||
})}
|
||||
testid={`${container.category}/create`}
|
||||
/>
|
||||
</div>
|
||||
</SplitItem>
|
||||
)}
|
||||
</Split>
|
||||
|
||||
<DataList aria-label="credential list" className="pf-u-mb-xl">
|
||||
<DataList
|
||||
aria-label="credential list"
|
||||
className="pf-u-mb-xl"
|
||||
data-testid={`${container.category}/credential-list`}
|
||||
>
|
||||
{container.userCredentialMetadatas.length === 0 && (
|
||||
<EmptyRow
|
||||
message={t("notSetUp", {
|
||||
|
|
92
js/apps/account-ui/test/account-security/signing-in.spec.ts
Normal file
92
js/apps/account-ui/test/account-security/signing-in.spec.ts
Normal file
|
@ -0,0 +1,92 @@
|
|||
import { expect, test } from "@playwright/test";
|
||||
import {
|
||||
getUserByUsername,
|
||||
getCredentials,
|
||||
deleteCredential,
|
||||
deleteRealm,
|
||||
importRealm,
|
||||
} from "../admin-client";
|
||||
import { login } from "../login";
|
||||
import groupsRealm from "../realms/groups-realm.json" assert { type: "json" };
|
||||
import RealmRepresentation from "@keycloak/keycloak-admin-client/lib/defs/realmRepresentation";
|
||||
|
||||
const realm = "groups";
|
||||
test.describe("Signing in", () => {
|
||||
// Tests for keycloak account console, section Signing in in Account security
|
||||
test("Should see only password", async ({ page }) => {
|
||||
await login(page, "jdoe", "jdoe", "groups");
|
||||
|
||||
await page.getByTestId("accountSecurity").click();
|
||||
await expect(page.getByTestId("account-security/signing-in")).toBeVisible();
|
||||
page.getByTestId("account-security/signing-in").click();
|
||||
|
||||
await expect(
|
||||
page
|
||||
.getByTestId("basic-authentication/credential-list")
|
||||
.getByRole("listitem"),
|
||||
).toHaveCount(1);
|
||||
await expect(
|
||||
page
|
||||
.getByTestId("basic-authentication/credential-list")
|
||||
.getByRole("listitem"),
|
||||
).toContainText("My password");
|
||||
await expect(page.getByTestId("basic-authentication/create")).toBeHidden();
|
||||
|
||||
await expect(
|
||||
page.getByTestId("two-factor/credential-list").getByRole("listitem"),
|
||||
).toHaveCount(1);
|
||||
await expect(
|
||||
page.getByTestId("two-factor/credential-list").getByRole("listitem"),
|
||||
).toContainText("not set up");
|
||||
await expect(page.getByTestId("two-factor/create")).toBeVisible();
|
||||
|
||||
await page.getByTestId("two-factor/create").click();
|
||||
await expect(page.locator("#kc-page-title")).toContainText(
|
||||
"Mobile Authenticator Setup",
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
test.describe("Signing in 2", () => {
|
||||
test.afterAll(async () => {
|
||||
await deleteRealm(realm);
|
||||
await importRealm(groupsRealm as RealmRepresentation);
|
||||
});
|
||||
test("Password removal", async ({ page }) => {
|
||||
const jdoeUser = await getUserByUsername("jdoe", realm);
|
||||
|
||||
await login(page, "jdoe", "jdoe", "groups");
|
||||
|
||||
const credentials = await getCredentials(jdoeUser!.id!, realm);
|
||||
deleteCredential(jdoeUser!.id!, credentials![0].id!, realm);
|
||||
|
||||
await page.getByTestId("accountSecurity").click();
|
||||
await expect(page.getByTestId("account-security/signing-in")).toBeVisible();
|
||||
page.getByTestId("account-security/signing-in").click();
|
||||
|
||||
await expect(
|
||||
page
|
||||
.getByTestId("basic-authentication/credential-list")
|
||||
.getByRole("listitem"),
|
||||
).toHaveCount(1);
|
||||
await expect(
|
||||
page
|
||||
.getByTestId("basic-authentication/credential-list")
|
||||
.getByRole("listitem"),
|
||||
).toContainText("not set up");
|
||||
await expect(page.getByTestId("basic-authentication/create")).toBeVisible();
|
||||
|
||||
await expect(
|
||||
page.getByTestId("two-factor/credential-list").getByRole("listitem"),
|
||||
).toHaveCount(1);
|
||||
await expect(
|
||||
page.getByTestId("two-factor/credential-list").getByRole("listitem"),
|
||||
).toContainText("not set up");
|
||||
await expect(page.getByTestId("two-factor/create")).toBeVisible();
|
||||
|
||||
await page.getByTestId("basic-authentication/create").click();
|
||||
await expect(page.locator("#kc-page-title")).toContainText(
|
||||
"Update password",
|
||||
);
|
||||
});
|
||||
});
|
|
@ -58,6 +58,11 @@ export async function createUser(user: UserRepresentation, realm: string) {
|
|||
}
|
||||
}
|
||||
|
||||
export async function getUserByUsername(username: string, realm: string) {
|
||||
const users = await adminClient.users.find({ username, realm, exact: true });
|
||||
return users.length > 0 ? users[0] : undefined;
|
||||
}
|
||||
|
||||
export async function deleteUser(username: string, realm: string) {
|
||||
try {
|
||||
const users = await adminClient.users.find({ username, realm });
|
||||
|
@ -67,3 +72,31 @@ export async function deleteUser(username: string, realm: string) {
|
|||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
export async function updateUser(user: UserRepresentation, realm: string) {
|
||||
try {
|
||||
await adminClient.users.update({ id: user.id!, realm }, user);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
export async function getCredentials(id: string, realm: string) {
|
||||
try {
|
||||
return await adminClient.users.getCredentials({ id, realm });
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
export async function deleteCredential(
|
||||
id: string,
|
||||
credentialId: string,
|
||||
realm: string,
|
||||
) {
|
||||
try {
|
||||
await adminClient.users.deleteCredential({ id, credentialId, realm });
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ test.describe("Groups page", () => {
|
|||
await expect(page.getByTestId("group[1].name")).toHaveText("three");
|
||||
});
|
||||
|
||||
test("List my direct and indirect groups", async ({ page }) => {
|
||||
test("List direct and indirect groups", async ({ page }) => {
|
||||
await login(page, "alice", "alice", "groups");
|
||||
await page.getByTestId("groups").click();
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
"enabled": true,
|
||||
"realmRoles": [],
|
||||
"clientRoles": {
|
||||
"account": ["view-groups"]
|
||||
"account": ["view-groups", "manage-account"]
|
||||
},
|
||||
"credentials": [
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue