Always preserve session cookies for all tests (#2215)

This commit is contained in:
Jon Koops 2022-03-09 17:42:51 +01:00 committed by GitHub
parent 37d1087e7e
commit 4e697600e0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 21 additions and 92 deletions

View file

@ -1,7 +1,4 @@
import {
keycloakBefore,
keycloakBeforeEach,
} from "../support/util/keycloak_hooks";
import { keycloakBefore } from "../support/util/keycloak_hooks";
import adminClient from "../support/util/AdminClient";
import LoginPage from "../support/pages/LoginPage";
import ListingPage from "../support/pages/admin_console/ListingPage";
@ -39,10 +36,6 @@ describe("Client authentication subtab", () => {
adminClient.deleteClient(clientId);
});
beforeEach(() => {
keycloakBeforeEach();
});
it("Should update the resource server settings", () => {
authenticationTab.setPolicy("DISABLED").saveSettings();
masthead.checkNotificationMessage("Resource successfully updated");

View file

@ -7,10 +7,7 @@ import ListingPage, {
} from "../support/pages/admin_console/ListingPage";
import SidebarPage from "../support/pages/admin_console/SidebarPage";
import CreateClientScopePage from "../support/pages/admin_console/manage/client_scopes/CreateClientScopePage";
import {
keycloakBefore,
keycloakBeforeEach,
} from "../support/util/keycloak_hooks";
import { keycloakBefore } from "../support/util/keycloak_hooks";
import RoleMappingTab from "../support/pages/admin_console/manage/RoleMappingTab";
import ModalUtils from "../support/util/ModalUtils";
import adminClient from "../support/util/AdminClient";
@ -65,7 +62,6 @@ describe("Client Scopes test", () => {
});
beforeEach(() => {
keycloakBeforeEach();
sidebarPage.goToClientScopes();
});
@ -146,7 +142,6 @@ describe("Client Scopes test", () => {
});
beforeEach(() => {
keycloakBeforeEach();
sidebarPage.goToClientScopes();
});
@ -211,7 +206,6 @@ describe("Client Scopes test", () => {
});
beforeEach(() => {
keycloakBeforeEach();
sidebarPage.goToClientScopes();
});
@ -272,7 +266,6 @@ describe("Client Scopes test", () => {
});
beforeEach(() => {
keycloakBeforeEach();
sidebarPage.goToClientScopes();
});

View file

@ -4,10 +4,7 @@ import ListingPage from "../support/pages/admin_console/ListingPage";
import SidebarPage from "../support/pages/admin_console/SidebarPage";
import ModalUtils from "../support/util/ModalUtils";
import adminClient from "../support/util/AdminClient";
import {
keycloakBefore,
keycloakBeforeEach,
} from "../support/util/keycloak_hooks";
import { keycloakBefore } from "../support/util/keycloak_hooks";
const loginPage = new LoginPage();
const masthead = new Masthead();
@ -34,7 +31,6 @@ describe("Clients SAML tests", () => {
});
beforeEach(() => {
keycloakBeforeEach();
sidebarPage.goToClients();
listingPage.searchItem(samlClientName).goToItemDetails(samlClientName);
});
@ -75,7 +71,6 @@ describe("Clients SAML tests", () => {
});
beforeEach(() => {
keycloakBeforeEach();
sidebarPage.goToClients();
listingPage.searchItem(clientId).goToItemDetails(clientId);
cy.findByTestId("keysTab").click();

View file

@ -10,10 +10,7 @@ import ModalUtils from "../support/util/ModalUtils";
import AdvancedTab from "../support/pages/admin_console/manage/clients/AdvancedTab";
import adminClient from "../support/util/AdminClient";
import InitialAccessTokenTab from "../support/pages/admin_console/manage/clients/InitialAccessTokenTab";
import {
keycloakBefore,
keycloakBeforeEach,
} from "../support/util/keycloak_hooks";
import { keycloakBefore } from "../support/util/keycloak_hooks";
import RoleMappingTab from "../support/pages/admin_console/manage/RoleMappingTab";
import KeysTab from "../support/pages/admin_console/manage/clients/KeysTab";
import ClientScopesTab from "../support/pages/admin_console/manage/clients/ClientScopesTab";
@ -213,7 +210,6 @@ describe("Clients test", () => {
});
beforeEach(() => {
keycloakBeforeEach();
sidebarPage.goToClients();
});
@ -557,7 +553,6 @@ describe("Clients test", () => {
});
beforeEach(() => {
keycloakBeforeEach();
sidebarPage.goToClients();
client = "client_" + (Math.random() + 1).toString(36).substring(7);
@ -615,7 +610,6 @@ describe("Clients test", () => {
});
beforeEach(() => {
keycloakBeforeEach();
sidebarPage.goToClients();
});
@ -692,7 +686,6 @@ describe("Clients test", () => {
});
beforeEach(() => {
keycloakBeforeEach();
sidebarPage.goToClients();
listingPage.searchItem(keysName).goToItemDetails(keysName);
});
@ -729,10 +722,6 @@ describe("Clients test", () => {
listingPage.searchItem(clientName).goToItemDetails(clientName);
});
beforeEach(() => {
keycloakBeforeEach();
});
it("Displays the correct tabs", () => {
cy.findByTestId("client-tabs")
.findByTestId("clientSettingsTab")
@ -775,10 +764,6 @@ describe("Clients test", () => {
adminClient.deleteClient(clientId);
});
beforeEach(() => {
keycloakBeforeEach();
});
it("Shows an explainer text for bearer only clients", () => {
cy.findByTestId("bearer-only-explainer-label").trigger("mouseenter");
cy.findByTestId("bearer-only-explainer-tooltip").should("exist");

View file

@ -2,10 +2,7 @@ import ListingPage from "../support/pages/admin_console/ListingPage";
import LoginPage from "../support/pages/LoginPage";
import SidebarPage from "../support/pages/admin_console/SidebarPage";
import Masthead from "../support/pages/admin_console/Masthead";
import {
keycloakBefore,
keycloakBeforeEach,
} from "../support/util/keycloak_hooks";
import { keycloakBefore } from "../support/util/keycloak_hooks";
const loginPage = new LoginPage();
const masthead = new Masthead();
@ -33,10 +30,6 @@ describe("Masthead tests in desktop mode", () => {
loginPage.logIn();
});
beforeEach(() => {
keycloakBeforeEach();
});
it("Test dropdown in desktop mode", () => {
goToAcctMgtTest();
@ -62,10 +55,6 @@ describe("Masthead tests with kebab menu", () => {
masthead.setMobileMode(true);
});
beforeEach(() => {
keycloakBeforeEach();
});
it("Test dropdown in mobile mode", () => {
masthead.checkKebabShown();
goToAcctMgtTest();

View file

@ -3,10 +3,7 @@ import SidebarPage from "../support/pages/admin_console/SidebarPage";
import LoginPage from "../support/pages/LoginPage";
import PartialImportModal from "../support/pages/admin_console/configure/realm_settings/PartialImportModal";
import RealmSettings from "../support/pages/admin_console/configure/realm_settings/RealmSettings";
import {
keycloakBefore,
keycloakBeforeEach,
} from "../support/util/keycloak_hooks";
import { keycloakBefore } from "../support/util/keycloak_hooks";
import adminClient from "../support/util/AdminClient";
describe("Partial import test", () => {
@ -23,7 +20,6 @@ describe("Partial import test", () => {
});
beforeEach(() => {
keycloakBeforeEach();
// doing this from the UI has the added bonus of putting you in the test realm
sidebarPage.goToCreateRealm();
createRealmPage.fillRealmName(TEST_REALM).createRealm();

View file

@ -5,10 +5,7 @@ import ListingPage from "../support/pages/admin_console/ListingPage";
import SidebarPage from "../support/pages/admin_console/SidebarPage";
import CreateRealmRolePage from "../support/pages/admin_console/manage/realm_roles/CreateRealmRolePage";
import AssociatedRolesPage from "../support/pages/admin_console/manage/realm_roles/AssociatedRolesPage";
import {
keycloakBefore,
keycloakBeforeEach,
} from "../support/util/keycloak_hooks";
import { keycloakBefore } from "../support/util/keycloak_hooks";
import adminClient from "../support/util/AdminClient";
let itemId = "realm_role_crud";
@ -27,7 +24,6 @@ describe("Realm roles test", () => {
});
beforeEach(() => {
keycloakBeforeEach();
sidebarPage.goToRealmRoles();
});

View file

@ -1,10 +1,7 @@
import SidebarPage from "../support/pages/admin_console/SidebarPage";
import LoginPage from "../support/pages/LoginPage";
import RealmSettingsPage from "../support/pages/admin_console/manage/realm_settings/RealmSettingsPage";
import {
keycloakBefore,
keycloakBeforeEach,
} from "../support/util/keycloak_hooks";
import { keycloakBefore } from "../support/util/keycloak_hooks";
import adminClient from "../support/util/AdminClient";
import ModalUtils from "../support/util/ModalUtils";
import Masthead from "../support/pages/admin_console/Masthead";
@ -19,7 +16,6 @@ describe("Realm settings client policies tab tests", () => {
const realmSettingsPage = new RealmSettingsPage(realmName);
beforeEach(() => {
keycloakBeforeEach();
sidebarPage
.waitForPageLoad()
.goToRealm(realmName)

View file

@ -1,10 +1,7 @@
import SidebarPage from "../support/pages/admin_console/SidebarPage";
import LoginPage from "../support/pages/LoginPage";
import RealmSettingsPage from "../support/pages/admin_console/manage/realm_settings/RealmSettingsPage";
import {
keycloakBefore,
keycloakBeforeEach,
} from "../support/util/keycloak_hooks";
import { keycloakBefore } from "../support/util/keycloak_hooks";
import adminClient from "../support/util/AdminClient";
import ModalUtils from "../support/util/ModalUtils";
import Masthead from "../support/pages/admin_console/Masthead";
@ -21,7 +18,6 @@ describe("Realm settings client profiles tab tests", () => {
const realmSettingsPage = new RealmSettingsPage(realmName);
beforeEach(() => {
keycloakBeforeEach();
sidebarPage.waitForPageLoad().goToRealm(realmName).goToRealmSettings();
realmSettingsPage.goToClientPoliciesTab().goToClientProfilesList();
});

View file

@ -3,10 +3,7 @@ import SidebarPage from "../support/pages/admin_console/SidebarPage";
import CreateRealmPage from "../support/pages/admin_console/CreateRealmPage";
import Masthead from "../support/pages/admin_console/Masthead";
import adminClient from "../support/util/AdminClient";
import {
keycloakBefore,
keycloakBeforeEach,
} from "../support/util/keycloak_hooks";
import { keycloakBefore } from "../support/util/keycloak_hooks";
const masthead = new Masthead();
const loginPage = new LoginPage();
@ -26,10 +23,6 @@ describe("Realms test", () => {
loginPage.logIn();
});
beforeEach(() => {
keycloakBeforeEach();
});
after(() => {
[testRealmName, newRealmName, editedRealmName].map((realm) =>
adminClient.deleteRealm(realm)

View file

@ -6,10 +6,7 @@ import Masthead from "../support/pages/admin_console/Masthead";
import SidebarPage from "../support/pages/admin_console/SidebarPage";
import LoginPage from "../support/pages/LoginPage";
import adminClient from "../support/util/AdminClient";
import {
keycloakBefore,
keycloakBeforeEach,
} from "../support/util/keycloak_hooks";
import { keycloakBefore } from "../support/util/keycloak_hooks";
import ModalUtils from "../support/util/ModalUtils";
describe("Realm settings - User registration tab", () => {
@ -31,7 +28,6 @@ describe("Realm settings - User registration tab", () => {
});
beforeEach(() => {
keycloakBeforeEach();
sidebarPage.goToRealmSettings();
userRegistration.goToTab();
});

View file

@ -6,10 +6,7 @@ import ListingPage from "../support/pages/admin_console/ListingPage";
import UserDetailsPage from "../support/pages/admin_console/manage/users/UserDetailsPage";
import AttributesTab from "../support/pages/admin_console/manage/AttributesTab";
import ModalUtils from "../support/util/ModalUtils";
import {
keycloakBefore,
keycloakBeforeEach,
} from "../support/util/keycloak_hooks";
import { keycloakBefore } from "../support/util/keycloak_hooks";
import UserGroupsPage from "../support/pages/admin_console/manage/users/UserGroupsPage";
import adminClient from "../support/util/AdminClient";
import CredentialsPage from "../support/pages/admin_console/manage/users/CredentialsPage";
@ -46,7 +43,6 @@ describe("User creation", () => {
});
beforeEach(() => {
keycloakBeforeEach();
sidebarPage.goToUsers();
});

View file

@ -23,3 +23,12 @@ import "./commands";
if (!Cypress.env("KEYCLOAK_SERVER")) {
Cypress.env("KEYCLOAK_SERVER", "http://localhost:8180");
}
// Always preserve session related cookies.
Cypress.Cookies.defaults({
preserve: isSessionCookie,
});
function isSessionCookie({ name }: Cypress.Cookie) {
return name.startsWith("KEYCLOAK_") || name.startsWith("AUTH_SESSION_");
}

View file

@ -14,7 +14,3 @@ export const keycloakBefore = () => {
cy.visit("");
cy.get('[role="progressbar"]').should("not.exist");
};
export const keycloakBeforeEach = () => {
Cypress.Cookies.preserveOnce("KEYCLOAK_SESSION", "KEYCLOAK_IDENTITY");
};