| 1 |
|
| 2 |
|
| 3 |
from __future__ import absolute_import, division, print_function |
| 4 |
__metaclass__ = type |
| 5 |
from contextlib import contextmanager |
| 6 |
from ansible.module_utils.testing import patch_module_args |
| 7 |
from ansible_collections.netapp_eseries.santricity.plugins.modules.na_santricity_auth import NetAppESeriesAuth |
| 8 |
from ansible_collections.community.internal_test_tools.tests.unit.plugins.modules.utils import ( |
| 9 |
AnsibleFailJson, AnsibleExitJson, ModuleTestCase |
| 10 |
) |
| 11 |
from ansible_collections.community.internal_test_tools.tests.unit.compat import mock |
| 12 |
|
| 13 |
|
| 14 |
class AuthTest(ModuleTestCase): |
| 15 |
REQUIRED_PARAMS = {"api_username": "admin", "api_password": "password", "api_url": "http://localhost", "ssid": "1"} |
| 16 |
REQ_FUNC = "ansible_collections.netapp_eseries.santricity.plugins.modules.na_santricity_auth.NetAppESeriesAuth.request" |
| 17 |
SLEEP_FUNC = "ansible_collections.netapp_eseries.santricity.plugins.modules.na_santricity_auth.sleep" |
| 18 |
|
| 19 |
@contextmanager |
| 20 |
def _set_args(self, args=None): |
| 21 |
module_args = self.REQUIRED_PARAMS.copy() |
| 22 |
if args is not None: |
| 23 |
module_args.update(args) |
| 24 |
with patch_module_args(module_args): |
| 25 |
yield |
| 26 |
|
| 27 |
def test_minimum_password_length_change_required_pass(self): |
| 28 |
"""Verify minimum_password_length_change_required returns expected values.""" |
| 29 |
with self._set_args({"ssid": "Proxy", "user": "admin", "password": "adminpass", "minimum_password_length": 8}): |
| 30 |
auth = NetAppESeriesAuth() |
| 31 |
auth.is_proxy = lambda: True |
| 32 |
auth.is_embedded_available = lambda: False |
| 33 |
with mock.patch(self.REQ_FUNC, return_value=(200, {"adminPasswordSet": False, "minimumPasswordLength": 8})): |
| 34 |
self.assertFalse(auth.minimum_password_length_change_required()) |
| 35 |
|
| 36 |
with self._set_args({"ssid": "Proxy", "user": "admin", "password": "adminpass", "minimum_password_length": 7}): |
| 37 |
auth = NetAppESeriesAuth() |
| 38 |
auth.is_proxy = lambda: True |
| 39 |
auth.is_embedded_available = lambda: False |
| 40 |
with mock.patch(self.REQ_FUNC, return_value=(200, {"adminPasswordSet": False, "minimumPasswordLength": 8})): |
| 41 |
self.assertTrue(auth.minimum_password_length_change_required()) |
| 42 |
|
| 43 |
with self._set_args({"ssid": "10", "user": "admin", "password": "adminpass", "minimum_password_length": 8}): |
| 44 |
auth = NetAppESeriesAuth() |
| 45 |
auth.is_proxy = lambda: True |
| 46 |
auth.is_embedded_available = lambda: False |
| 47 |
with mock.patch(self.REQ_FUNC, return_value=(200, {"adminPasswordSet": False, "minimumPasswordLength": 8})): |
| 48 |
self.assertFalse(auth.minimum_password_length_change_required()) |
| 49 |
|
| 50 |
with self._set_args({"ssid": "10", "user": "admin", "password": "adminpass", "minimum_password_length": 8}): |
| 51 |
auth = NetAppESeriesAuth() |
| 52 |
auth.is_proxy = lambda: True |
| 53 |
auth.is_embedded_available = lambda: True |
| 54 |
with mock.patch(self.REQ_FUNC, return_value=(200, {"adminPasswordSet": False, "minimumPasswordLength": 8})): |
| 55 |
self.assertFalse(auth.minimum_password_length_change_required()) |
| 56 |
|
| 57 |
with self._set_args({"ssid": "10", "user": "admin", "password": "adminpass", "minimum_password_length": 7}): |
| 58 |
auth = NetAppESeriesAuth() |
| 59 |
auth.is_proxy = lambda: True |
| 60 |
auth.is_embedded_available = lambda: True |
| 61 |
with mock.patch(self.REQ_FUNC, return_value=(200, {"adminPasswordSet": False, "minimumPasswordLength": 8})): |
| 62 |
self.assertTrue(auth.minimum_password_length_change_required()) |
| 63 |
|
| 64 |
with self._set_args({"ssid": "1", "user": "admin", "password": "adminpass", "minimum_password_length": 8}): |
| 65 |
auth = NetAppESeriesAuth() |
| 66 |
auth.is_proxy = lambda: False |
| 67 |
auth.is_embedded_available = lambda: True |
| 68 |
with mock.patch(self.REQ_FUNC, return_value=(200, {"adminPasswordSet": False, "minimumPasswordLength": 8})): |
| 69 |
self.assertFalse(auth.minimum_password_length_change_required()) |
| 70 |
|
| 71 |
with self._set_args({"ssid": "1", "user": "admin", "password": "adminpass", "minimum_password_length": 7}): |
| 72 |
auth = NetAppESeriesAuth() |
| 73 |
auth.is_proxy = lambda: False |
| 74 |
auth.is_embedded_available = lambda: True |
| 75 |
with mock.patch(self.REQ_FUNC, return_value=(200, {"adminPasswordSet": False, "minimumPasswordLength": 8})): |
| 76 |
self.assertTrue(auth.minimum_password_length_change_required()) |
| 77 |
|
| 78 |
def test_minimum_password_length_change_required_fail(self): |
| 79 |
"""Verify minimum_password_length_change_required throws expected exceptions.""" |
| 80 |
with self._set_args({"ssid": "Proxy", "user": "admin", "password": "adminpass", "minimum_password_length": 10}): |
| 81 |
auth = NetAppESeriesAuth() |
| 82 |
auth.is_proxy = lambda: False |
| 83 |
with self.assertRaisesRegex(AnsibleFailJson, "Password does not meet the length requirement"): |
| 84 |
with mock.patch(self.REQ_FUNC, return_value=(200, {"adminPasswordSet": False, "minimumPasswordLength": 8})): |
| 85 |
auth.minimum_password_length_change_required() |
| 86 |
|
| 87 |
with self._set_args({"ssid": "Proxy", "user": "admin", "password": "adminpass"}): |
| 88 |
auth = NetAppESeriesAuth() |
| 89 |
auth.is_proxy = lambda: False |
| 90 |
with self.assertRaisesRegex(AnsibleFailJson, "Password does not meet the length requirement"): |
| 91 |
with mock.patch(self.REQ_FUNC, return_value=(200, {"adminPasswordSet": True, "minimumPasswordLength": 10})): |
| 92 |
auth.minimum_password_length_change_required() |
| 93 |
|
| 94 |
def test_update_minimum_password_length_pass(self): |
| 95 |
"""Verify update_minimum_password_length returns expected values.""" |
| 96 |
with self._set_args({"ssid": "Proxy", "user": "admin", "password": "adminpass", "minimum_password_length": 8}): |
| 97 |
auth = NetAppESeriesAuth() |
| 98 |
auth.is_proxy = lambda: True |
| 99 |
auth.is_embedded_available = lambda: False |
| 100 |
auth.is_admin_password_set = True |
| 101 |
with mock.patch(self.REQ_FUNC, return_value=(200, None)): |
| 102 |
auth.update_minimum_password_length() |
| 103 |
|
| 104 |
with self._set_args({"ssid": "Proxy", "user": "admin", "password": "adminpass", "minimum_password_length": 8}): |
| 105 |
auth = NetAppESeriesAuth() |
| 106 |
auth.is_proxy = lambda: True |
| 107 |
auth.is_embedded_available = lambda: False |
| 108 |
auth.is_admin_password_set = False |
| 109 |
with mock.patch(self.REQ_FUNC, return_value=(200, None)): |
| 110 |
auth.update_minimum_password_length() |
| 111 |
|
| 112 |
with self._set_args({"ssid": "Proxy", "user": "admin", "password": "adminpass", "minimum_password_length": 8}): |
| 113 |
auth = NetAppESeriesAuth() |
| 114 |
auth.is_proxy = lambda: True |
| 115 |
auth.is_embedded_available = lambda: False |
| 116 |
auth.is_admin_password_set = False |
| 117 |
with mock.patch(self.REQ_FUNC, side_effect=[Exception(), (200, None)]): |
| 118 |
auth.update_minimum_password_length() |
| 119 |
|
| 120 |
with self._set_args({"ssid": "10", "user": "admin", "password": "adminpass", "minimum_password_length": 8}): |
| 121 |
auth = NetAppESeriesAuth() |
| 122 |
auth.is_proxy = lambda: True |
| 123 |
auth.is_embedded_available = lambda: True |
| 124 |
auth.is_admin_password_set = True |
| 125 |
with mock.patch(self.REQ_FUNC, return_value=(200, None)): |
| 126 |
auth.update_minimum_password_length() |
| 127 |
|
| 128 |
with self._set_args({"ssid": "10", "user": "admin", "password": "adminpass", "minimum_password_length": 8}): |
| 129 |
auth = NetAppESeriesAuth() |
| 130 |
auth.is_proxy = lambda: True |
| 131 |
auth.is_embedded_available = lambda: True |
| 132 |
auth.is_admin_password_set = False |
| 133 |
with mock.patch(self.REQ_FUNC, return_value=(200, None)): |
| 134 |
auth.update_minimum_password_length() |
| 135 |
|
| 136 |
with self._set_args({"ssid": "1", "user": "admin", "password": "adminpass", "minimum_password_length": 8}): |
| 137 |
auth = NetAppESeriesAuth() |
| 138 |
auth.is_proxy = lambda: False |
| 139 |
auth.is_embedded_available = lambda: True |
| 140 |
auth.is_admin_password_set = True |
| 141 |
with mock.patch(self.REQ_FUNC, return_value=(200, None)): |
| 142 |
auth.update_minimum_password_length() |
| 143 |
|
| 144 |
with self._set_args({"ssid": "1", "user": "admin", "password": "adminpass", "minimum_password_length": 8}): |
| 145 |
auth = NetAppESeriesAuth() |
| 146 |
auth.is_proxy = lambda: False |
| 147 |
auth.is_embedded_available = lambda: True |
| 148 |
auth.is_admin_password_set = False |
| 149 |
with mock.patch(self.REQ_FUNC, return_value=(200, None)): |
| 150 |
auth.update_minimum_password_length() |
| 151 |
|
| 152 |
def test_update_minimum_password_length_fail(self): |
| 153 |
"""Verify update_minimum_password_length throws expected exceptions.""" |
| 154 |
with self._set_args({"ssid": "Proxy", "user": "admin", "password": "adminpass", "minimum_password_length": 8}): |
| 155 |
auth = NetAppESeriesAuth() |
| 156 |
auth.is_proxy = lambda: True |
| 157 |
auth.is_embedded_available = lambda: False |
| 158 |
auth.is_admin_password_set = False |
| 159 |
with self.assertRaisesRegex(AnsibleFailJson, "Failed to set minimum password length."): |
| 160 |
with mock.patch(self.REQ_FUNC, return_value=Exception()): |
| 161 |
auth.update_minimum_password_length() |
| 162 |
|
| 163 |
with self._set_args({"ssid": "10", "user": "admin", "password": "adminpass", "minimum_password_length": 8}): |
| 164 |
auth = NetAppESeriesAuth() |
| 165 |
auth.is_proxy = lambda: True |
| 166 |
auth.is_embedded_available = lambda: True |
| 167 |
auth.is_admin_password_set = False |
| 168 |
with self.assertRaisesRegex(AnsibleFailJson, "Failed to set minimum password length."): |
| 169 |
with mock.patch(self.REQ_FUNC, return_value=Exception()): |
| 170 |
auth.update_minimum_password_length() |
| 171 |
|
| 172 |
with self._set_args({"ssid": "1", "user": "admin", "password": "adminpass", "minimum_password_length": 8}): |
| 173 |
auth = NetAppESeriesAuth() |
| 174 |
auth.is_proxy = lambda: False |
| 175 |
auth.is_embedded_available = lambda: True |
| 176 |
auth.is_admin_password_set = False |
| 177 |
with self.assertRaisesRegex(AnsibleFailJson, "Failed to set minimum password length."): |
| 178 |
with mock.patch(self.REQ_FUNC, return_value=Exception()): |
| 179 |
auth.update_minimum_password_length() |
| 180 |
|
| 181 |
def test_logout_system_pass(self): |
| 182 |
"""Verify logout_system returns expected values.""" |
| 183 |
with self._set_args({"ssid": "Proxy", "user": "admin", "password": "adminpass", "minimum_password_length": 8}): |
| 184 |
auth = NetAppESeriesAuth() |
| 185 |
auth.is_proxy = lambda: True |
| 186 |
auth.is_embedded_available = lambda: False |
| 187 |
with mock.patch(self.REQ_FUNC, return_value=(204, None)): |
| 188 |
auth.logout_system() |
| 189 |
with self._set_args({"ssid": "10", "user": "admin", "password": "adminpass", "minimum_password_length": 8}): |
| 190 |
auth = NetAppESeriesAuth() |
| 191 |
auth.is_proxy = lambda: True |
| 192 |
auth.is_embedded_available = lambda: False |
| 193 |
with mock.patch(self.REQ_FUNC, return_value=(204, None)): |
| 194 |
auth.logout_system() |
| 195 |
with self._set_args({"ssid": "Proxy", "user": "admin", "password": "adminpass", "minimum_password_length": 8}): |
| 196 |
auth = NetAppESeriesAuth() |
| 197 |
auth.is_proxy = lambda: True |
| 198 |
auth.is_embedded_available = lambda: True |
| 199 |
with mock.patch(self.REQ_FUNC, return_value=(204, None)): |
| 200 |
auth.logout_system() |
| 201 |
with self._set_args({"ssid": "Proxy", "user": "admin", "password": "adminpass", "minimum_password_length": 8}): |
| 202 |
auth = NetAppESeriesAuth() |
| 203 |
auth.is_proxy = lambda: False |
| 204 |
auth.is_embedded_available = lambda: True |
| 205 |
with mock.patch(self.REQ_FUNC, return_value=(204, None)): |
| 206 |
auth.logout_system() |
| 207 |
|
| 208 |
def test_password_change_required_pass(self): |
| 209 |
"""Verify password_change_required returns expected values.""" |
| 210 |
with self._set_args({"ssid": "Proxy", "user": "admin"}): |
| 211 |
auth = NetAppESeriesAuth() |
| 212 |
self.assertFalse(auth.password_change_required()) |
| 213 |
|
| 214 |
with self._set_args({"ssid": "Proxy", "user": "admin", "password": "adminpass"}): |
| 215 |
auth = NetAppESeriesAuth() |
| 216 |
auth.is_proxy = lambda: True |
| 217 |
auth.is_embedded_available = lambda: False |
| 218 |
with mock.patch(self.REQ_FUNC, side_effect=[(200, {"minimumPasswordLength": 8, "adminPasswordSet": False})]): |
| 219 |
self.assertTrue(auth.password_change_required()) |
| 220 |
with self._set_args({"ssid": "10", "user": "admin", "password": "adminpass"}): |
| 221 |
auth = NetAppESeriesAuth() |
| 222 |
auth.is_proxy = lambda: True |
| 223 |
auth.is_embedded_available = lambda: True |
| 224 |
with mock.patch(self.REQ_FUNC, side_effect=[(200, {"minimumPasswordLength": 8, "adminPasswordSet": False})]): |
| 225 |
self.assertTrue(auth.password_change_required()) |
| 226 |
with self._set_args({"ssid": "10", "user": "admin", "password": "adminpass"}): |
| 227 |
auth = NetAppESeriesAuth() |
| 228 |
auth.is_proxy = lambda: True |
| 229 |
auth.is_embedded_available = lambda: False |
| 230 |
with mock.patch(self.REQ_FUNC, side_effect=[(200, {"minimumPasswordLength": 8, "adminPasswordSet": False})]): |
| 231 |
self.assertTrue(auth.password_change_required()) |
| 232 |
with self._set_args({"ssid": "10", "user": "admin", "password": "adminpass"}): |
| 233 |
auth = NetAppESeriesAuth() |
| 234 |
auth.is_proxy = lambda: False |
| 235 |
auth.is_embedded_available = lambda: True |
| 236 |
with mock.patch(self.REQ_FUNC, side_effect=[(200, {"minimumPasswordLength": 8, "adminPasswordSet": False})]): |
| 237 |
self.assertTrue(auth.password_change_required()) |
| 238 |
|
| 239 |
with self._set_args({"ssid": "Proxy", "user": "admin", "password": "adminpass"}): |
| 240 |
auth = NetAppESeriesAuth() |
| 241 |
auth.is_proxy = lambda: True |
| 242 |
auth.is_embedded_available = lambda: False |
| 243 |
auth.logout_system = lambda: None |
| 244 |
with mock.patch(self.REQ_FUNC, side_effect=[(200, {"minimumPasswordLength": 8, "adminPasswordSet": True}), (200, None)]): |
| 245 |
self.assertFalse(auth.password_change_required()) |
| 246 |
with mock.patch(self.REQ_FUNC, side_effect=[(200, {"minimumPasswordLength": 8, "adminPasswordSet": True}), (401, None)]): |
| 247 |
self.assertTrue(auth.password_change_required()) |
| 248 |
|
| 249 |
with self._set_args({"ssid": "10", "user": "admin", "password": "adminpass"}): |
| 250 |
auth = NetAppESeriesAuth() |
| 251 |
auth.is_proxy = lambda: True |
| 252 |
auth.is_embedded_available = lambda: True |
| 253 |
auth.logout_system = lambda: None |
| 254 |
with mock.patch(self.REQ_FUNC, side_effect=[(200, {"minimumPasswordLength": 8, "adminPasswordSet": True}), (200, None)]): |
| 255 |
self.assertFalse(auth.password_change_required()) |
| 256 |
with mock.patch(self.REQ_FUNC, side_effect=[(401, None)]): |
| 257 |
self.assertTrue(auth.password_change_required()) |
| 258 |
|
| 259 |
with self._set_args({"ssid": "10", "user": "admin", "password": "adminpass"}): |
| 260 |
auth = NetAppESeriesAuth() |
| 261 |
auth.is_proxy = lambda: True |
| 262 |
auth.is_embedded_available = lambda: False |
| 263 |
auth.logout_system = lambda: None |
| 264 |
with mock.patch(self.REQ_FUNC, side_effect=[(200, {"minimumPasswordLength": 8, "adminPasswordSet": True}), (200, {"isValidPassword": True})]): |
| 265 |
self.assertFalse(auth.password_change_required()) |
| 266 |
with mock.patch(self.REQ_FUNC, side_effect=[(200, {"minimumPasswordLength": 8, "adminPasswordSet": True}), (200, {"isValidPassword": False})]): |
| 267 |
self.assertTrue(auth.password_change_required()) |
| 268 |
|
| 269 |
with self._set_args({"ssid": "10", "user": "admin", "password": "adminpass"}): |
| 270 |
auth = NetAppESeriesAuth() |
| 271 |
auth.is_proxy = lambda: False |
| 272 |
auth.is_embedded_available = lambda: True |
| 273 |
auth.logout_system = lambda: None |
| 274 |
with mock.patch(self.REQ_FUNC, side_effect=[(200, {"minimumPasswordLength": 8, "adminPasswordSet": True}), (200, None)]): |
| 275 |
self.assertFalse(auth.password_change_required()) |
| 276 |
with mock.patch(self.REQ_FUNC, side_effect=[(200, {"minimumPasswordLength": 8, "adminPasswordSet": True}), (401, None)]): |
| 277 |
self.assertTrue(auth.password_change_required()) |
| 278 |
|
| 279 |
def test_password_change_required_fail(self): |
| 280 |
"""Verify password_change_required throws expected exceptions.""" |
| 281 |
with self._set_args({"ssid": "Proxy", "user": "admin", "password": "adminpass"}): |
| 282 |
auth = NetAppESeriesAuth() |
| 283 |
auth.is_proxy = lambda: True |
| 284 |
auth.is_embedded_available = lambda: False |
| 285 |
auth.logout_system = lambda: None |
| 286 |
with self.assertRaisesRegex(AnsibleFailJson, "SAML enabled! SAML disables default role based login."): |
| 287 |
with mock.patch(self.REQ_FUNC, side_effect=[(200, {"minimumPasswordLength": 8, "adminPasswordSet": True}), (422, None)]): |
| 288 |
auth.password_change_required() |
| 289 |
|
| 290 |
with self._set_args({"ssid": "10", "user": "admin", "password": "adminpass"}): |
| 291 |
auth = NetAppESeriesAuth() |
| 292 |
auth.is_proxy = lambda: True |
| 293 |
auth.is_embedded_available = lambda: False |
| 294 |
auth.logout_system = lambda: None |
| 295 |
auth.is_web_services_version_met = lambda x: True |
| 296 |
with self.assertRaisesRegex(AnsibleFailJson, "For platforms before E2800 use SANtricity Web Services Proxy 4.1 or later!"): |
| 297 |
with mock.patch(self.REQ_FUNC, side_effect=[(200, {"minimumPasswordLength": 8, "adminPasswordSet": True}), (404, None)]): |
| 298 |
self.assertFalse(auth.password_change_required()) |
| 299 |
auth.is_web_services_version_met = lambda x: False |
| 300 |
with self.assertRaisesRegex(AnsibleFailJson, "Failed to validate stored password!"): |
| 301 |
with mock.patch(self.REQ_FUNC, side_effect=[(200, {"minimumPasswordLength": 8, "adminPasswordSet": True}), (404, None)]): |
| 302 |
self.assertFalse(auth.password_change_required()) |
| 303 |
with self.assertRaisesRegex(AnsibleFailJson, "Failed to validate stored password!"): |
| 304 |
with mock.patch(self.REQ_FUNC, side_effect=[(200, {"minimumPasswordLength": 8, "adminPasswordSet": True}), (422, None)]): |
| 305 |
self.assertFalse(auth.password_change_required()) |
| 306 |
|
| 307 |
with self._set_args({"ssid": "10", "user": "monitor", "password": "monitorpass"}): |
| 308 |
auth = NetAppESeriesAuth() |
| 309 |
auth.is_proxy = lambda: True |
| 310 |
auth.is_embedded_available = lambda: False |
| 311 |
auth.logout_system = lambda: None |
| 312 |
auth.is_web_services_version_met = lambda x: True |
| 313 |
with self.assertRaisesRegex( |
| 314 |
AnsibleFailJson, |
| 315 |
"Role based login not available! Only storage system password can be set for storage systems prior to" |
| 316 |
): |
| 317 |
with mock.patch(self.REQ_FUNC, side_effect=[(200, {"minimumPasswordLength": 8, "adminPasswordSet": True})]): |
| 318 |
self.assertFalse(auth.password_change_required()) |
| 319 |
|
| 320 |
def test_set_array_admin_password_pass(self): |
| 321 |
"""Verify set_array_admin_password results.""" |
| 322 |
with self._set_args({"ssid": "Proxy", "user": "admin", "password": "adminpass"}): |
| 323 |
auth = NetAppESeriesAuth() |
| 324 |
auth.is_proxy = lambda: True |
| 325 |
auth.is_embedded_available = lambda: False |
| 326 |
with mock.patch(self.REQ_FUNC, side_effect=[(200, None)]): |
| 327 |
auth.set_array_admin_password() |
| 328 |
with mock.patch(self.REQ_FUNC, side_effect=[Exception(), (200, None)]): |
| 329 |
auth.set_array_admin_password() |
| 330 |
|
| 331 |
with self._set_args({"ssid": "10", "user": "admin", "password": "adminpass"}): |
| 332 |
auth = NetAppESeriesAuth() |
| 333 |
auth.is_proxy = lambda: True |
| 334 |
auth.is_embedded_available = lambda: False |
| 335 |
with mock.patch(self.REQ_FUNC, side_effect=[(200, None)]): |
| 336 |
auth.set_array_admin_password() |
| 337 |
auth.is_embedded_available = lambda: True |
| 338 |
with mock.patch(self.REQ_FUNC, side_effect=[(200, None)]): |
| 339 |
auth.set_array_admin_password() |
| 340 |
|
| 341 |
with self._set_args({"ssid": "1", "user": "admin", "password": "adminpass"}): |
| 342 |
auth = NetAppESeriesAuth() |
| 343 |
auth.is_proxy = lambda: False |
| 344 |
auth.is_embedded_available = lambda: True |
| 345 |
with mock.patch(self.REQ_FUNC, return_value=(200, None)): |
| 346 |
auth.set_array_admin_password() |
| 347 |
|
| 348 |
def test_set_array_admin_password_fail(self): |
| 349 |
"""Verify set_array_admin_password throws expected exceptions.""" |
| 350 |
with self._set_args({"ssid": "Proxy", "user": "admin", "password": "adminpass"}): |
| 351 |
auth = NetAppESeriesAuth() |
| 352 |
auth.is_proxy = lambda: True |
| 353 |
auth.is_embedded_available = lambda: False |
| 354 |
with self.assertRaisesRegex(AnsibleFailJson, "Failed to set proxy's admin password."): |
| 355 |
with mock.patch(self.REQ_FUNC, side_effect=[Exception(), Exception()]): |
| 356 |
auth.set_array_admin_password() |
| 357 |
|
| 358 |
with self._set_args({"ssid": "10", "user": "admin", "password": "adminpass"}): |
| 359 |
auth = NetAppESeriesAuth() |
| 360 |
auth.is_proxy = lambda: True |
| 361 |
auth.is_embedded_available = lambda: False |
| 362 |
with self.assertRaisesRegex(AnsibleFailJson, "Failed to set storage system's admin password."): |
| 363 |
with mock.patch(self.REQ_FUNC, return_value=Exception()): |
| 364 |
auth.set_array_admin_password() |
| 365 |
|
| 366 |
with self._set_args({"ssid": "1", "user": "admin", "password": "adminpass"}): |
| 367 |
auth = NetAppESeriesAuth() |
| 368 |
auth.is_proxy = lambda: False |
| 369 |
auth.is_embedded_available = lambda: True |
| 370 |
with self.assertRaisesRegex(AnsibleFailJson, "Failed to set embedded storage system's admin password."): |
| 371 |
with mock.patch(self.REQ_FUNC, return_value=Exception()): |
| 372 |
auth.set_array_admin_password() |
| 373 |
|
| 374 |
def test_set_array_password_pass(self): |
| 375 |
"""Verify set_array_password results.""" |
| 376 |
with self._set_args({"ssid": "Proxy", "user": "admin", "password": "adminpass"}): |
| 377 |
auth = NetAppESeriesAuth() |
| 378 |
auth.is_proxy = lambda: True |
| 379 |
auth.is_embedded_available = lambda: False |
| 380 |
auth.is_admin_password_set = True |
| 381 |
with mock.patch(self.REQ_FUNC, return_value=(200, None)): |
| 382 |
auth.set_array_password() |
| 383 |
|
| 384 |
with self._set_args({"ssid": "10", "user": "admin", "password": "adminpass"}): |
| 385 |
auth = NetAppESeriesAuth() |
| 386 |
auth.is_proxy = lambda: True |
| 387 |
auth.is_embedded_available = lambda: True |
| 388 |
auth.is_admin_password_set = True |
| 389 |
with mock.patch(self.REQ_FUNC, return_value=(200, None)): |
| 390 |
auth.set_array_password() |
| 391 |
|
| 392 |
with self._set_args({"ssid": "1", "user": "admin", "password": "adminpass"}): |
| 393 |
auth = NetAppESeriesAuth() |
| 394 |
auth.is_proxy = lambda: False |
| 395 |
auth.is_embedded_available = lambda: True |
| 396 |
auth.is_admin_password_set = True |
| 397 |
with mock.patch(self.REQ_FUNC, return_value=(200, None)): |
| 398 |
auth.set_array_password() |
| 399 |
|
| 400 |
def test_set_array_password_fail(self): |
| 401 |
"""Verify set_array_password throws expected exceptions.""" |
| 402 |
with self._set_args({"ssid": "Proxy", "user": "monitor", "password": "adminpass"}): |
| 403 |
auth = NetAppESeriesAuth() |
| 404 |
auth.is_proxy = lambda: True |
| 405 |
auth.is_embedded_available = lambda: False |
| 406 |
auth.is_admin_password_set = False |
| 407 |
with self.assertRaisesRegex(AnsibleFailJson, "Admin password not set! Set admin password before changing non-admin user passwords."): |
| 408 |
auth.set_array_password() |
| 409 |
|
| 410 |
with self._set_args({"ssid": "Proxy", "user": "admin", "password": "adminpass"}): |
| 411 |
auth = NetAppESeriesAuth() |
| 412 |
auth.is_proxy = lambda: True |
| 413 |
auth.is_embedded_available = lambda: False |
| 414 |
auth.is_admin_password_set = True |
| 415 |
with self.assertRaisesRegex(AnsibleFailJson, "Failed to set proxy password."): |
| 416 |
with mock.patch(self.REQ_FUNC, return_value=Exception()): |
| 417 |
auth.set_array_password() |
| 418 |
|
| 419 |
with self._set_args({"ssid": "10", "user": "admin", "password": "adminpass"}): |
| 420 |
auth = NetAppESeriesAuth() |
| 421 |
auth.is_proxy = lambda: True |
| 422 |
auth.is_embedded_available = lambda: True |
| 423 |
auth.is_admin_password_set = True |
| 424 |
with self.assertRaisesRegex(AnsibleFailJson, "Failed to set embedded user password."): |
| 425 |
with mock.patch(self.REQ_FUNC, return_value=Exception()): |
| 426 |
auth.set_array_password() |
| 427 |
|
| 428 |
with self._set_args({"ssid": "1", "user": "admin", "password": "adminpass"}): |
| 429 |
auth = NetAppESeriesAuth() |
| 430 |
auth.is_proxy = lambda: False |
| 431 |
auth.is_embedded_available = lambda: True |
| 432 |
auth.is_admin_password_set = True |
| 433 |
with self.assertRaisesRegex(AnsibleFailJson, "Failed to set embedded user password."): |
| 434 |
with mock.patch(self.REQ_FUNC, return_value=Exception()): |
| 435 |
auth.set_array_password() |
| 436 |
|
| 437 |
def test_apply_pass(self): |
| 438 |
"""Verify apply results.""" |
| 439 |
with self._set_args({"ssid": "1", "user": "admin", "password": "adminpass"}): |
| 440 |
auth = NetAppESeriesAuth() |
| 441 |
auth.is_admin_password_set = True |
| 442 |
auth.password_change_required = lambda: True |
| 443 |
auth.minimum_password_length_change_required = lambda: True |
| 444 |
auth.update_minimum_password_length = lambda: None |
| 445 |
auth.set_array_admin_password = lambda: None |
| 446 |
auth.set_array_password = lambda: None |
| 447 |
with self.assertRaisesRegex(AnsibleExitJson, "'admin' password and required password length has been changed."): |
| 448 |
auth.apply() |
| 449 |
|
| 450 |
with self._set_args({"ssid": "1", "user": "admin", "password": "adminpass"}): |
| 451 |
auth = NetAppESeriesAuth() |
| 452 |
auth.is_admin_password_set = False |
| 453 |
auth.password_change_required = lambda: True |
| 454 |
auth.minimum_password_length_change_required = lambda: True |
| 455 |
auth.update_minimum_password_length = lambda: None |
| 456 |
auth.set_array_admin_password = lambda: None |
| 457 |
auth.set_array_password = lambda: None |
| 458 |
with self.assertRaisesRegex(AnsibleExitJson, "'admin' password and required password length has been changed."): |
| 459 |
auth.apply() |
| 460 |
|
| 461 |
with self._set_args({"ssid": "1", "user": "monitor", "password": "adminpass"}): |
| 462 |
auth = NetAppESeriesAuth() |
| 463 |
auth.is_admin_password_set = True |
| 464 |
auth.password_change_required = lambda: True |
| 465 |
auth.minimum_password_length_change_required = lambda: True |
| 466 |
auth.update_minimum_password_length = lambda: None |
| 467 |
auth.set_array_admin_password = lambda: None |
| 468 |
auth.set_array_password = lambda: None |
| 469 |
with self.assertRaisesRegex(AnsibleExitJson, "'monitor' password and required password length has been changed."): |
| 470 |
auth.apply() |
| 471 |
|
| 472 |
with self._set_args({"ssid": "1", "user": "admin", "password": "adminpass"}): |
| 473 |
auth = NetAppESeriesAuth() |
| 474 |
auth.is_admin_password_set = True |
| 475 |
auth.password_change_required = lambda: True |
| 476 |
auth.minimum_password_length_change_required = lambda: False |
| 477 |
auth.update_minimum_password_length = lambda: None |
| 478 |
auth.set_array_admin_password = lambda: None |
| 479 |
auth.set_array_password = lambda: None |
| 480 |
with self.assertRaisesRegex(AnsibleExitJson, "'admin' password has been changed."): |
| 481 |
auth.apply() |
| 482 |
|
| 483 |
with self._set_args({"ssid": "1", "user": "admin", "password": "adminpass"}): |
| 484 |
auth = NetAppESeriesAuth() |
| 485 |
auth.is_admin_password_set = True |
| 486 |
auth.password_change_required = lambda: False |
| 487 |
auth.minimum_password_length_change_required = lambda: True |
| 488 |
auth.update_minimum_password_length = lambda: None |
| 489 |
auth.set_array_admin_password = lambda: None |
| 490 |
auth.set_array_password = lambda: None |
| 491 |
with self.assertRaisesRegex(AnsibleExitJson, "Required password length has been changed."): |
| 492 |
auth.apply() |
| 493 |
|
| 494 |
with self._set_args({"ssid": "1", "user": "admin", "password": "adminpass"}): |
| 495 |
auth = NetAppESeriesAuth() |
| 496 |
auth.is_admin_password_set = True |
| 497 |
auth.password_change_required = lambda: False |
| 498 |
auth.minimum_password_length_change_required = lambda: False |
| 499 |
auth.update_minimum_password_length = lambda: None |
| 500 |
auth.set_array_admin_password = lambda: None |
| 501 |
auth.set_array_password = lambda: None |
| 502 |
with self.assertRaisesRegex(AnsibleExitJson, "No changes have been made."): |
| 503 |
auth.apply() |