From 8fed5c588a31fecc046e49db81b8e8d8312813fc Mon Sep 17 00:00:00 2001 From: John McCall Date: Sun, 15 Dec 2024 17:17:46 -0500 Subject: [PATCH] feat: add tests --- tests/integration/targets/login_role/aliases | 2 + .../targets/login_role/meta/main.yml | 3 + .../targets/login_role/tasks/main.yml | 91 +++++++++++++++++++ .../targets/win_login_role/aliases | 5 + .../targets/win_login_role/meta/main.yml | 3 + 5 files changed, 104 insertions(+) create mode 100644 tests/integration/targets/login_role/aliases create mode 100644 tests/integration/targets/login_role/meta/main.yml create mode 100644 tests/integration/targets/login_role/tasks/main.yml create mode 100644 tests/integration/targets/win_login_role/aliases create mode 100644 tests/integration/targets/win_login_role/meta/main.yml diff --git a/tests/integration/targets/login_role/aliases b/tests/integration/targets/login_role/aliases new file mode 100644 index 00000000..4f4b6b91 --- /dev/null +++ b/tests/integration/targets/login_role/aliases @@ -0,0 +1,2 @@ +context/target +setup/once/setup_sqlserver diff --git a/tests/integration/targets/login_role/meta/main.yml b/tests/integration/targets/login_role/meta/main.yml new file mode 100644 index 00000000..a3309752 --- /dev/null +++ b/tests/integration/targets/login_role/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - setup_sqlserver_test_plugins diff --git a/tests/integration/targets/login_role/tasks/main.yml b/tests/integration/targets/login_role/tasks/main.yml new file mode 100644 index 00000000..99820104 --- /dev/null +++ b/tests/integration/targets/login_role/tasks/main.yml @@ -0,0 +1,91 @@ +--- +- name: Var block + vars: + login_name: "PhillipJFry" + plain_password: "P0pS3cret!23$%" + password_expiration_enabled: false + password_policy_enforced: false + password_must_change: false + enabled: false + default_database: "master" + language: "us_english" + default_schema: "dbo" + database: "master" + server_role: "sysadmin" + module_defaults: + lowlydba.sqlserver.login: + sql_instance: "{{ sqlserver_instance }}" + sql_username: "{{ sqlserver_username }}" + sql_password: "{{ sqlserver_password }}" + default_database: "{{ default_database }}" + login: "{{ login_name }}" + password: "{{ plain_password }}" + password_expiration_enabled: "{{ password_expiration_enabled }}" + password_must_change: "{{ password_must_change }}" + enabled: "{{ enabled }}" + language: "{{ language }}" + state: present + lowlydba.sqlserver.login_role: + sql_instance: "{{ sqlserver_instance }}" + sql_username: "{{ sqlserver_username }}" + sql_password: "{{ sqlserver_password }}" + server_role: "{{ database }}" + login: "{{ login_name }}" + state: present + tags: ["sqlserver.user"] + block: + - name: Create login + lowlydba.sqlserver.login: + register: result + - assert: + that: + - result.data != None + + - name: Add login to server role + lowlydba.sqlserver.login_role: + register: result + - assert: + that: + - result is changed + + - name: Add login to non-existent server role + lowlydba.sqlserver.login_role: + server_role: IMadeThisOneUp + register: error_result + failed_when: error_result.failed + ignore_errors: true + - assert: + that: + - error_result.failed == true + - "'Server role [IMadeThisOneUp] does not exist' in error_result.msg" + + - name: Add non-existent login to server role + lowlydba.sqlserver.login_role: + login: NewUserWhoThis + register: error_result + failed_when: error_result.failed + ignore_errors: true + - assert: + that: + - error_result.failed == true + - "'Login [NewUserWhoThis] does not exist' in error_result.msg" + + - name: Add Login again to database role + lowlydba.sqlserver.login_role: + register: result + - assert: + that: + - result is not changed + + - name: Remove login from server role + lowlydba.sqlserver.login_role: + state: "absent" + register: result + - assert: + that: + - result is changed + + always: + - name: Drop login + lowlydba.sqlserver.login: + state: "absent" diff --git a/tests/integration/targets/win_login_role/aliases b/tests/integration/targets/win_login_role/aliases new file mode 100644 index 00000000..06b0f6dd --- /dev/null +++ b/tests/integration/targets/win_login_role/aliases @@ -0,0 +1,5 @@ +windows/all +windows/group/2 +context/target +setup/once/setup_win_sqlserver +needs/target/login_role diff --git a/tests/integration/targets/win_login_role/meta/main.yml b/tests/integration/targets/win_login_role/meta/main.yml new file mode 100644 index 00000000..ca300b30 --- /dev/null +++ b/tests/integration/targets/win_login_role/meta/main.yml @@ -0,0 +1,3 @@ +--- +dependencies: + - login_role