| 1 | import { Given } from "@badeball/cypress-cucumber-preprocessor"; |
| 2 | import { loginAsAdmin, logout } from "../../common/authentication"; |
| 3 | import { |
| 4 | entryDoesNotExist, |
| 5 | entryExists, |
| 6 | checkEntry, |
| 7 | } from "../../common/data_tables"; |
| 8 | import { navigateTo } from "../../common/navigation"; |
| 9 | import { findEntryInTable } from "../../common/settings_table"; |
| 10 | import { addItemToRightList } from "../../common/ui/dual_list"; |
| 11 | |
| 12 | Given( |
| 13 | "I have element {string} named {string} in rule {string}", |
| 14 | (elementType: string, element: string, ruleName: string) => { |
| 15 | loginAsAdmin(); |
| 16 | navigateTo(`hbac-rules/${ruleName}`); |
| 17 | |
| 18 | cy.dataCy(`hbac-rules-tab-settings-tab-${elementType}s`).click(); |
| 19 | cy.dataCy(`hbac-rules-tab-settings-tab-${elementType}s`).should( |
| 20 | "be.visible" |
| 21 | ); |
| 22 | |
| 23 | cy.dataCy(`settings-button-add-${elementType}`).click(); |
| 24 | cy.dataCy("dual-list-modal").should("exist"); |
| 25 | |
| 26 | cy.dataCy("dual-list-search-link").click(); |
| 27 | addItemToRightList(element); |
| 28 | |
| 29 | cy.dataCy("modal-button-add").click(); |
| 30 | cy.dataCy("dual-list-modal").should("not.exist"); |
| 31 | cy.dataCy("add-member-success").should("exist"); |
| 32 | |
| 33 | findEntryInTable(element, elementType); |
| 34 | entryExists(element); |
| 35 | |
| 36 | logout(); |
| 37 | } |
| 38 | ); |
| 39 | |
| 40 | Given( |
| 41 | "I delete element {string} named {string} from rule {string}", |
| 42 | (elementType: string, element: string, ruleName: string) => { |
| 43 | loginAsAdmin(); |
| 44 | navigateTo(`hbac-rules/${ruleName}`); |
| 45 | |
| 46 | cy.dataCy(`hbac-rules-tab-settings-tab-${elementType}s`).click(); |
| 47 | cy.dataCy(`hbac-rules-tab-settings-tab-${elementType}s`).should( |
| 48 | "be.visible" |
| 49 | ); |
| 50 | |
| 51 | findEntryInTable(element, elementType); |
| 52 | entryExists(element); |
| 53 | checkEntry(element); |
| 54 | |
| 55 | cy.dataCy(`settings-button-delete-${elementType}`).click(); |
| 56 | cy.dataCy("remove-hbac-rule-members-modal").should("exist"); |
| 57 | entryExists(element); |
| 58 | |
| 59 | cy.dataCy("modal-button-delete").click(); |
| 60 | cy.dataCy("remove-member-success").should("exist"); |
| 61 | entryDoesNotExist(element); |
| 62 | |
| 63 | logout(); |
| 64 | } |
| 65 | ); |
| 66 | |
| 67 | Given( |
| 68 | "I have host {string} in rule {string}", |
| 69 | (host: string, ruleName: string) => { |
| 70 | const hostFqdn = `${host}.${Cypress.env("HOSTNAME")}`; |
| 71 | |
| 72 | loginAsAdmin(); |
| 73 | navigateTo(`hbac-rules/${ruleName}`); |
| 74 | |
| 75 | cy.dataCy("hbac-rules-tab-settings-tab-hosts").click(); |
| 76 | cy.dataCy("hbac-rules-tab-settings-tab-hosts").should("be.visible"); |
| 77 | |
| 78 | cy.dataCy("settings-button-add-host").click(); |
| 79 | cy.dataCy("dual-list-modal").should("exist"); |
| 80 | |
| 81 | cy.dataCy("dual-list-search-link").click(); |
| 82 | addItemToRightList(hostFqdn); |
| 83 | |
| 84 | cy.dataCy("modal-button-add").click(); |
| 85 | cy.dataCy("dual-list-modal").should("not.exist"); |
| 86 | cy.dataCy("add-member-success").should("exist"); |
| 87 | |
| 88 | findEntryInTable(hostFqdn, "host"); |
| 89 | entryExists(hostFqdn); |
| 90 | logout(); |
| 91 | } |
| 92 | ); |
| 93 | |
| 94 | Given( |
| 95 | "I delete host {string} from rule {string}", |
| 96 | (host: string, ruleName: string) => { |
| 97 | loginAsAdmin(); |
| 98 | navigateTo(`hbac-rules/${ruleName}`); |
| 99 | |
| 100 | const fullHost = host + "." + Cypress.env("HOSTNAME"); |
| 101 | cy.dataCy("hbac-rules-tab-settings-tab-hosts").click(); |
| 102 | cy.dataCy("hbac-rules-tab-settings-tab-hosts").should("be.visible"); |
| 103 | |
| 104 | findEntryInTable(fullHost, "host"); |
| 105 | entryExists(fullHost); |
| 106 | |
| 107 | findEntryInTable(fullHost, "host"); |
| 108 | checkEntry(fullHost); |
| 109 | |
| 110 | cy.dataCy("settings-button-delete-host").click(); |
| 111 | cy.dataCy("remove-hbac-rule-members-modal").should("exist"); |
| 112 | entryExists(fullHost); |
| 113 | |
| 114 | cy.dataCy("modal-button-delete").click(); |
| 115 | cy.dataCy("remove-member-success").should("exist"); |
| 116 | entryDoesNotExist(fullHost); |
| 117 | |
| 118 | logout(); |
| 119 | } |
| 120 | ); |
| 121 | |
| 122 | Given( |
| 123 | "I have service {string} in rule {string}", |
| 124 | (service: string, ruleName: string) => { |
| 125 | loginAsAdmin(); |
| 126 | navigateTo(`hbac-rules/${ruleName}`); |
| 127 | |
| 128 | cy.dataCy("hbac-rules-tab-settings-tab-services").click(); |
| 129 | cy.dataCy("hbac-rules-tab-settings-tab-services").should("be.visible"); |
| 130 | |
| 131 | cy.dataCy("settings-button-add-hbacsvc").click(); |
| 132 | cy.dataCy("dual-list-modal").should("exist"); |
| 133 | |
| 134 | cy.dataCy("dual-list-search-link").click(); |
| 135 | addItemToRightList(service); |
| 136 | |
| 137 | cy.dataCy("modal-button-add").click(); |
| 138 | cy.dataCy("dual-list-modal").should("not.exist"); |
| 139 | cy.dataCy("add-member-success").should("exist"); |
| 140 | |
| 141 | findEntryInTable(service, "hbacsvc"); |
| 142 | entryExists(service); |
| 143 | |
| 144 | logout(); |
| 145 | } |
| 146 | ); |
| 147 | |
| 148 | Given( |
| 149 | "I delete service {string} from rule {string}", |
| 150 | (service: string, ruleName: string) => { |
| 151 | loginAsAdmin(); |
| 152 | navigateTo(`hbac-rules/${ruleName}`); |
| 153 | |
| 154 | cy.dataCy("hbac-rules-tab-settings-tab-services").click(); |
| 155 | cy.dataCy("hbac-rules-tab-settings-tab-services").should("be.visible"); |
| 156 | |
| 157 | findEntryInTable(service, "hbacsvc"); |
| 158 | entryExists(service); |
| 159 | |
| 160 | findEntryInTable(service, "hbacsvc"); |
| 161 | checkEntry(service); |
| 162 | |
| 163 | cy.dataCy("settings-button-delete-hbacsvc").click(); |
| 164 | cy.dataCy("remove-hbac-rule-members-modal").should("exist"); |
| 165 | entryExists(service); |
| 166 | |
| 167 | cy.dataCy("modal-button-delete").click(); |
| 168 | cy.dataCy("remove-member-success").should("exist"); |
| 169 | entryDoesNotExist(service); |
| 170 | |
| 171 | logout(); |
| 172 | } |
| 173 | ); |
| 174 | |
| 175 | Given( |
| 176 | "I have servicegroup {string} in rule {string}", |
| 177 | (svcGroup: string, ruleName: string) => { |
| 178 | loginAsAdmin(); |
| 179 | navigateTo(`hbac-rules/${ruleName}`); |
| 180 | |
| 181 | cy.dataCy("hbac-rules-tab-settings-tab-servicegroups").click(); |
| 182 | cy.dataCy("hbac-rules-tab-settings-tab-servicegroups").should("be.visible"); |
| 183 | |
| 184 | cy.dataCy("settings-button-add-hbacsvcgroup").click(); |
| 185 | cy.dataCy("dual-list-modal").should("exist"); |
| 186 | |
| 187 | cy.dataCy("dual-list-search-link").click(); |
| 188 | addItemToRightList(svcGroup); |
| 189 | |
| 190 | cy.dataCy("modal-button-add").click(); |
| 191 | cy.dataCy("dual-list-modal").should("not.exist"); |
| 192 | cy.dataCy("add-member-success").should("exist"); |
| 193 | |
| 194 | findEntryInTable(svcGroup, "hbacsvcgroup"); |
| 195 | entryExists(svcGroup); |
| 196 | |
| 197 | logout(); |
| 198 | } |
| 199 | ); |
| 200 | |
| 201 | Given( |
| 202 | "I delete servicegroup {string} from rule {string}", |
| 203 | (svcGroup: string, ruleName: string) => { |
| 204 | loginAsAdmin(); |
| 205 | navigateTo(`hbac-rules/${ruleName}`); |
| 206 | |
| 207 | cy.dataCy("hbac-rules-tab-settings-tab-servicegroups").click(); |
| 208 | cy.dataCy("hbac-rules-tab-settings-tab-servicegroups").should("be.visible"); |
| 209 | |
| 210 | findEntryInTable(svcGroup, "hbacsvcgroup"); |
| 211 | entryExists(svcGroup); |
| 212 | |
| 213 | findEntryInTable(svcGroup, "hbacsvcgroup"); |
| 214 | checkEntry(svcGroup); |
| 215 | |
| 216 | cy.dataCy("settings-button-delete-hbacsvcgroup").click(); |
| 217 | cy.dataCy("remove-hbac-rule-members-modal").should("exist"); |
| 218 | entryExists(svcGroup); |
| 219 | |
| 220 | cy.dataCy("modal-button-delete").click(); |
| 221 | cy.dataCy("remove-member-success").should("exist"); |
| 222 | entryDoesNotExist(svcGroup); |
| 223 | |
| 224 | logout(); |
| 225 | } |
| 226 | ); |