| 1 |
#!/usr/bin/python3 -cimport os, sys; os.execv(os.path.dirname(sys.argv[1]) + "/../common/pywrap", sys.argv) |
| 2 |
|
| 3 |
# |
| 4 |
# Copyright (C) 2018 Red Hat, Inc. |
| 5 |
# SPDX-License-Identifier: LGPL-2.1-or-later |
| 6 |
|
| 7 |
|
| 8 |
import time |
| 9 |
|
| 10 |
import netlib |
| 11 |
import testlib |
| 12 |
|
| 13 |
|
| 14 |
def wait_unit_state(machine, unit, state): |
| 15 |
|
| 16 |
def active_state(unit): |
| 17 |
# HACK: don't use `systemctl is-active` here because of |
| 18 |
# https://bugzilla.redhat.com/show_bug.cgi?id=1073481 |
| 19 |
# Also, use `systemctl --value` once that exists everywhere |
| 20 |
line = machine.execute(f"systemctl show -p ActiveState {unit}") |
| 21 |
return line.strip().split("=")[1] |
| 22 |
|
| 23 |
testlib.wait(lambda: active_state(unit) == state, delay=0.2) |
| 24 |
|
| 25 |
|
| 26 |
def get_active_rules(machine): |
| 27 |
active_zones = machine.execute("firewall-cmd --get-active-zones | grep -o '^[[:alnum:]]*'").split() |
| 28 |
active_rules = [] |
| 29 |
for zone in active_zones: |
| 30 |
active_rules += machine.execute(f"firewall-cmd --zone '{zone}' --list-services").split() |
| 31 |
ports = machine.execute(f"firewall-cmd --zone '{zone}' --list-ports").strip() |
| 32 |
if ports: |
| 33 |
active_rules += [ports] |
| 34 |
return active_rules |
| 35 |
|
| 36 |
|
| 37 |
@testlib.skipOstree("no firewalld") |
| 38 |
@testlib.nondestructive |
| 39 |
class TestFirewall(netlib.NetworkCase): |
| 40 |
def setUp(self): |
| 41 |
super().setUp() |
| 42 |
m = self.machine |
| 43 |
self.restore_dir("/etc/firewalld", restart_unit="firewalld") |
| 44 |
|
| 45 |
m.execute("systemctl restart firewalld") |
| 46 |
testlib.wait(lambda: m.execute("firewall-cmd --state")) |
| 47 |
|
| 48 |
self.btn_danger = "pf-m-danger" |
| 49 |
self.btn_primary = "pf-m-primary" |
| 50 |
self.default_zone = "Public zone" |
| 51 |
|
| 52 |
# Arch Linux image has no active zones by default |
| 53 |
if m.image == "arch": |
| 54 |
m.execute("firewall-cmd --zone 'public' --change-interface='eth0'; firewall-cmd --runtime-to-permanent") |
| 55 |
|
| 56 |
def testNetworkingPage(self): |
| 57 |
b = self.browser |
| 58 |
m = self.machine |
| 59 |
|
| 60 |
def get_num_zones(): |
| 61 |
testlib.wait(lambda: m.execute("firewall-cmd --state")) |
| 62 |
return int(m.execute("firewall-cmd --get-active-zones | grep --count '^[a-zA-Z]'").strip()) |
| 63 |
|
| 64 |
self.login_and_go("/network", superuser=False) |
| 65 |
|
| 66 |
active_zones = get_num_zones() |
| 67 |
|
| 68 |
# Zones should be visible as unprivileged user |
| 69 |
self.wait_onoff("#networking-firewall-summary", val=True) |
| 70 |
wait_unit_state(m, "firewalld", "active") |
| 71 |
b.wait_in_text("#networking-firewall-summary", f"{active_zones} active zone") |
| 72 |
m.execute("systemctl stop firewalld") |
| 73 |
b.relogin("/network", superuser=True) |
| 74 |
|
| 75 |
self.wait_onoff("#networking-firewall-summary", val=False) |
| 76 |
self.toggle_onoff("#networking-firewall-summary") |
| 77 |
self.wait_onoff("#networking-firewall-summary", val=True) |
| 78 |
wait_unit_state(m, "firewalld", "active") |
| 79 |
|
| 80 |
active_zones = get_num_zones() |
| 81 |
b.wait_in_text("#networking-firewall-summary", f"{active_zones} active zone") |
| 82 |
|
| 83 |
self.toggle_onoff("#networking-firewall-summary") |
| 84 |
self.wait_onoff("#networking-firewall-summary", val=False) |
| 85 |
wait_unit_state(m, "firewalld", "inactive") |
| 86 |
b.wait_in_text("#networking-firewall-summary", "0 active zones") |
| 87 |
|
| 88 |
# toggle the service from CLI, page should react |
| 89 |
try: |
| 90 |
m.execute("systemctl start firewalld") |
| 91 |
wait_unit_state(m, "firewalld", "active") |
| 92 |
except testlib.Error: |
| 93 |
print("====== firewalld.service =======") |
| 94 |
print(m.execute("systemctl status firewalld")) |
| 95 |
raise |
| 96 |
|
| 97 |
self.wait_onoff("#networking-firewall-summary", val=True) |
| 98 |
try: |
| 99 |
testlib.wait(lambda: get_num_zones() == active_zones) |
| 100 |
b.wait_in_text("#networking-firewall-summary", f"{active_zones} active zone") |
| 101 |
except testlib.Error: |
| 102 |
m.execute("firewall-cmd --get-active-zones >&2") |
| 103 |
raise |
| 104 |
|
| 105 |
try: |
| 106 |
m.execute("systemctl stop firewalld") |
| 107 |
wait_unit_state(m, "firewalld", "inactive") |
| 108 |
except testlib.Error: |
| 109 |
print("====== firewalld.service =======") |
| 110 |
print(m.execute("systemctl status firewalld")) |
| 111 |
raise |
| 112 |
|
| 113 |
self.wait_onoff("#networking-firewall-summary", val=False) |
| 114 |
b.wait_in_text("#networking-firewall-summary", "0 active zones") |
| 115 |
|
| 116 |
b.click("#networking-firewall-link") |
| 117 |
b.enter_page("/network/firewall") |
| 118 |
|
| 119 |
b.click(".pf-v6-c-breadcrumb li:first-of-type") |
| 120 |
|
| 121 |
b.enter_page("/network") |
| 122 |
|
| 123 |
self.allow_journal_messages( |
| 124 |
".*The name org.fedoraproject.FirewallD1 was not provided by any .service files.*", |
| 125 |
".*org.fedoraproject.FirewallD1: .*: GDBus.Error:org.freedesktop.DBus.Error.NoReply.*") |
| 126 |
|
| 127 |
# test missing "pkcheck" binary, in that case fallback to the admin check |
| 128 |
def testPkcheckMissing(self): |
| 129 |
b = self.browser |
| 130 |
m = self.machine |
| 131 |
|
| 132 |
# Path to the "pkcheck" PolicyKit utility |
| 133 |
pkcheck = m.execute("command -v pkcheck").strip() |
| 134 |
# "Hide" pkcheck |
| 135 |
m.execute(f"mount --bind /dev/null '{pkcheck}'") |
| 136 |
|
| 137 |
try: |
| 138 |
# Regular user is not allowed to change the firewall switch |
| 139 |
self.login_and_go("/network", superuser=False) |
| 140 |
b.wait_visible("#networking-firewall-switch:disabled") |
| 141 |
|
| 142 |
# Super user is allowed to change the firewall switch |
| 143 |
b.relogin("/network", superuser=True) |
| 144 |
b.wait_visible("#networking-firewall-switch:not([disabled])") |
| 145 |
finally: |
| 146 |
m.execute(f"umount '{pkcheck}'") |
| 147 |
|
| 148 |
def testFirewallPage(self): |
| 149 |
b = self.browser |
| 150 |
m = self.machine |
| 151 |
|
| 152 |
# Changed in #13686, remove all existing ports before testing |
| 153 |
for port in m.execute("firewall-cmd --zone 'public' --list-ports").split(): |
| 154 |
m.execute(f"firewall-cmd --remove-port='{port}' --zone 'public'") |
| 155 |
m.execute(f"firewall-cmd --permanent --remove-port='{port}' --zone 'public'") |
| 156 |
|
| 157 |
# Zones should be visible as unprivileged user |
| 158 |
self.login_and_go("/network/firewall", superuser=False) |
| 159 |
self.wait_onoff("#firewall-heading-title-group", val=True) |
| 160 |
wait_unit_state(m, "firewalld", "active") |
| 161 |
# Wait until the default zone is listed |
| 162 |
b.wait_in_text("#zones-listing .zone-section[data-id='public']", self.default_zone) |
| 163 |
b.wait_not_present("#add-zone-button") |
| 164 |
# "Add services" button should not be present |
| 165 |
b.wait_not_present(".zone-section[data-id='public'] .add-services-button") |
| 166 |
m.execute("systemctl stop firewalld") |
| 167 |
b.relogin("/network/firewall", superuser=True) |
| 168 |
|
| 169 |
# "Add services" button should not be present |
| 170 |
b.wait_not_present(".add-services-button") |
| 171 |
|
| 172 |
self.wait_onoff("#firewall-heading-title-group", val=False) |
| 173 |
self.toggle_onoff("#firewall-heading-title-group") |
| 174 |
self.wait_onoff("#firewall-heading-title-group", val=True) |
| 175 |
wait_unit_state(m, "firewalld", "active") |
| 176 |
|
| 177 |
# Wait until the default zone is listed |
| 178 |
b.wait_in_text("#zones-listing .zone-section[data-id='public']", self.default_zone) |
| 179 |
|
| 180 |
# "Add services" button should be enabled |
| 181 |
b.wait_visible(".zone-section[data-id='public'] .add-services-button:enabled") |
| 182 |
|
| 183 |
# ensure that pop3 is not enabled (shouldn't be on any of our images), |
| 184 |
# so that we can use it for testing |
| 185 |
b.wait_not_present(".zone-section[data-id='public'] tr[data-row-id='pop3']") |
| 186 |
|
| 187 |
m.execute("firewall-cmd --add-service=pop3") |
| 188 |
b.wait_visible(".zone-section[data-id='public'] tr[data-row-id='pop3']") |
| 189 |
|
| 190 |
# Check that all services are shown. This only works reliably since #12806 |
| 191 |
active_rules = get_active_rules(m) |
| 192 |
b.wait_count(".zone-section table.ct-table tbody", len(active_rules)) |
| 193 |
|
| 194 |
b.click(".zone-section[data-id='public'] tr[data-row-id='pop3'] [data-ouia-component-id='toggle-pop3']") |
| 195 |
b.wait_in_text(".zone-section[data-id='public'] tbody.pf-m-expanded tr.pf-v6-c-table__expandable-row", "Post Office Protocol") |
| 196 |
|
| 197 |
b.click(".zone-section[data-id='public'] tr[data-row-id='pop3'] button.pf-v6-c-menu-toggle") |
| 198 |
b.click(".pf-v6-c-menu__list-item.pf-m-danger button") |
| 199 |
b.wait_not_present(".zone-section[data-id='public'] tr[data-row-id='pop3']") |
| 200 |
self.assertNotIn('pop3', m.execute("firewall-cmd --list-services").split()) |
| 201 |
|
| 202 |
# Test that service without name is shown properly |
| 203 |
m.execute("firewall-cmd --permanent --new-service=empty; firewall-cmd --reload; firewall-cmd --add-service=empty") |
| 204 |
b.wait_visible(".zone-section[data-id='public'] tr[data-row-id='empty']") |
| 205 |
|
| 206 |
m.execute("firewall-cmd --add-port=9998/udp --add-port=9999/udp --add-port=6666/tcp") |
| 207 |
b.wait_in_text(".zone-section[data-id='public'] tr[data-row-id='public-6666-tcp-port']", "6666") |
| 208 |
b.wait_in_text(".zone-section[data-id='public'] tr[data-row-id='public-9998-udp-port']", "9998") |
| 209 |
b.wait_in_text(".zone-section[data-id='public'] tr[data-row-id='public-9999-udp-port']", "9999") |
| 210 |
|
| 211 |
for (port, ptype) in [(6666, "tcp"), (9998, "udp")]: |
| 212 |
row_sel = f".zone-section[data-id='public'] tr[data-row-id='public-{port}-{ptype}-port']" |
| 213 |
b.click(f"{row_sel} button.pf-m-plain") |
| 214 |
b.click(".pf-v6-c-menu__list-item.pf-m-danger button") |
| 215 |
b.wait_not_present(row_sel) |
| 216 |
|
| 217 |
# Also via firewall-cmd |
| 218 |
m.execute("firewall-cmd --remove-port=9999/udp") |
| 219 |
b.wait_not_present(".zone-section[data-id='public'] tr[data-row-id='public-9999-udp-port']") |
| 220 |
|
| 221 |
# switch service off again |
| 222 |
self.toggle_onoff("#firewall-heading-title-group") |
| 223 |
self.wait_onoff("#firewall-heading-title-group", val=False) |
| 224 |
wait_unit_state(m, "firewalld", "inactive") |
| 225 |
# "Add services" button should be hidden again |
| 226 |
b.wait_not_present(".zone-section[data-id='public'] .add-services-button") |
| 227 |
|
| 228 |
def testAddServices(self): |
| 229 |
b = self.browser |
| 230 |
m = self.machine |
| 231 |
|
| 232 |
self.login_and_go("/network/firewall") |
| 233 |
b.wait_in_text("#zones-listing .zone-section[data-id='public']", self.default_zone) |
| 234 |
|
| 235 |
# add a service to the runtime configuration via the cli, after all the |
| 236 |
# operations it should still be there, indicating no reload took place |
| 237 |
m.execute("firewall-cmd --add-service=http") |
| 238 |
b.wait_visible(".zone-section[data-id='public'] tr[data-row-id='http']") |
| 239 |
|
| 240 |
b.assert_pixels("#zones-listing .zone-section[data-id='public']", "firewall-default-zone-card", |
| 241 |
# HACK: medium layout has unstable horizontal width |
| 242 |
skip_layouts=["medium"]) |
| 243 |
|
| 244 |
# click on the "Add services" button |
| 245 |
b.click(".zone-section[data-id='public'] .add-services-button") |
| 246 |
b.wait_visible(".pf-v6-c-modal-box .service-list #firewall-service-pop3") |
| 247 |
|
| 248 |
# check functionality of radio buttons |
| 249 |
b.click("#add-services-dialog input[value='ports']") |
| 250 |
b.wait_not_present("#filter-services-input") |
| 251 |
b.click("#add-services-dialog input[value='services']") |
| 252 |
b.wait_visible("#filter-services-input") |
| 253 |
|
| 254 |
# filter for pop3 |
| 255 |
b.wait_visible(".pf-v6-c-modal-box .service-list #firewall-service-imap") |
| 256 |
b.set_input_text("#filter-services-input", "pop") |
| 257 |
b.wait_not_present(".pf-v6-c-modal-box .service-list #firewall-service-imap") |
| 258 |
b.wait_visible(".pf-v6-c-modal-box .service-list #firewall-service-pop3") |
| 259 |
self.assertIn("TCP: 110", b.text(".pf-v6-c-modal-box .service-list li:first-child .service-ports.tcp")) |
| 260 |
b.wait_not_present(".pf-v6-c-modal-box .service-list li:first-child .service-ports.udp") |
| 261 |
# clear filter |
| 262 |
b.set_input_text("#filter-services-input", "") |
| 263 |
b.wait_visible(".pf-v6-c-modal-box .service-list #firewall-service-imap") |
| 264 |
b.wait_visible(".pf-v6-c-modal-box .service-list #firewall-service-pop3") |
| 265 |
|
| 266 |
# filter for port 110 |
| 267 |
b.wait_visible(".pf-v6-c-modal-box .service-list #firewall-service-imap") |
| 268 |
b.set_input_text("#filter-services-input", "110") |
| 269 |
b.wait_not_present(".pf-v6-c-modal-box .service-list #firewall-service-imap") |
| 270 |
b.wait_visible(".pf-v6-c-modal-box .service-list #firewall-service-pop3") |
| 271 |
self.assertIn("TCP: 110", b.text(".pf-v6-c-modal-box .service-list li:first-child .service-ports.tcp")) |
| 272 |
b.wait_not_present(".pf-v6-c-modal-box .service-list li:first-child .service-ports.udp") |
| 273 |
# clear filter |
| 274 |
b.set_input_text("#filter-services-input", "") |
| 275 |
b.wait_visible(".pf-v6-c-modal-box .service-list #firewall-service-imap") |
| 276 |
b.wait_visible(".pf-v6-c-modal-box .service-list #firewall-service-pop3") |
| 277 |
|
| 278 |
# HACK: the dialog needs some time to set up after resizing |
| 279 |
b.assert_pixels(".pf-v6-c-modal-box", "firewall-add-services-to-zone-modal", wait_delay=3) |
| 280 |
|
| 281 |
# don't select anything in the dialog |
| 282 |
b.wait_visible(f"#add-services-dialog .{self.btn_primary}:disabled") |
| 283 |
b.click("#add-services-dialog footer .btn-cancel") |
| 284 |
b.wait_not_present(".pf-v6-c-modal-box") |
| 285 |
|
| 286 |
def addService(zone, service): |
| 287 |
b.click(f".zone-section[data-id='{zone}'] .add-services-button") |
| 288 |
b.click(f"#add-services-dialog .service-list #firewall-service-{service}") |
| 289 |
b.click(f"#add-services-dialog footer .{self.btn_primary}") |
| 290 |
b.wait_not_present(".pf-v6-c-modal-box") |
| 291 |
b.wait_visible(f".zone-section[data-id='{zone}'] tr[data-row-id='{service}']") |
| 292 |
self.assertIn(service, m.execute(f"firewall-cmd --zone={zone} --list-services")) |
| 293 |
|
| 294 |
# now add pop3 |
| 295 |
addService('public', 'pop3') |
| 296 |
freeipa = "freeipa-4" |
| 297 |
addService("public", freeipa) |
| 298 |
b.click( |
| 299 |
f'.zone-section[data-id="public"] tr[data-row-id="{freeipa}"] [data-ouia-component-id="toggle-{freeipa}"]' |
| 300 |
) |
| 301 |
b.wait_in_text(".zone-section[data-id='public'] tbody.pf-m-expanded .pf-v6-c-table__expandable-row", "Included Services") |
| 302 |
b.click( |
| 303 |
f'.zone-section[data-id="public"] tr[data-row-id="{freeipa}"] [data-ouia-component-id="toggle-{freeipa}"]' |
| 304 |
) |
| 305 |
|
| 306 |
# pop3 should now not appear any more in Add Services dialog |
| 307 |
b.click(".zone-section[data-id='public'] .add-services-button") |
| 308 |
b.wait_visible(".pf-v6-c-modal-box .service-list #firewall-service-imap") |
| 309 |
b.wait_not_present(".pf-v6-c-modal-box .service-list #firewall-service-pop3") |
| 310 |
b.click("#add-services-dialog footer .btn-cancel") |
| 311 |
b.wait_not_present(".pf-v6-c-modal-box") |
| 312 |
|
| 313 |
# should still be here |
| 314 |
b.wait_visible(".zone-section[data-id='public'] tr[data-row-id='http']") |
| 315 |
|
| 316 |
# Service without name should appear in the dialog |
| 317 |
m.execute("firewall-cmd --permanent --new-service=empty; firewall-cmd --reload") |
| 318 |
b.click(".zone-section[data-id='public'] .add-services-button") |
| 319 |
b.wait_visible(".pf-v6-c-modal-box .service-list #firewall-service-empty") |
| 320 |
b.click("#add-services-dialog footer .btn-cancel") |
| 321 |
b.wait_not_present(".pf-v6-c-modal-box") |
| 322 |
|
| 323 |
# remove all services |
| 324 |
services = set(m.execute("firewall-cmd --list-services").strip().split(" ")) |
| 325 |
# some images come with an extra preconfigured libvirt zone so remove all |
| 326 |
# the service which belong to both libvirt and public (and thus |
| 327 |
# requiring checkboxes to be clicked), then remove all the services |
| 328 |
# belonging either libvirt or public |
| 329 |
for service in services: |
| 330 |
b.click(f".zone-section[data-id='public'] tr[data-row-id='{service}'] button.pf-v6-c-menu-toggle") |
| 331 |
b.click(".pf-v6-c-menu__list-item.pf-m-danger button") |
| 332 |
# removing cockpit services requires confirmation |
| 333 |
if service == "cockpit": |
| 334 |
b.click(f"#delete-confirmation-dialog button.{self.btn_danger}") |
| 335 |
b.wait_not_present(f".zone-section[data-id='public'] tr[data-row-id='{service}']") |
| 336 |
self.assertEqual(m.execute("firewall-cmd --list-services").strip(), "") |
| 337 |
|
| 338 |
# Test that we show 'Additional ports' even when no service is present |
| 339 |
m.execute("firewall-cmd --add-port=9998/tcp --zone public") |
| 340 |
b.wait_in_text(".zone-section[data-id='public'] tr[data-row-id='public-9998-tcp-port']", "9998") |
| 341 |
|
| 342 |
# test error handling |
| 343 |
m.execute("firewall-cmd --add-service=pop3") |
| 344 |
b.wait_visible(".zone-section[data-id='public'] tr[data-row-id='pop3']") |
| 345 |
b.wait_in_text(".zone-section[data-id='public'] tr[data-row-id='public-9998-tcp-port']", "9998") |
| 346 |
# remove service in cockpit |
| 347 |
b.click(".zone-section[data-id='public'] tr[data-row-id='pop3'] button.pf-v6-c-menu-toggle") |
| 348 |
b.click(".pf-v6-c-menu__list-item.pf-m-danger button") |
| 349 |
b.wait_not_present(".zone-section[data-id='public'] tr[data-row-id='pop3']") |
| 350 |
|
| 351 |
def testAddCustomServices(self): |
| 352 |
b = self.browser |
| 353 |
m = self.machine |
| 354 |
|
| 355 |
self.login_and_go("/network/firewall") |
| 356 |
b.wait_in_text("#zones-listing .zone-section[data-id='public']", self.default_zone) |
| 357 |
|
| 358 |
# add a service to the runtime configuration via the cli, after all the |
| 359 |
# operations it should be removed, indicating a reload took place |
| 360 |
m.execute("firewall-cmd --add-service=http") |
| 361 |
b.wait_visible("tr[data-row-id='http']") |
| 362 |
|
| 363 |
def open_dialog(): |
| 364 |
b.click(".zone-section[data-id='public'] .add-services-button") |
| 365 |
b.wait_visible("#add-services-dialog input[value='ports']:enabled") |
| 366 |
b.click("#add-services-dialog input[value='ports']") |
| 367 |
b.wait_visible("#tcp-ports") |
| 368 |
b.wait_visible("#tcp-ports") |
| 369 |
|
| 370 |
def set_field(sel, val, expected): |
| 371 |
b.set_input_text(sel, val) |
| 372 |
b.wait_val("#service-name", expected) |
| 373 |
|
| 374 |
def check_error(text): |
| 375 |
b.wait_in_text(".pf-v6-c-form__helper-text .pf-m-error", text) |
| 376 |
|
| 377 |
def save(identifier, tcp, udp, desc="", submit_text="Add ports"): |
| 378 |
b.click(f"button:contains('{submit_text}')") |
| 379 |
b.wait_not_present("#add-services-dialog") |
| 380 |
# expand-togglecustom--80-82-echo-83-123-snmp |
| 381 |
print(identifier) |
| 382 |
# expand-togglefreeipa-4 |
| 383 |
line_sel = f".zone-section[data-id='public'] tr[data-row-id='{identifier}']" |
| 384 |
b.wait_in_text(line_sel, "".join([identifier, tcp, udp])) |
| 385 |
if desc: |
| 386 |
# Click expand button |
| 387 |
b.click(f'{line_sel} [data-ouia-component-id="toggle-{identifier}"]') |
| 388 |
b.wait_text(line_sel + " + tr", desc) |
| 389 |
|
| 390 |
out = m.execute("firewall-cmd --zone public --list-services") |
| 391 |
self.assertIn(identifier, out) |
| 392 |
|
| 393 |
open_dialog() |
| 394 |
set_field("#tcp-ports", "80", "custom--http") |
| 395 |
set_field("#tcp-ports", "", "") |
| 396 |
set_field("#tcp-ports", "80,7", "custom--http-echo") |
| 397 |
set_field("#udp-ports", "123", "custom--http-echo-ntp") |
| 398 |
set_field("#udp-ports", "123, 50000", "custom--http-echo-ntp-50000") |
| 399 |
set_field("#tcp-ports", "", "custom--ntp-50000") |
| 400 |
set_field("#tcp-ports", "https", "custom--https-ntp-50000") |
| 401 |
save("custom--https-ntp-50000", "443", "123, 50000") |
| 402 |
|
| 403 |
open_dialog() |
| 404 |
set_field("#tcp-ports", "80-82", "custom--80-82") |
| 405 |
set_field("#tcp-ports", "80-82, echo", "custom--80-82-echo") |
| 406 |
set_field("#udp-ports", "ntp, snmp", "custom--80-82-echo-ntp-snmp") |
| 407 |
set_field("#udp-ports", "83-ntp", "custom--80-82-echo-83-123") |
| 408 |
set_field("#udp-ports", "83-ntp, snmp", "custom--80-82-echo-83-123-snmp") |
| 409 |
b.set_input_text("#service-description", "custom snmp firewall rule") |
| 410 |
# Test that the service name field is really optional |
| 411 |
b.set_input_text("#service-name", "") |
| 412 |
save("custom--80-82-echo-83-123-snmp", "80-82, 7", "83-123, 161", "custom snmp firewall rule") |
| 413 |
out = m.execute("firewall-cmd --info-service custom--80-82-echo-83-123-snmp") |
| 414 |
self.assertIn("ports: 80-82/tcp 7/tcp 83-123/udp 161/udp", out) |
| 415 |
|
| 416 |
open_dialog() |
| 417 |
set_field("#tcp-ports", "80", "custom--http") |
| 418 |
b.set_input_text("#service-name", "I-am-persistent") |
| 419 |
b.set_input_text("#tcp-ports", "7") |
| 420 |
time.sleep(5) # We need to validate that the service name did not change |
| 421 |
b.wait_val("#service-name", "I-am-persistent") |
| 422 |
save("I-am-persistent", "7", "") |
| 423 |
|
| 424 |
open_dialog() |
| 425 |
set_field("#tcp-ports", "500000", "") |
| 426 |
check_error("Invalid port number") |
| 427 |
set_field("#tcp-ports", "-1", "") |
| 428 |
check_error("Invalid port number") |
| 429 |
set_field("#tcp-ports", "8a", "") |
| 430 |
check_error("Unknown service name") |
| 431 |
set_field("#tcp-ports", "foobar", "") |
| 432 |
check_error("Unknown service name") |
| 433 |
set_field("#tcp-ports", "80-80", "") |
| 434 |
check_error("Range must be strictly ordered") |
| 435 |
set_field("#tcp-ports", "80-79", "") |
| 436 |
check_error("Range must be strictly ordered") |
| 437 |
set_field("#tcp-ports", "https-http", "") |
| 438 |
check_error("Range must be strictly ordered") |
| 439 |
set_field("#tcp-ports", "80-90-", "") |
| 440 |
check_error("Invalid range") |
| 441 |
set_field("#tcp-ports", "80-90-100", "") |
| 442 |
check_error("Invalid range") |
| 443 |
b.click("#add-services-dialog button.btn-cancel") |
| 444 |
|
| 445 |
# test error handling |
| 446 |
# attempt to create custom service which already exists |
| 447 |
m.execute("firewall-cmd --permanent --new-service=custom--19834") |
| 448 |
m.execute("firewall-cmd --permanent --service=custom--19834 --add-port=19834/udp") |
| 449 |
open_dialog() |
| 450 |
set_field("#udp-ports", "19834", "custom--19834") |
| 451 |
b.click(f"#add-services-dialog .{self.btn_primary}") |
| 452 |
b.wait_in_text("#add-services-dialog div.pf-m-danger", "org.fedoraproject.FirewallD1.Exception: NAME_CONFLICT: new_service(): 'custom--19834'") |
| 453 |
b.click("#add-services-dialog button.btn-cancel") |
| 454 |
|
| 455 |
# should have been removed in the reload |
| 456 |
b.wait_not_present("tr[data-row-id='http']") |
| 457 |
|
| 458 |
b.click("tr[data-row-id='custom--80-82-echo-83-123-snmp'] button[aria-label=Details]") |
| 459 |
b.click("tr[data-row-id='custom--80-82-echo-83-123-snmp'] .pf-v6-c-menu-toggle.pf-m-plain") |
| 460 |
b.click("button.pf-v6-c-menu__item:contains('Edit')") |
| 461 |
b.wait_val("#tcp-ports", "80-82, 7") |
| 462 |
b.wait_val("#udp-ports", "83-123, 161") |
| 463 |
b.wait_val("#service-name", "custom--80-82-echo-83-123-snmp") |
| 464 |
b.wait_val("#service-description", "custom snmp firewall rule") |
| 465 |
b.set_input_text("#tcp-ports", "80-82, 8") |
| 466 |
b.set_input_text("#service-description", "edited snmp firewall rule") |
| 467 |
b.wait_val("#service-name", "custom--80-82-echo-83-123-snmp") |
| 468 |
save("custom--80-82-echo-83-123-snmp", "80-82, 8", "83-123, 161", "edited snmp firewall rule", 'Edit service') |
| 469 |
out = m.execute("firewall-cmd --info-service custom--80-82-echo-83-123-snmp") |
| 470 |
self.assertIn("ports: 80-82/tcp 8/tcp 83-123/udp 161/udp", out) |
| 471 |
|
| 472 |
def testMultipleZones(self): |
| 473 |
b = self.browser |
| 474 |
m = self.machine |
| 475 |
|
| 476 |
# create unused interface for adding a new zone |
| 477 |
# FIXME: Firewall page does not pick this up once it's already open |
| 478 |
home_iface = "ethome" |
| 479 |
self.add_veth(home_iface) |
| 480 |
|
| 481 |
def addServiceToZone(service, zone): |
| 482 |
b.click(f".zone-section[data-id='{zone}'] .add-services-button") |
| 483 |
b.click(f"#add-services-dialog .service-list #firewall-service-{service}") |
| 484 |
b.click(f"#add-services-dialog footer .{self.btn_primary}") |
| 485 |
b.wait_not_present(".pf-v6-c-modal-box") |
| 486 |
b.wait_visible(f".zone-section[data-id='{zone}'] tr[data-row-id='{service}']") |
| 487 |
self.assertIn(service, m.execute(f"firewall-cmd --zone={zone} --list-services")) |
| 488 |
|
| 489 |
def addZone(zone, interfaces=None, sources=None, error=None, do_pixel=False): |
| 490 |
if interfaces is None: |
| 491 |
interfaces = [] |
| 492 |
b.click("#add-zone-button") |
| 493 |
b.wait_visible("#add-zone-dialog") |
| 494 |
b.wait_visible(f"#add-zone-dialog footer button.{self.btn_primary}:disabled") |
| 495 |
b.click(f"#add-zone-dialog .add-zone-zones-firewalld input[value='{zone}']") |
| 496 |
|
| 497 |
if do_pixel: |
| 498 |
b.assert_pixels("#add-zone-dialog", "firewall-add-zone-dialog") |
| 499 |
|
| 500 |
for i in interfaces: |
| 501 |
b.click(f"#add-zone-dialog input[value='{i}']") |
| 502 |
if sources: |
| 503 |
b.click("#add-zone-dialog input[value='ip-range']") |
| 504 |
b.set_input_text("#add-zone-dialog #add-zone-ip", sources) |
| 505 |
|
| 506 |
b.click(f"#add-zone-dialog footer button.{self.btn_primary}:enabled") |
| 507 |
|
| 508 |
if error: |
| 509 |
b.wait_in_text("#add-zone-dialog div.pf-m-danger", error) |
| 510 |
b.click("#add-zone-dialog footer button.btn-cancel") |
| 511 |
b.wait_not_present("#add-zone-dialog") |
| 512 |
return |
| 513 |
|
| 514 |
b.wait_not_present("#add-zone-dialog") |
| 515 |
for source in sources.split(",") if sources else []: |
| 516 |
b.wait_in_text(f"#zones-listing .zone-section[data-id='{zone}']", source) |
| 517 |
for i in interfaces: |
| 518 |
b.wait_in_text(f"#zones-listing .zone-section[data-id='{zone}']", i) |
| 519 |
b.wait_visible(f"#zones-listing .zone-section[data-id='{zone}']") |
| 520 |
b.wait_visible(f"#zones-listing .zone-section[data-id='{zone}'] tr[data-row-id='cockpit']") |
| 521 |
|
| 522 |
def removeZone(zone): |
| 523 |
b.click(f".zone-section[data-id='{zone}'] .zone-section-buttons button.pf-v6-c-menu-toggle") |
| 524 |
b.click(".pf-v6-c-menu__list-item.pf-m-danger button") |
| 525 |
b.click(f"#delete-confirmation-dialog button.{self.btn_danger}") |
| 526 |
b.wait_not_present(f".zone-section[data-id='{zone}']") |
| 527 |
|
| 528 |
self.login_and_go("/network/firewall") |
| 529 |
b.wait_in_text("#zones-listing .zone-section[data-id='public']", self.default_zone) |
| 530 |
|
| 531 |
# add predefined work zone |
| 532 |
addZone("work", sources="192.168.1.0/24", do_pixel=True) |
| 533 |
|
| 534 |
addServiceToZone("pop3", "work") |
| 535 |
b.wait_visible(".zone-section[data-id='work'] tr[data-row-id='pop3']") |
| 536 |
self.assertNotIn(self.default_zone.split(" ")[0], b.text("tr[data-row-id='pop3']")) |
| 537 |
addServiceToZone("pop3", "public") |
| 538 |
b.wait_visible(".zone-section[data-id='public'] tr[data-row-id='pop3']") |
| 539 |
|
| 540 |
# Remove the service from public zone |
| 541 |
b.click(".zone-section[data-id='public'] tr[data-row-id='pop3'] [data-ouia-component-id='toggle-pop3']") |
| 542 |
b.click(".zone-section[data-id='public'] tr[data-row-id='pop3'] button.pf-v6-c-menu-toggle") |
| 543 |
b.click(".pf-v6-c-menu__list-item.pf-m-danger button") |
| 544 |
b.wait_not_present(".zone-section[data-id='public'] tr[data-row-id='pop3']") |
| 545 |
b.wait_visible(".zone-section[data-id='work'] tr[data-row-id='pop3']") |
| 546 |
|
| 547 |
# Remove the service from the work zone |
| 548 |
b.click(".zone-section[data-id='work'] tr[data-row-id='pop3'] button.pf-v6-c-menu-toggle") |
| 549 |
b.click(".pf-v6-c-menu__list-item.pf-m-danger button") |
| 550 |
b.wait_not_present(".zone-section[data-id='work'] tr[data-row-id='pop3']") |
| 551 |
|
| 552 |
# remove predefined work zone |
| 553 |
removeZone("work") |
| 554 |
# add zone with previously unused interface |
| 555 |
addZone("home", interfaces=[home_iface]) |
| 556 |
# Interfaces which already belong to an active zone shouldn't show up in |
| 557 |
# the Add Zone dialog anymore |
| 558 |
b.click("#add-zone-button") |
| 559 |
b.wait_visible("#add-zone-dialog") |
| 560 |
b.wait_not_present(f"#add-zone-body input[value='{home_iface}']") |
| 561 |
b.click("#add-zone-dialog footer button.btn-cancel") |
| 562 |
b.wait_not_present("#add-zone-dialog") |
| 563 |
|
| 564 |
addServiceToZone("pop3", "home") |
| 565 |
removeZone("home") |
| 566 |
|
| 567 |
addZone("work", sources="totally invalid address", error="org.fedoraproject.FirewallD1.Exception: INVALID_ADDR: totally invalid address") |
| 568 |
|
| 569 |
|
| 570 |
if __name__ == '__main__': |
| 571 |
testlib.test_main() |