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

First Draft of the User Module #42

Merged
merged 47 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
5e2890c
updated tests
KiLLuuuhh Apr 12, 2024
c0cffc8
applied suggestions from @rekup
KiLLuuuhh Apr 12, 2024
6b430db
applied suggestions from @rekup
KiLLuuuhh Apr 12, 2024
095f5b8
applied suggestions from @rekup
KiLLuuuhh Apr 12, 2024
8c10207
applied suggestions from @rekup
KiLLuuuhh Apr 12, 2024
149f0d4
applied suggestions from @rekup
KiLLuuuhh Apr 12, 2024
3ff4581
applied suggestions from @rekup
KiLLuuuhh Apr 12, 2024
8e55170
applied suggestions from @rekup
KiLLuuuhh Apr 12, 2024
70396bf
applied suggestions from @rekup
KiLLuuuhh Apr 12, 2024
edf3bda
applied suggestions from @rekup (introduced salted secrets)
KiLLuuuhh Apr 12, 2024
07fe3cb
ensured correct error handling as @rekup suggested
KiLLuuuhh Apr 15, 2024
ab868b3
ensured correct error handling as @rekup suggested
KiLLuuuhh Apr 15, 2024
07ce948
excluded tests from pylint
KiLLuuuhh Apr 15, 2024
13037e1
fixed linter error
KiLLuuuhh Apr 15, 2024
4f1f6a1
fixed last linter erros
KiLLuuuhh Apr 15, 2024
737e6c4
added pylinter exception for crypt since this library is used in the …
KiLLuuuhh Apr 15, 2024
7f20b61
reformted code
KiLLuuuhh Apr 15, 2024
6ecd52b
updated docstring methods
KiLLuuuhh Apr 15, 2024
ea1e357
updated default value for shell
KiLLuuuhh Apr 15, 2024
849900e
ran black
KiLLuuuhh Apr 15, 2024
5ebde03
changed default shell to /sbin/nologin
KiLLuuuhh Apr 15, 2024
6bfa3eb
added fully qualifed names to the converge file
KiLLuuuhh Apr 15, 2024
3585d8d
updated error handling
KiLLuuuhh Apr 15, 2024
4ae1f21
fixed argument
KiLLuuuhh Apr 15, 2024
b3991dc
Update plugins/module_utils/system_access_users_utils.py
KiLLuuuhh Apr 15, 2024
8d8319d
black errors
KiLLuuuhh Apr 15, 2024
2e0e6a2
fixed typo
KiLLuuuhh Apr 15, 2024
81f33a5
reformat
KiLLuuuhh Apr 15, 2024
60a8909
initial version of the system_settings_logging module (#61)
rekup Apr 15, 2024
b6036ad
fixed module_index
KiLLuuuhh Apr 15, 2024
ba6ccfa
fixed module_index
KiLLuuuhh Apr 15, 2024
77ecae1
added 2.15 sanity ignore
KiLLuuuhh Apr 16, 2024
95c34d0
added 2.16 sanity ignore
KiLLuuuhh Apr 16, 2024
33e7c2e
added devel sanity ignore
KiLLuuuhh Apr 16, 2024
4a8b825
updated devel test
KiLLuuuhh Apr 16, 2024
1e6b242
updated devel test python versions
KiLLuuuhh Apr 16, 2024
6dfd6dc
removed sanity ignores
KiLLuuuhh Apr 16, 2024
337f414
added debug.msg to return apikeys if created
KiLLuuuhh Apr 16, 2024
2d66cf3
refactored hash_secret creation
KiLLuuuhh Apr 16, 2024
da43382
added unhashed secret to result
KiLLuuuhh Apr 16, 2024
4a9a3bf
ran black
KiLLuuuhh Apr 16, 2024
4e34cc4
impemented hash function
KiLLuuuhh Apr 16, 2024
e473425
removed unused function
KiLLuuuhh Apr 16, 2024
57c4b8a
removed unused function
KiLLuuuhh Apr 16, 2024
a25fbb8
added some validation and error handling to _generate_hashed_secret
KiLLuuuhh Apr 17, 2024
0efa717
refactored error
KiLLuuuhh Apr 17, 2024
c583ef7
added three tests to confirm functionality of _generate_hashed_secret
KiLLuuuhh Apr 17, 2024
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
209 changes: 209 additions & 0 deletions molecule/system_access_users/converge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
---
- name: converge
hosts: all
become: true
tasks:
- name: "test"
ansible.builtin.debug:
msg: "test"

# Test User minimum requirements
- name: "Test User 1: Test minimum requirements User Creation"
puzzle.opnsense.system_access_users:
username: test_user_1
password: test_password_1

# Test User minimum requirements disabled
- name: "Test User 2: Test disabled User Creation"
puzzle.opnsense.system_access_users:
username: test_user_2
password: test_password_2
full_name: "Test User 2: Test disabled User Creation"
disabled: True

# Test User with Full Name
- name: "Test User 3: Test User Creation with Full Name"
puzzle.opnsense.system_access_users:
username: test_user_3
password: test_password_3
full_name: "Test User 3: Test User Creation with Full Name"

# Test User with E-Mail
- name: "Test User 4: Test User Creation with E-Mail"
puzzle.opnsense.system_access_users:
username: test_user_4
password: test_password_4
email: [email protected]
full_name: "Test User 4: Test User Creation with E-Mail"

# Test User with Comment
- name: "Test User 5: Test User Creation with Comment"
puzzle.opnsense.system_access_users:
username: test_user_5
password: test_password_5
comment: Test User 5 Comment
full_name: "Test User 5: Test User Creation with Comment"

# Test User with Preferred landing page
- name: "Test User 6: Test User Creation with Preferred landing page"
puzzle.opnsense.system_access_users:
username: test_user_6
password: test_password_6
landing_page: /ui/ipsec/sessions
full_name: "Test User 6: Test User Creation with Preferred landing page"

# Test User with nologin shell
- name: "Test User 7: Test User Creation with nologin shell"
puzzle.opnsense.system_access_users:
username: test_user_7
password: test_password_7
shell: /sbin/nologin
full_name: "Test User 7: Test User Creation with nologin shell"

# Test User with csh shell
- name: "Test User 8: Test User Creation with csh shell"
puzzle.opnsense.system_access_users:
username: test_user_8
password: test_password_8
shell: /bin/csh
full_name: "Test User 8: Test User Creation with csh shell"

# Test User with sh shell
- name: "Test User 9: Test User Creation with sh shell"
puzzle.opnsense.system_access_users:
username: test_user_9
password: test_password_9
shell: /bin/sh
full_name: "Test User 9: Test User Creation with sh shell"

# Test User with tcsh shell
- name: "Test User 10: Test User Creation with tcsh shell"
puzzle.opnsense.system_access_users:
username: test_user_10
password: test_password_10
shell: /bin/tcsh
full_name: "Test User 10: Test User Creation with tcsh shell"

# Test User with Expiration date
- name: "Test User 11: Test User Creation with Expiration date"
puzzle.opnsense.system_access_users:
username: test_user_11
password: test_password_11
expires: 02/27/2024
full_name: "Test User 11: Test User Creation with Expiration date"

# Test User with group as string
- name: "Test User 12: Test User Creation with group as string"
puzzle.opnsense.system_access_users:
username: test_user_12
password: test_password_12
full_name: "Test User 12: Test User Creation with group as string"
groups: admins

# Test User with group as list
- name: "Test User 13: Test User Creation with group as list"
puzzle.opnsense.system_access_users:
username: test_user_13
password: test_password_13
full_name: "Test User 13: Test User Creation with group as list"
groups:
- admins

# Test User with not existing group as list
- name: "Test User 14: Test User Creation with not existing group as list"
puzzle.opnsense.system_access_users:
username: test_user_14
password: test_password_14
full_name: "Test User 14: Test User Creation with not existing group as list"
groups:
- test
register: test_user_14_result
ignore_errors: yes

- name: "Verify that the user creation failed due to non-existing group"
ansible.builtin.assert:
that:
- test_user_14_result is failed
fail_msg: "User creation should fail due to non-existing group"
success_msg: "User creation failed as expected due to non-existing group"

# Test User with empty otp_seed
- name: "Test User 15: Test User Creation with empty otp_seed"
puzzle.opnsense.system_access_users:
username: test_user_15
password: test_password_15
otp_seed: ""
full_name: "Test User 15: Test User Creation with empty otp_seed"

# Test User with otp_seed
- name: "Test User 16: Test User Creation with otp_seed"
puzzle.opnsense.system_access_users:
username: test_user_16
password: test_password_16
otp_seed: test_seed
full_name: "Test User 16: Test User Creation with otp_seed"

# Test User with empty authorizedkeys
- name: "Test User 17: Test User Creation with empty authorizedkeys"
puzzle.opnsense.system_access_users:
username: test_user_17
password: test_password_17
authorizedkeys: ""
full_name: "Test User 17: Test User Creation with empty authorizedkeys"

# Test User with authorizedkeys
- name: "Test User 18: Test User Creation with authorizedkeys"
puzzle.opnsense.system_access_users:
username: test_user_18
password: test_password_18
authorizedkeys: test_authorized_key
full_name: "Test User 18: Test User Creation with authorizedkeys"

# Test User with empty api_keys
- name: "Test User 19: Test User Creation with empty api_keys"
puzzle.opnsense.system_access_users:
username: test_user_19
password: test_password_19
apikeys: ""
full_name: "Test User 19: Test User Creation with empty api_keys"
register: api_keys_result

- name: Return the created apikeys and secret of Test User 19
ansible.builtin.debug:
msg: "The following api_keys were created {{ api_keys_result.generated_apikeys }}"
when:
- "'generated_apikeys' in api_keys_result"
- api_keys_result.generated_apikeys | length > 0

# Test User with too short api_keys
- name: "Test User 20: Test User Creation with too short api_keys"
puzzle.opnsense.system_access_users:
username: test_user_20
password: test_password_20
apikeys: "TEST_API_KEY"
full_name: "Test User 20: Test User Creation with too short api_keys"
register: test_user_20_result
ignore_errors: yes

- name: "Verify that the user creation failed due to too short api key"
ansible.builtin.assert:
that:
- test_user_20_result is failed
fail_msg: "The API key: TEST_API_KEY is not a valid string. Must be >= 80 characters."
success_msg: "The API key: TEST_API_KEY is not a valid string. Must be >= 80 characters."

# Test User with valid api_keys
- name: "Test User 21: Test User Creation with valid api_keys"
puzzle.opnsense.system_access_users:
username: test_user_21
password: test_password_21
apikeys: "TEST_API_KEY_WITH_RANDOM_CHARS_UNTIL_80_zo5Y3bUpOQFfbQnAOB6GqbHsPAP9Jqbjofnqu9xc"
full_name: "Test User 21: Test User Creation with valid api_keys"
register: api_keys_result

- name: Return the created apikeys and secret of Test User 21
ansible.builtin.debug:
msg: "The following api_keys were created {{ api_keys_result.generated_apikeys }}"
when:
- "'generated_apikeys' in api_keys_result"
- api_keys_result.generated_apikeys | length > 0
69 changes: 69 additions & 0 deletions molecule/system_access_users/molecule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
---
scenario:
name: system_access_users
test_sequence:
# - dependency not relevant unless we have requirements
- destroy
- syntax
- create
# - prepare
- converge
- idempotence
#- verify
- cleanup
- destroy

driver:
name: vagrant
parallel: true

platforms:
- name: "22.7"
hostname: false
box: puzzle/opnsense
box_version: "22.7"
memory: 1024
cpus: 2
instance_raw_config_args:
- 'vm.guest = :freebsd'
- 'ssh.sudo_command = "%c"'
- 'ssh.shell = "/bin/sh"'
- name: "23.1"
box: puzzle/opnsense
hostname: false
box_version: "23.1"
memory: 1024
cpus: 2
instance_raw_config_args:
- 'vm.guest = :freebsd'
- 'ssh.sudo_command = "%c"'
- 'ssh.shell = "/bin/sh"'
- name: "23.7"
box: puzzle/opnsense
hostname: false
box_version: "23.7"
memory: 1024
cpus: 2
instance_raw_config_args:
- 'vm.guest = :freebsd'
- 'ssh.sudo_command = "%c"'
- 'ssh.shell = "/bin/sh"'
- name: "24.1"
box: puzzle/opnsense
hostname: false
box_version: "24.1"
memory: 1024
cpus: 2
instance_raw_config_args:
- 'vm.guest = :freebsd'
- 'ssh.sudo_command = "%c"'
- 'ssh.shell = "/bin/sh"'

provisioner:
name: ansible
# env:
# ANSIBLE_VERBOSITY: 3
verifier:
name: ansible
options:
become: true
6 changes: 6 additions & 0 deletions molecule/system_access_users/verify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
- name: Verify connectivity to server
hosts: all
tasks:
- name: Ping the server
ansible.builtin.ping:
Loading