Skip to content

Commit

Permalink
SPSH-967: Implemented PW tests for 2FA (#95)
Browse files Browse the repository at this point in the history
* SPSH-967: Implemented PW tests for 2FA

* SPSH-967: Refactored and implemented the tests for 2FA

* SPSH-967: Removed the 2FA test user from the config

* SPSH-967: Reverted changes for 2FA tests

* SPSH-967: PR Review & Refactor.

* SPSH-967: undone the env.dev file

* SPSH-967: Fixed issues caused by merge conflicts

* SPSH-967: Fixed 2FA tests
  • Loading branch information
phaelcg authored Nov 25, 2024
1 parent 761e090 commit 4064a10
Show file tree
Hide file tree
Showing 9 changed files with 269 additions and 29 deletions.
6 changes: 3 additions & 3 deletions base/api/testHelperPerson.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { HeaderPage } from '../../pages/Header.page';
import { LoginPage } from '../../pages/LoginView.page';
import { faker } from '@faker-js/faker';
import { lehrkraftOeffentlichRolle } from '../roles';
import { generateLehrerNachname, generateLehrerVorname } from "../testHelperGenerateTestdataNames";
import { generateNachname, generateVorname } from "../testHelperGenerateTestdataNames";

const FRONTEND_URL: string | undefined = process.env.FRONTEND_URL || "";

Expand Down Expand Up @@ -98,8 +98,8 @@ export async function getPersonId(page: Page, Benutzername: string): Promise<str
export async function createTeacherAndLogin(page) {
const header = new HeaderPage(page);
const login: LoginPage = new LoginPage(page);
const vorname = await generateLehrerVorname();
const nachname = await generateLehrerNachname();
const vorname = await generateVorname();
const nachname = await generateNachname();
const organisation = 'Testschule Schulportal';
const kopersNr = '0815' + faker.string.numeric({ length: 3 });

Expand Down
3 changes: 2 additions & 1 deletion base/rollentypen.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export const typelehrer = "LEHR";
export const typelehrer = "LEHR";
export const typeSchueler = "LERN";
3 changes: 2 additions & 1 deletion base/sp.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export const email = "E-Mail";
export const email = "E-Mail";
export const itslearning = "itslearning";
4 changes: 2 additions & 2 deletions base/testHelperGenerateTestdataNames.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { faker } from "@faker-js/faker/locale/de";
import { generateRandomString, CharacterSetType } from "ts-randomstring/lib/index.js"

export async function generateLehrerVorname(){
export async function generateVorname(){
return "TAuto-PW-V-" + faker.person.firstName() + generateRandomString({length: 3,charSetType: CharacterSetType.Alphabetic})
}

export async function generateLehrerNachname(){
export async function generateNachname(){
return "TAuto-PW-N-" + faker.person.lastName() + generateRandomString({length: 3,charSetType: CharacterSetType.Alphabetic})
}

Expand Down
1 change: 0 additions & 1 deletion pages/ProfileView.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,5 @@ export class ProfilePage{
this.cardHeadline_2FA = page.getByTestId('two-factor-card');
this.text_no2FA = page.getByText('Es wurde noch kein zweiter Faktor für Sie eingerichtet.');
this.button_2FAEinrichten = page.getByTestId('open-2FA-self-service-dialog-icon');

}
}
52 changes: 52 additions & 0 deletions pages/admin/PersonDetailsView.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export class PersonDetailsViewPage{
readonly text_h2_benutzerBearbeiten: Locator;

// Passwort
readonly text_h3_passwort_headline: Locator;
readonly button_pwChange: Locator;
readonly button_pwReset: Locator;
readonly text_pwResetInfo: Locator;
Expand All @@ -17,6 +18,7 @@ export class PersonDetailsViewPage{
readonly button_closeDeletePersonConfirm: Locator;

// Schulzuordnungen
readonly text_h3_schulzuordnung_headline: Locator;
readonly button_editSchulzuordnung: Locator;
readonly button_addSchulzuordnung: Locator;
readonly combobox_organisation: Locator;
Expand All @@ -27,6 +29,9 @@ export class PersonDetailsViewPage{
readonly button_confirmAddSchulzuordnung: Locator;
readonly button_saveAssignmentChanges: Locator;
readonly button_closeSaveAssignmentChanges: Locator;

// Benutzer sperren
readonly text_h3_lockPerson_headline: Locator;
readonly button_lockPerson: Locator;
readonly button_lockPersonConfirm: Locator;
readonly text_h2_dialogBenutzerSperren: Locator;
Expand All @@ -38,12 +43,29 @@ export class PersonDetailsViewPage{
readonly radio_button_befristet: Locator;
readonly text_sperrdatumAb: Locator;
readonly text_sperrdatumBis: Locator;

// 2FA
readonly text_h3_2FA: Locator;
readonly text_token_IstEingerichtet_info: Locator;
readonly text_neuen_token_einrichten_info: Locator;
readonly text_kein_token_ist_Eingerichtet: Locator;
readonly button_2FAEinrichten: Locator;
readonly text_2FA_info: Locator;
readonly dialog_2FA_Einrichten: Locator;
readonly text_h2_2FA_cardheadline: Locator;
readonly selectOption_2FA_softwareToken: Locator;
readonly text_2FA_softwareToken_info: Locator;
readonly button_2FA_Einrichten_Weiter: Locator;
readonly button_close_softwareToken_dialog: Locator;
readonly button_2FA_Zuruecksetzen_Weiter: Locator;


constructor(page){
this.page = page;
this.text_h2_benutzerBearbeiten = page.getByTestId('layout-card-headline');

// Passwort
this.text_h3_passwort_headline = page.locator( `//h3[text()='Passwort']`);
this.button_pwChange = page.getByTestId('open-password-reset-dialog-icon');
this.button_pwReset = page.getByTestId('password-reset-button');
this.text_pwResetInfo = page.getByTestId('password-reset-info-text');
Expand All @@ -56,6 +78,7 @@ export class PersonDetailsViewPage{
this.button_closeDeletePersonConfirm = page.getByTestId('close-person-delete-success-dialog-button');

// Schulzuordnungen
this.text_h3_schulzuordnung_headline = page.getByText('Schulzuordnung(en)');
this.button_editSchulzuordnung = page.locator('div').filter({ hasText: /^Schulzuordnung\(en\)Bearbeiten$/ }).getByTestId('zuordnung-edit-button');
this.button_addSchulzuordnung = page.getByTestId('zuordnung-create-button');
this.combobox_organisationDialogBenutzerSperren = page.getByTestId('person-lock-card').locator('.v-field__input');
Expand All @@ -66,6 +89,9 @@ export class PersonDetailsViewPage{
this.button_confirmAddSchulzuordnung = page.getByRole('button', { name: 'Ja' });
this.button_saveAssignmentChanges = page.getByTestId('zuordnung-changes-save');
this.button_closeSaveAssignmentChanges = page.getByRole('dialog').getByRole('button', { name: 'Schließen' });

// Benutzer sperren
this.text_h3_lockPerson_headline = page.getByTestId('person-lock-info').getByText('Status');
this.button_lockPerson = page.getByTestId('open-lock-dialog-button');
this.button_lockPersonConfirm = page.getByTestId('lock-user-button');
this.text_h2_dialogBenutzerSperren = page.getByTestId('person-lock-card').getByTestId('layout-card-headline');
Expand All @@ -77,6 +103,20 @@ export class PersonDetailsViewPage{
this.radio_button_befristet = page.getByTestId('befristet-radio-button').getByLabel('Befristet');
this.text_sperrdatumAb = page.getByTestId('lock-info-1-attribute');
this.text_sperrdatumBis = page.getByTestId('lock-info-2-attribute');

//2FA
this.text_h3_2FA = page.getByText('Zwei-Faktor-Authentifizierung (2FA)');
this.text_kein_token_ist_Eingerichtet = page.getByText('Für diesen Benutzer ist aktuell keine 2FA eingerichtet.');
this.text_token_IstEingerichtet_info = page.getByText('Für diesen Benutzer ist aktuell ein Software-Token eingerichtet.');
this.text_neuen_token_einrichten_info = page.getByText('Um einen neuen Token einzurichten, muss der aktuelle Token durch die schulischen Administratorinnen und Administratoren zurückgesetzt werden.');
this.button_2FAEinrichten = page.getByTestId('open-2FA-dialog-icon');
this.dialog_2FA_Einrichten = page.getByTestId('two-factor-authentication-dialog');
this.text_h2_2FA_cardheadline = this.dialog_2FA_Einrichten.getByTestId('layout-card-headline');
this.text_2FA_softwareToken_info = page.getByText('Ein QR-Code wird generiert, welcher direkt eingescannt oder ausgedruckt werden kann.');
this.selectOption_2FA_softwareToken = page.getByTestId('software-token-radio-button');
this.button_2FA_Einrichten_Weiter = page.getByTestId('proceed-two-factor-authentication-dialog-button');
this.button_close_softwareToken_dialog = page.getByTestId('close-software-token-dialog-button');
this.button_2FA_Zuruecksetzen_Weiter = page.getByTestId('two-way-authentification-set-up-button');
}

public async lockUserWithoutDate() {
Expand Down Expand Up @@ -111,4 +151,16 @@ export class PersonDetailsViewPage{
public async checkLockDateTo(lockDateTo: string) {
await expect(this.text_sperrdatumBis).toHaveText(lockDateTo);
}

public async softwareTokenEinrichten() {
await this.button_2FAEinrichten.click();
await expect(this.text_h2_2FA_cardheadline).toHaveText('Zwei-Faktor-Authentifizierung einrichten');
await expect(this.selectOption_2FA_softwareToken).toHaveText('Software-Token einrichten');
await expect(this.text_2FA_softwareToken_info).toBeVisible();
await this.button_2FA_Einrichten_Weiter.click();

await expect(this.text_h2_2FA_cardheadline).toHaveText('Software-Token einrichten');
await this.button_close_softwareToken_dialog.click();
}

}
6 changes: 3 additions & 3 deletions tests/Person.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { addSystemrechtToRolle } from "../base/api/testHelperRolle.page";
import { LONG, SHORT, STAGE, BROWSER } from "../base/tags";
import { deletePersonByUsername, deleteRolleById, deleteRolleByName } from "../base/testHelperDeleteTestdata.ts";
import { landesadminRolle, schuelerRolle, schuladminOeffentlichRolle } from "../base/roles.ts";
import { generateLehrerNachname, generateLehrerVorname, generateRolleName } from "../base/testHelperGenerateTestdataNames.ts";
import { generateNachname, generateVorname, generateRolleName } from "../base/testHelperGenerateTestdataNames.ts";

const PW: string | undefined = process.env.PW;
const ADMIN: string | undefined = process.env.USER;
Expand Down Expand Up @@ -705,8 +705,8 @@ test.describe(`Testfälle für die Administration von Personen": Umgebung: ${pro
const PersonDetailsView = new PersonDetailsViewPage(page);
const header = new HeaderPage(page);

const vorname = await generateLehrerVorname();
const nachname = await generateLehrerNachname();
const vorname = await generateVorname();
const nachname = await generateNachname();
const rolle = await generateRolleName();
const berechtigung = 'SYSADMIN';
const idSP = await getSPId(page, 'Schulportal-Administration');
Expand Down
Loading

0 comments on commit 4064a10

Please sign in to comment.