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

Removed check of pw_length #559

Merged
merged 2 commits into from
Feb 15, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 12 additions & 48 deletions plugins/modules/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,6 @@
from ansible_collections.checkmk.general.plugins.module_utils.utils import (
result_as_dict,
)
from ansible_collections.checkmk.general.plugins.module_utils.version import (
CheckmkVersion,
)

USER = (
"username",
Expand Down Expand Up @@ -409,19 +406,6 @@ def needs_editing(self):
return True
return False

def shortpassword(self, data):
ver = self.getversion()
if ver >= CheckmkVersion("2.3.0") and "auth_option" in data:
if (
"password" in data["auth_option"]
and len(data["auth_option"]["password"]) < 12
) or (
"secret" in data["auth_option"]
and len(data["auth_option"]["secret"]) < 10
):
return True
return False

def get(self):
result = self._fetch(
code_mapping=UserHTTPCodes.get,
Expand All @@ -442,44 +426,24 @@ def create(self):
# in the Checkmk API...
data.setdefault("fullname", data["username"])

if self.shortpassword(data):
result = RESULT(
http_code=0,
msg="Password too short. For 2.3 and higher, please provide at least 12 characters (automation min. 10).",
content="",
etag="",
failed=True,
changed=False,
)
else:
result = self._fetch(
code_mapping=UserHTTPCodes.create,
endpoint=UserEndpoints.create,
data=data,
method="POST",
)
result = self._fetch(
code_mapping=UserHTTPCodes.create,
endpoint=UserEndpoints.create,
data=data,
method="POST",
)
return result

def edit(self, etag):
data = self._build_user_data()
self.headers["if-Match"] = etag

if self.shortpassword(data):
result = RESULT(
http_code=0,
msg="Password too short. For 2.3 and higher, please provide at least 12 characters (automation min. 10).",
content="",
etag="",
failed=True,
changed=False,
)
else:
result = self._fetch(
code_mapping=UserHTTPCodes.edit,
endpoint=self._build_default_endpoint(),
data=data,
method="PUT",
)
result = self._fetch(
code_mapping=UserHTTPCodes.edit,
endpoint=self._build_default_endpoint(),
data=data,
method="PUT",
)

return result

Expand Down
38 changes: 0 additions & 38 deletions tests/integration/targets/user/tasks/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -203,44 +203,6 @@
delegate_to: localhost
run_once: true # noqa run-once[task]

- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Test create with short pw for 2.3 (should fail)"
user: # noqa fqcn[action-core] # The FQCN lint makes no sense here, as we want to test our local module
server_url: "{{ checkmk_var_server_url }}"
site: "{{ outer_item.site }}"
automation_user: "{{ checkmk_var_automation_user }}"
automation_secret: "{{ checkmk_var_automation_secret }}"
customer: "{{ (customer != None) | ternary(customer, omit) }}" # See PR #427
name: "autotest"
fullname: "autotest"
auth_type: "automation"
password: "2short"
roles:
- admin
state: "present"
delegate_to: localhost
run_once: true # noqa run-once[task]
when: "'2.3' in outer_item.version"
register: checkmk_shortpwcheck_create
failed_when: "'Password too short. For 2.3 and higher' not in checkmk_shortpwcheck_create.msg"

- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Test reset with short pw for 2.3 (should fail)"
user: # noqa fqcn[action-core] # The FQCN lint makes no sense here, as we want to test our local module
server_url: "{{ checkmk_var_server_url }}"
site: "{{ outer_item.site }}"
automation_user: "{{ checkmk_var_automation_user }}"
automation_secret: "{{ checkmk_var_automation_secret }}"
customer: "{{ (customer != None) | ternary(customer, omit) }}" # See PR #427
name: "{{ item.name }}"
password: "{{ item.password }}"
auth_type: "{{ item.auth_type }}"
state: "reset_password"
delegate_to: localhost
run_once: true # noqa run-once[task]
loop: "{{ checkmk_var_users_new_short_pw }}"
when: "'2.3' in outer_item.version"
register: checkmk_shortpwcheck_edit
failed_when: "'Password too short. For 2.3 and higher' not in checkmk_shortpwcheck_edit.msg"

- name: "{{ outer_item.version }} - {{ outer_item.edition | upper }} - Delete users."
user: # noqa fqcn[action-core] # The FQCN lint makes no sense here, as we want to test our local module
server_url: "{{ checkmk_var_server_url }}"
Expand Down
5 changes: 0 additions & 5 deletions tests/integration/targets/user/vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,6 @@ checkmk_var_users_newpw:
password: "abcdefghij"
auth_type: automation

checkmk_var_users_new_short_pw:
- name: user3
password: "abcdefg"
auth_type: password

checkmk_var_users_edit:
- name: admin1
fullname: Admin Eins
Expand Down
Loading