Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply MissingFilePermissionsRule to get_url module #1949

Merged
merged 4 commits into from
Mar 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 39 additions & 0 deletions src/ansiblelint/rules/MissingFilePermissionsRule.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
"ansible.builtin.copy",
"file",
"ansible.builtin.file",
"get_url",
"ansible.builtin.get_url",
"replace", # implicit preserve behavior but mode: preserve is invalid
"ansible.builtin.replace",
"template", # supports preserve
Expand Down Expand Up @@ -136,6 +138,16 @@ def matchtask(
mode: 0600
"""

SUCCESS_PERMISSIONS_PRESENT_GET_URL = """
- hosts: all
tasks:
- name: permissions not missing and numeric
get_url:
url: http://foo
dest: foo
mode: 0600
"""

SUCCESS_ABSENT_STATE = """
- hosts: all
tasks:
Expand Down Expand Up @@ -235,6 +247,17 @@ def matchtask(
line: some content here
"""

FAIL_MISSING_PERMISSIONS_GET_URL = """
---
- hosts: all
tasks:
- name: permissions missing
# noqa: fqcn-builtins
get_url:
url: http://foo
dest: foo
"""

FAIL_LINEINFILE_CREATE = """
- hosts: all
tasks:
Expand Down Expand Up @@ -293,6 +316,14 @@ def test_success_permissions_present(rule_runner: RunFromText) -> None:
results = rule_runner.run_playbook(SUCCESS_PERMISSIONS_PRESENT)
assert len(results) == 0

@pytest.mark.parametrize(
"rule_runner", (MissingFilePermissionsRule,), indirect=["rule_runner"]
)
def test_success_permissions_present_get_url(rule_runner: RunFromText) -> None:
"""Permissions present and numeric for get_url."""
results = rule_runner.run_playbook(SUCCESS_PERMISSIONS_PRESENT_GET_URL)
assert len(results) == 0

@pytest.mark.parametrize(
"rule_runner", (MissingFilePermissionsRule,), indirect=["rule_runner"]
)
Expand Down Expand Up @@ -365,6 +396,14 @@ def test_fail_missing_permissions_directory(rule_runner: RunFromText) -> None:
results = rule_runner.run_playbook(FAIL_MISSING_PERMISSIONS_DIRECTORY)
assert len(results) == 2

@pytest.mark.parametrize(
"rule_runner", (MissingFilePermissionsRule,), indirect=["rule_runner"]
)
def test_fail_missing_permissions_get_url(rule_runner: RunFromText) -> None:
"""Missing permissions with get_url module."""
results = rule_runner.run_playbook(FAIL_MISSING_PERMISSIONS_GET_URL)
assert len(results) == 1

@pytest.mark.parametrize(
"rule_runner", (MissingFilePermissionsRule,), indirect=["rule_runner"]
)
Expand Down
2 changes: 2 additions & 0 deletions test/TestSkipInsideYaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@

- name: test YAML and var-spacing
ansible.builtin.get_url:
# noqa: risky-file-permissions
url: http://example.com/really_long_path/really_long_path/really_long_path/really_long_path/really_long_path/really_long_path/really_long_path/really_long_path/file.conf
dest: "{{dest_proj_path}}/foo.conf"
- name: test YAML and var-spacing (skipped)
ansible.builtin.get_url:
# noqa: risky-file-permissions
url: http://example.com/really_long_path/really_long_path/really_long_path/really_long_path/really_long_path/really_long_path/really_long_path/really_long_path/file.conf # noqa yaml
dest: "{{dest_proj_path}}/foo.conf" # noqa var-spacing

Expand Down