|
| 1 | +import json |
1 | 2 | import re |
2 | 3 | import time |
3 | 4 |
|
4 | 5 | import pytest |
| 6 | +from pytest import MonkeyPatch |
5 | 7 |
|
6 | 8 | from linodecli.exit_codes import ExitCodes |
7 | 9 | from tests.integration.helpers import ( |
8 | 10 | delete_target_id, |
9 | 11 | exec_failing_test_command, |
10 | 12 | exec_test_command, |
| 13 | + get_random_text, |
11 | 14 | ) |
12 | 15 |
|
13 | 16 | BASE_CMD = ["linode-cli", "firewalls"] |
14 | | -FIREWALL_LABEL = "label-fw-test" + str(int(time.time())) |
| 17 | +FIREWALL_LABEL = "fw-" + get_random_text(5) |
15 | 18 |
|
16 | 19 |
|
17 | 20 | @pytest.fixture |
@@ -253,3 +256,87 @@ def test_update_firewall(test_firewall_id): |
253 | 256 | ) |
254 | 257 |
|
255 | 258 | assert re.search(firewall_id + "," + updated_label + ",enabled", result) |
| 259 | + |
| 260 | + |
| 261 | +@pytest.mark.skip("skip until there is a way to delete default firewall") |
| 262 | +def test_firewall_settings_update_and_list(test_firewall_id): |
| 263 | + for cmd in [ |
| 264 | + BASE_CMD |
| 265 | + + [ |
| 266 | + "firewall-settings-update", |
| 267 | + "--default_firewall_ids.vpc_interfac", |
| 268 | + test_firewall_id, |
| 269 | + "--default_firewall_ids.public_interface", |
| 270 | + test_firewall_id, |
| 271 | + "--default_firewall_ids.nodebalancer", |
| 272 | + test_firewall_id, |
| 273 | + "--default_firewall_ids.linode", |
| 274 | + test_firewall_id, |
| 275 | + "--json", |
| 276 | + ], |
| 277 | + BASE_CMD |
| 278 | + + [ |
| 279 | + "firewall-settings-list", |
| 280 | + "--json", |
| 281 | + ], |
| 282 | + ]: |
| 283 | + data = json.loads(exec_test_command(cmd).stdout.decode().rstrip()) |
| 284 | + firewall_ids = data[0]["default_firewall_ids"] |
| 285 | + for key in [ |
| 286 | + "linode", |
| 287 | + "nodebalancer", |
| 288 | + "public_interface", |
| 289 | + "vpc_interface", |
| 290 | + ]: |
| 291 | + assert firewall_ids[key] == int(test_firewall_id) |
| 292 | + |
| 293 | + |
| 294 | +def test_firewall_templates_list(monkeypatch: MonkeyPatch): |
| 295 | + monkeypatch.setenv("LINODE_CLI_API_VERSION", "v4beta") |
| 296 | + data = json.loads( |
| 297 | + exec_test_command(BASE_CMD + ["templates-list", "--json"]) |
| 298 | + .stdout.decode() |
| 299 | + .rstrip() |
| 300 | + ) |
| 301 | + |
| 302 | + slugs = {template["slug"] for template in data} |
| 303 | + expected_slugs = {"akamai-non-prod", "vpc", "public"} |
| 304 | + assert expected_slugs.issubset(slugs) |
| 305 | + |
| 306 | + for template in data: |
| 307 | + assert "slug" in template |
| 308 | + assert "rules" in template |
| 309 | + rules = template["rules"] |
| 310 | + |
| 311 | + assert "inbound_policy" in rules |
| 312 | + assert "outbound_policy" in rules |
| 313 | + assert isinstance(rules.get("inbound", []), list) |
| 314 | + assert isinstance(rules.get("outbound", []), list) |
| 315 | + |
| 316 | + for rule in rules.get("inbound", []): |
| 317 | + assert "action" in rule |
| 318 | + assert "protocol" in rule |
| 319 | + assert "label" in rule |
| 320 | + assert "addresses" in rule |
| 321 | + |
| 322 | + |
| 323 | +def test_firewall_template_view(monkeypatch: MonkeyPatch): |
| 324 | + monkeypatch.setenv("LINODE_CLI_API_VERSION", "v4beta") |
| 325 | + for slug in ["akamai-non-prod", "vpc", "public"]: |
| 326 | + data = json.loads( |
| 327 | + exec_test_command(BASE_CMD + ["template-view", slug, "--json"]) |
| 328 | + .stdout.decode() |
| 329 | + .rstrip() |
| 330 | + ) |
| 331 | + template = data[0] |
| 332 | + |
| 333 | + assert template["slug"] == slug |
| 334 | + assert "rules" in template |
| 335 | + assert "inbound" in template["rules"] |
| 336 | + assert "outbound" in template["rules"] |
| 337 | + assert "inbound_policy" in template["rules"] |
| 338 | + assert "outbound_policy" in template["rules"] |
| 339 | + assert template["rules"]["inbound_policy"] == "DROP" |
| 340 | + assert template["rules"]["outbound_policy"] == "ACCEPT" |
| 341 | + assert isinstance(template["rules"]["inbound"], list) |
| 342 | + assert isinstance(template["rules"]["outbound"], list) |
0 commit comments