Skip to content

Commit 0c50189

Browse files
committed
Redesigned checks in unit tests
1 parent 47b1f4d commit 0c50189

File tree

1 file changed

+33
-5
lines changed

1 file changed

+33
-5
lines changed

tests/unit/plugins/modules/test_cert_info.py

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,22 @@ def exit_json(*args, **kwargs):
7070

7171
checks_passed = True
7272

73-
# check every item in certificate if it matches with the result
74-
# and if that fails, don't catch the Exception, so the test will fail
75-
for item in certificate:
76-
if certificate[item] != kwargs[item]:
73+
# only if passphrase_check mode is disabled
74+
if args['passphrase_check'] is False:
75+
# check every item in certificate if it matches with the result
76+
# and if that fails, don't catch the Exception, so the test will fail
77+
for item in certificate:
78+
if certificate[item] != kwargs[item]:
79+
checks_passed = False
80+
# if passphrase_check mode is enabled
81+
else:
82+
# fail checks, if passphrase is wrong and passphrase_check kwarg is not False
83+
if args['passphrase'] is 'PleaseChangeMe-Wrong' and kwargs['passphrase_check'] is not False:
7784
checks_passed = False
78-
85+
# fail checks, if passphrase is correct and passphrase_check kwarg is not True
86+
if args['passphrase'] is 'PleaseChangeMe' and kwargs['passphrase_check'] is not True:
87+
checks_passed = False
88+
7989
if checks_passed:
8090
raise AnsibleExitJson(kwargs)
8191

@@ -131,6 +141,24 @@ def test_module_exit_when_path_and_password_correct(self):
131141
})
132142
cert_info.main()
133143

144+
def test_module_exit_when_password_wrong_with_passphrase_check(self):
145+
with self.assertRaises(AnsibleExitJson):
146+
set_module_args({
147+
'path': 'molecule/plugins/files/es-ca/elastic-stack-ca.p12',
148+
'passphrase': 'PleaseChangeMe-Wrong',
149+
'passphrase_check': True
150+
})
151+
cert_info.main()
152+
153+
def test_module_exit_when_password_correct_with_passphrase_check(self):
154+
with self.assertRaises(AnsibleExitJson):
155+
set_module_args({
156+
'path': 'molecule/plugins/files/es-ca/elastic-stack-ca.p12',
157+
'passphrase': 'PleaseChangeMe',
158+
'passphrase_check': True
159+
})
160+
cert_info.main()
161+
134162

135163
if __name__ == '__main__':
136164
unittest.main()

0 commit comments

Comments
 (0)