Skip to content

Commit 3e5f663

Browse files
committed
Replace given seeds with direct ipa calls
1 parent 4199c9f commit 3e5f663

11 files changed

Lines changed: 239 additions & 128 deletions

File tree

cypress/e2e/common/cleanupHook.ts

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
import { Before } from "@badeball/cypress-cucumber-preprocessor";
2+
3+
const echoToTerminal = (message: string) => {
4+
const escaped = message.replace(/"/g, '\\"');
5+
cy.exec(
6+
`echo "${escaped}" >> /home/vmiticka/Programming/freeipa-webui/cypress/support/logs.log`
7+
);
8+
};
9+
10+
export const cleanup = (
11+
commands_find: string[],
12+
commands_delete: string[],
13+
omit: string[]
14+
) => {
15+
const command = commands_find.join(" ");
16+
echoToTerminal(
17+
`cleanup starting: find=[${command}] delete=[${commands_delete.join(" ")}] omit=[${omit}]`
18+
);
19+
cy.ipa(command, undefined, {
20+
failOnNonZeroExit: false,
21+
}).then((result) => {
22+
const items: string[] = result.stdout
23+
.split("\n")
24+
.map((line) => line.split(":")[1]?.trim() || "")
25+
.filter((u) => u.length > 0 && !omit.includes(u));
26+
27+
const sample = items.slice(0, 10);
28+
const suffix = items.length > 10 ? " ..." : "";
29+
echoToTerminal(
30+
`about to delete ${items.length} item(s): ${sample.join(", ")}${suffix}`
31+
);
32+
33+
//items.forEach((u) => {
34+
// cy.ipa(commands_delete.join(" "), u, { failOnNonZeroExit: false });
35+
// });
36+
37+
echoToTerminal(
38+
`done cleanup: delete=[${commands_delete.join(" ")}] total=${items.length}`
39+
);
40+
});
41+
};
42+
43+
// Special-case cleanup for services: keep core principals for the test server
44+
const cleanupServices = () => {
45+
const host = Cypress.env("SERVER_NAME") as string;
46+
const keepPrefixes = [
47+
`HTTP/${host}`,
48+
`DNS/${host}`,
49+
`dogtag/${host}`,
50+
`ipa-dnskeysyncd/${host}`,
51+
`ldap/${host}`,
52+
];
53+
54+
echoToTerminal(
55+
`cleanup starting: services keep=[${keepPrefixes.join(", ")}]`
56+
);
57+
58+
cy.exec(`podman exec webui ipa service-find --pkey-only`, {
59+
failOnNonZeroExit: false,
60+
}).then((result) => {
61+
const items: string[] = result.stdout
62+
.split("\n")
63+
.map((line) => line.split(":")[1]?.trim() || "")
64+
.filter(
65+
(u) =>
66+
u.length > 0 && !keepPrefixes.some((prefix) => u.startsWith(prefix))
67+
);
68+
69+
const sample = items.slice(0, 10);
70+
const suffix = items.length > 10 ? " ..." : "";
71+
echoToTerminal(
72+
`about to delete ${items.length} service(s): ${sample.join(", ")}${suffix}`
73+
);
74+
75+
items.forEach((u) => {
76+
cy.ipa("service-del", u, { failOnNonZeroExit: false });
77+
});
78+
79+
echoToTerminal(`done cleanup: service-del total=${items.length}`);
80+
});
81+
};
82+
83+
Before(() => {
84+
cy.log("running cleanup");
85+
cleanup(["automember-find", "--pkey-only"], ["automember-del"], []);
86+
cleanup(["certmaprule-find", "--pkey-only"], ["certmaprule-del"], []);
87+
cleanup(["dnsforwardzone-find", "--pkey-only"], ["dnsforwardzone-del"], []);
88+
cleanup(["dnsrecord-find", "--pkey-only"], ["dnsrecord-del"], []);
89+
cleanup(["dnszone-find", "--pkey-only"], ["dnszone-del"], []);
90+
cleanup(
91+
["group-find", "--pkey-only"],
92+
["group-del"],
93+
["admins", "editors", "ipausers", "trust admins"]
94+
);
95+
cleanup(["hbacrule-find", "--pkey-only"], ["hbacrule-del"], []);
96+
cleanup(["hbacsvc-find", "--pkey-only"], ["hbacsvc-del"], []);
97+
cleanup(["hbacsvcgroup-find", "--pkey-only"], ["hbacsvcgroup-del"], []);
98+
cleanup(["host-find", "--pkey-only"], ["host-del"], []);
99+
cleanup(["hostgroup-find", "--pkey-only"], ["hostgroup-del"], []);
100+
cleanup(["idoverridegroup-find", "--pkey-only"], ["idoverridegroup-del"], []);
101+
cleanup(["idoverrideuser-find", "--pkey-only"], ["idoverrideuser-del"], []);
102+
cleanup(["idp-find", "--pkey-only"], ["idp-del"], []);
103+
cleanup(["idrange-find", "--pkey-only"], ["idrange-del"], []);
104+
cleanup(["idview-find", "--pkey-only"], ["idview-del"], []);
105+
cleanup(["netgroup-find", "--pkey-only"], ["netgroup-del"], []);
106+
cleanup(["pwpolicy-find", "--pkey-only"], ["pwpolicy-del"], []);
107+
cleanupServices();
108+
cleanup(["stageuser-find", "--pkey-only"], ["stageuser-del"], []);
109+
cleanup(["sudocmd-find", "--pkey-only"], ["sudocmd-del"], []);
110+
cleanup(["sudocmdgroup-find", "--pkey-only"], ["sudocmdgroup-del"], []);
111+
cleanup(["sudorule-find", "--pkey-only"], ["sudorule-del"], []);
112+
cleanup(["trust-find", "--pkey-only"], ["trust-del"], []);
113+
cleanup(["user-find", "--pkey-only"], ["user-del"], ["admin"]);
114+
});

cypress/e2e/common/hbac_rule_management.ts

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,23 @@ import {
44
selectEntry,
55
searchForEntry,
66
entryDoesNotExist,
7-
entryExists,
87
} from "../common/data_tables";
98
import { navigateTo } from "../common/navigation";
10-
import { typeInTextbox } from "../common/ui/textbox";
119

1210
Given("hbac rule {string} exists", (ruleName: string) => {
13-
loginAsAdmin();
14-
navigateTo("hbac-rules");
15-
16-
cy.dataCy("hbac-rules-button-add").click();
17-
cy.dataCy("add-hbac-rule-modal").should("exist");
18-
19-
typeInTextbox("modal-textbox-rule-name", ruleName);
20-
cy.dataCy("modal-textbox-rule-name").should("have.value", ruleName);
21-
22-
cy.dataCy("modal-button-add").click();
23-
cy.dataCy("add-hbac-rule-modal").should("not.exist");
24-
25-
searchForEntry(ruleName);
26-
entryExists(ruleName);
27-
logout();
11+
cy.ipa("hbacrule-show", ruleName, { failOnNonZeroExit: false }).then(
12+
(result) => {
13+
if (result.code !== 0) {
14+
cy.ipa("hbacrule-add", ruleName).then((addResult) => {
15+
if (addResult.code !== 0) {
16+
throw new Error(
17+
`Failed to add HBAC rule ${ruleName} ${addResult.stderr}`
18+
);
19+
}
20+
});
21+
}
22+
}
23+
);
2824
});
2925

3026
Given("I delete hbac rule {string}", (ruleName: string) => {
Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
import { Given } from "@badeball/cypress-cucumber-preprocessor";
22
import { loginAsAdmin, logout } from "./authentication";
3-
import {
4-
selectEntry,
5-
searchForEntry,
6-
entryDoesNotExist,
7-
entryExists,
8-
} from "./data_tables";
3+
import { selectEntry, searchForEntry, entryDoesNotExist } from "./data_tables";
94
import { navigateTo } from "./navigation";
10-
import { typeInTextbox } from "./ui/textbox";
115

126
Given("I delete host {string}", (hostName: string) => {
137
loginAsAdmin();
@@ -26,22 +20,13 @@ Given("I delete host {string}", (hostName: string) => {
2620
});
2721

2822
Given("host {string} exists", (hostName: string) => {
29-
loginAsAdmin();
30-
navigateTo("hosts");
31-
32-
cy.dataCy("hosts-button-add").click();
33-
cy.dataCy("add-host-modal").should("exist");
34-
35-
typeInTextbox("modal-textbox-host-name", hostName);
36-
cy.dataCy("modal-textbox-host-name").should("have.value", hostName);
37-
38-
cy.dataCy("modal-checkbox-force-host").check();
39-
cy.dataCy("modal-checkbox-force-host").should("be.checked");
40-
41-
cy.dataCy("modal-button-add").click();
42-
cy.dataCy("add-host-modal").should("not.exist");
43-
44-
searchForEntry(hostName);
45-
entryExists(hostName);
46-
logout();
23+
cy.ipa("host-show", hostName, { failOnNonZeroExit: false }).then((result) => {
24+
if (result.code !== 0) {
25+
cy.ipa("host-add --force", hostName).then((addResult) => {
26+
if (addResult.code !== 0) {
27+
throw new Error(`Failed to add host ${hostName} ${addResult.stderr}`);
28+
}
29+
});
30+
}
31+
});
4732
});

cypress/e2e/common/sudo_rules_management.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
entryDoesNotExist,
55
searchForEntry,
66
selectEntry,
7-
validateEntry,
87
} from "../common/data_tables";
98
import { navigateTo } from "../common/navigation";
109
import { typeInTextbox } from "../common/ui/textbox";
@@ -21,11 +20,19 @@ export const addSudoRule = (ruleName: string) => {
2120
};
2221

2322
Given("sudo rule {string} exists", (ruleName: string) => {
24-
loginAsAdmin();
25-
navigateTo("sudo-rules");
26-
addSudoRule(ruleName);
27-
validateEntry(ruleName);
28-
logout();
23+
cy.ipa("sudorule-show", ruleName, { failOnNonZeroExit: false }).then(
24+
(result) => {
25+
if (result.code !== 0) {
26+
cy.ipa("sudorule-add", ruleName).then((addResult) => {
27+
if (addResult.code !== 0) {
28+
throw new Error(
29+
`Failed to add sudo rule ${ruleName} ${addResult.stderr}`
30+
);
31+
}
32+
});
33+
}
34+
}
35+
);
2936
});
3037

3138
Given("I delete sudo rule {string}", (ruleName: string) => {

cypress/e2e/dns/dnszones.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,19 @@ Then("I should not see DNS zone {string} in the list", (zoneName: string) => {
172172
});
173173

174174
Given("DNS zone {string} exists", (zoneName: string) => {
175-
loginAsAdmin();
176-
navigateTo("dns-zones");
177-
178-
createDnsZone(zoneName);
179-
180-
searchForEntry(parseZoneName(zoneName));
181-
entryExists(parseZoneName(zoneName));
182-
logout();
175+
cy.ipa("dnszone-show", zoneName, { failOnNonZeroExit: false }).then(
176+
(result) => {
177+
if (result.code !== 0) {
178+
cy.ipa("dnszone-add", zoneName).then((addResult) => {
179+
if (addResult.code !== 0) {
180+
throw new Error(
181+
`Failed to add DNS zone ${zoneName} ${addResult.stderr}`
182+
);
183+
}
184+
});
185+
}
186+
}
187+
);
183188
});
184189

185190
Then(

cypress/e2e/hbac/hbac_service/hbac_service.ts

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,26 @@ import {
77
searchForEntry,
88
selectEntry,
99
} from "../../common/data_tables";
10-
import { typeInTextbox } from "cypress/e2e/common/ui/textbox";
1110
import { addItemToRightList } from "cypress/e2e/common/ui/dual_list";
1211
import {
1312
searchForMembersEntry,
1413
selectMembersEntry,
1514
} from "cypress/e2e/common/members_table";
1615

1716
Given("HBAC service {string} exists", (serviceName: string) => {
18-
loginAsAdmin();
19-
navigateTo("hbac-services");
20-
21-
searchForEntry(serviceName);
22-
cy.dataCy("hbac-services-button-add").click();
23-
cy.dataCy("add-hbac-service-modal").should("exist");
24-
25-
typeInTextbox("modal-textbox-service-name", serviceName);
26-
cy.dataCy("modal-textbox-service-name").should("have.value", serviceName);
27-
28-
cy.dataCy("modal-button-add").click();
29-
cy.dataCy("add-hbac-service-modal").should("not.exist");
30-
cy.dataCy("add-hbacservice-success").should("exist");
31-
32-
searchForEntry(serviceName);
33-
entryExists(serviceName);
34-
35-
logout();
17+
cy.ipa("hbacsvc-show", serviceName, { failOnNonZeroExit: false }).then(
18+
(result) => {
19+
if (result.code !== 0) {
20+
cy.ipa("hbacsvc-add", serviceName).then((result) => {
21+
if (result.code !== 0) {
22+
throw new Error(
23+
`Failed to add HBAC service ${serviceName} ${result.stderr}`
24+
);
25+
}
26+
});
27+
}
28+
}
29+
);
3630
});
3731

3832
Given("I delete service {string}", (serviceName: string) => {

cypress/e2e/hbac/hbac_service_group/hbac_service_group.ts

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,33 +7,26 @@ import {
77
searchForEntry,
88
selectEntry,
99
} from "../../common/data_tables";
10-
import { typeInTextbox } from "../../common/ui/textbox";
1110
import { addItemToRightList } from "cypress/e2e/common/ui/dual_list";
1211
import {
1312
searchForMembersEntry,
1413
selectMembersEntry,
1514
} from "cypress/e2e/common/members_table";
1615

1716
Given("HBAC service group {string} exists", (groupName: string) => {
18-
loginAsAdmin();
19-
navigateTo("hbac-service-groups");
20-
21-
searchForEntry(groupName);
22-
23-
cy.dataCy("hbac-service-groups-button-add").click();
24-
cy.dataCy("add-hbac-service-group-modal").should("exist");
25-
26-
typeInTextbox("modal-textbox-service-group-name", groupName);
27-
cy.dataCy("modal-textbox-service-group-name").should("have.value", groupName);
28-
29-
cy.dataCy("modal-button-add").click();
30-
cy.dataCy("add-hbac-service-group-modal").should("not.exist");
31-
cy.dataCy("add-hbacservicegroup-success").should("exist");
32-
33-
searchForEntry(groupName);
34-
entryExists(groupName);
35-
36-
logout();
17+
cy.ipa("hbacsvcgroup-show", groupName, { failOnNonZeroExit: false }).then(
18+
(result) => {
19+
if (result.code !== 0) {
20+
cy.ipa("hbacsvcgroup-add", groupName).then((addResult) => {
21+
if (addResult.code !== 0) {
22+
throw new Error(
23+
`Failed to add HBAC service group ${groupName} ${addResult.stderr}`
24+
);
25+
}
26+
});
27+
}
28+
}
29+
);
3730
});
3831

3932
Given("I delete service group {string}", (groupName: string) => {

0 commit comments

Comments
 (0)