Feature to filter Login Events by IP Address (#19341)

Closes #19289
This commit is contained in:
Gabriel Padilha Santos 2023-04-06 08:33:15 -03:00 committed by GitHub
parent 9bb18400ad
commit 7a5b6efe7f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 58 additions and 0 deletions

View file

@ -231,6 +231,17 @@ describe.skip("Events tests", () => {
listingPage.itemsGreaterThan(0); listingPage.itemsGreaterThan(0);
}); });
it("Search by Ip Adress to", () => {
userEventsTab
.assertIpAddressChipGroupExist(true)
.assertUserIdChipGroupExist(false)
.assertEventTypeChipGroupExist(false)
.assertClientChipGroupExist(false)
.assertDateFromChipGroupExist(false)
.assertDateToChipGroupExist(false);
listingPage.itemsGreaterThan(0);
});
it("Search by all elements", () => { it("Search by all elements", () => {
const searchData = new UserEventSearchData(); const searchData = new UserEventSearchData();
searchData.client = eventsTestUserClientId; searchData.client = eventsTestUserClientId;
@ -247,6 +258,13 @@ describe.skip("Events tests", () => {
.assertDateToChipGroupExist(true); .assertDateToChipGroupExist(true);
listingPage.itemsGreaterThan(0); listingPage.itemsGreaterThan(0);
}); });
it("Check `search user events` button enabled", () => {
userEventsTab
.openSearchUserEventDropdownMenu()
.typeIpAddress("11111")
.assertSearchEventBtnIsEnabled(true);
});
}); });
describe("Admin events list", () => { describe("Admin events list", () => {

View file

@ -7,6 +7,7 @@ enum UserEventsTabSearchFormFieldsLabel {
Client = "Client", Client = "Client",
DateFrom = "Date(from)", DateFrom = "Date(from)",
DateTo = "Date(to)", DateTo = "Date(to)",
IpAddress = "IP Address",
} }
export class UserEventSearchData { export class UserEventSearchData {
@ -15,6 +16,7 @@ export class UserEventSearchData {
client?: string; client?: string;
dateFrom?: string; dateFrom?: string;
dateTo?: string; dateTo?: string;
ipAddress?: string;
} }
const emptyStatePage = new EmptyStatePage(); const emptyStatePage = new EmptyStatePage();
@ -27,6 +29,7 @@ export default class UserEventsTab extends PageObject {
private searchClientInput = "#kc-client"; private searchClientInput = "#kc-client";
private searchDateFromInput = "#kc-dateFrom"; private searchDateFromInput = "#kc-dateFrom";
private searchDateToInput = "#kc-dateTo"; private searchDateToInput = "#kc-dateTo";
private searchIpAddress = "#kc-ipAddress";
private searchEventsBtn = "search-events-btn"; private searchEventsBtn = "search-events-btn";
private refreshBtn = "refresh-btn"; private refreshBtn = "refresh-btn";
@ -80,6 +83,11 @@ export default class UserEventsTab extends PageObject {
return this; return this;
} }
public typeIpAddress(ipAddress: string) {
cy.get(this.searchIpAddress).type(ipAddress);
return this;
}
public searchUserEvent(searchData: UserEventSearchData) { public searchUserEvent(searchData: UserEventSearchData) {
this.openSearchUserEventDropdownMenu(); this.openSearchUserEventDropdownMenu();
if (searchData.userId) { if (searchData.userId) {
@ -101,6 +109,9 @@ export default class UserEventsTab extends PageObject {
if (searchData.dateTo) { if (searchData.dateTo) {
cy.get(this.searchDateToInput).type(searchData.dateTo); cy.get(this.searchDateToInput).type(searchData.dateTo);
} }
if (searchData.ipAddress) {
cy.get(this.searchIpAddress).type(searchData.ipAddress);
}
cy.findByTestId(this.searchEventsBtn).click(); cy.findByTestId(this.searchEventsBtn).click();
return this; return this;
} }
@ -140,6 +151,13 @@ export default class UserEventsTab extends PageObject {
return this; return this;
} }
public searchUserEventByIpAddress(ipAddress: string) {
const searchData = new UserEventSearchData();
searchData.ipAddress = ipAddress;
this.searchUserEvent(searchData);
return this;
}
public removeEventTypeChipGroupItem(itemName: string) { public removeEventTypeChipGroupItem(itemName: string) {
super.removeChipGroupItem( super.removeChipGroupItem(
UserEventsTabSearchFormFieldsLabel.EventType, UserEventsTabSearchFormFieldsLabel.EventType,
@ -197,6 +215,14 @@ export default class UserEventsTab extends PageObject {
return this; return this;
} }
public assertIpAddressChipGroupExist(exist: boolean) {
super.assertChipGroupExist(
UserEventsTabSearchFormFieldsLabel.IpAddress,
exist
);
return this;
}
public assertNoSearchResultsExist(exist: boolean) { public assertNoSearchResultsExist(exist: boolean) {
emptyStatePage.checkIfExists(exist); emptyStatePage.checkIfExists(exist);
return this; return this;

View file

@ -58,6 +58,7 @@ type UserEventSearchForm = {
dateTo: string; dateTo: string;
user: string; user: string;
type: EventType[]; type: EventType[];
authIpAddress: string;
}; };
const defaultValues: UserEventSearchForm = { const defaultValues: UserEventSearchForm = {
@ -66,6 +67,7 @@ const defaultValues: UserEventSearchForm = {
dateTo: "", dateTo: "",
user: "", user: "",
type: [], type: [],
authIpAddress: "",
}; };
const StatusRow = (event: EventRepresentation) => const StatusRow = (event: EventRepresentation) =>
@ -141,6 +143,7 @@ export default function EventsSection() {
dateTo: t("dateTo"), dateTo: t("dateTo"),
user: t("userId"), user: t("userId"),
type: t("eventType"), type: t("eventType"),
authIpAddress: t("ipAddress"),
}; };
const { const {
@ -369,6 +372,17 @@ export default function EventsSection() {
)} )}
/> />
</FormGroup> </FormGroup>
<FormGroup
label={t("ipAddress")}
fieldId="kc-ipAddress"
className="keycloak__events_search__form_label"
>
<KeycloakTextInput
id="kc-ipAddress"
data-testid="ipAddress-searchField"
{...register("authIpAddress")}
/>
</FormGroup>
<ActionGroup> <ActionGroup>
<Button <Button
data-testid="search-events-btn" data-testid="search-events-btn"