|
| 1 | +""" |
| 2 | +Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. |
| 3 | +The Universal Permissive License (UPL), Version 1.0 |
| 4 | +""" |
| 5 | +import jarray |
| 6 | +import unittest |
| 7 | + |
| 8 | +from wlsdeploy.aliases.aliases import Aliases |
| 9 | +from wlsdeploy.aliases.location_context import LocationContext |
| 10 | +from wlsdeploy.aliases.model_constants import JDBC_DRIVER_PARAMS |
| 11 | +from wlsdeploy.aliases.model_constants import JDBC_RESOURCE |
| 12 | +from wlsdeploy.aliases.model_constants import JDBC_SYSTEM_RESOURCE |
| 13 | +from wlsdeploy.aliases.model_constants import PASSWORD_ENCRYPTED |
| 14 | +from wlsdeploy.aliases.wlst_modes import WlstModes |
| 15 | +from wlsdeploy.logging.platform_logger import PlatformLogger |
| 16 | +from wlsdeploy.util.model_context import ModelContext |
| 17 | + |
| 18 | + |
| 19 | +class AliasPasswordTestCase(unittest.TestCase): |
| 20 | + |
| 21 | + _logger = PlatformLogger('wlsdeploy.aliases') |
| 22 | + _wls_version = '12.2.1.3' |
| 23 | + _wlst_password_name = "Password" |
| 24 | + _wlst_password_encrypted_name = "PasswordEncrypted" |
| 25 | + |
| 26 | + _password = 'welcome1' |
| 27 | + _encrypted_password = '{AES}BR5Lw+UuwM4ZmFcTu2GX5C2w0Jcr6E30uhZvhoyXjYU=' |
| 28 | + _encrypted_password_bytes = jarray.array(_encrypted_password, 'b') |
| 29 | + |
| 30 | + def setUp(self): |
| 31 | + model_context = ModelContext("test", {}) |
| 32 | + self.aliases = Aliases(model_context, wlst_mode=WlstModes.OFFLINE, wls_version=self._wls_version) |
| 33 | + self.online_aliases = Aliases(model_context, wlst_mode=WlstModes.ONLINE, wls_version=self._wls_version) |
| 34 | + |
| 35 | + self.location = LocationContext() |
| 36 | + self.location.append_location(JDBC_SYSTEM_RESOURCE) |
| 37 | + self.location.add_name_token(self.aliases.get_name_token(self.location), "Mine") |
| 38 | + self.location.append_location(JDBC_RESOURCE) |
| 39 | + self.location.append_location(JDBC_DRIVER_PARAMS) |
| 40 | + |
| 41 | + def testOfflineModelNames(self): |
| 42 | + # Using offline WLST, only PasswordEncrypted is an attribute, and its value is encrypted. |
| 43 | + # The model name should be PasswordEncrypted. |
| 44 | + model_name, model_value = \ |
| 45 | + self.aliases.get_model_attribute_name_and_value(self.location, self._wlst_password_encrypted_name, |
| 46 | + self._encrypted_password) |
| 47 | + self.assertEquals(model_name, PASSWORD_ENCRYPTED) |
| 48 | + |
| 49 | + def testOnlineModelNames(self): |
| 50 | + # Using online WLST, both Password and PasswordEncrypted are WLST attributes. |
| 51 | + |
| 52 | + # The PasswordEncrypted WLST attribute should translate to the PasswordEncrypted model attribute. |
| 53 | + model_name, model_value = \ |
| 54 | + self.online_aliases.get_model_attribute_name_and_value(self.location, self._wlst_password_encrypted_name, |
| 55 | + self._encrypted_password) |
| 56 | + self.assertEqual(model_name, PASSWORD_ENCRYPTED) |
| 57 | + |
| 58 | + # The Password WLST attribute should be skipped, since its value cannot be retrieved. |
| 59 | + # This is accomplished by returning a model name of None. |
| 60 | + model_name, model_value = \ |
| 61 | + self.online_aliases.get_model_attribute_name_and_value(self.location, self._wlst_password_name, |
| 62 | + self._encrypted_password) |
| 63 | + self.assertEquals(model_name, None) |
| 64 | + |
| 65 | + def testOfflineWlstNames(self): |
| 66 | + # Using offline WLST, the PasswordEncrypted model attribute should translate to the PasswordEncrypted WLST |
| 67 | + # attribute, regardless of whether the password is encrypted. |
| 68 | + |
| 69 | + # using encrypted password |
| 70 | + wlst_name, wlst_value = \ |
| 71 | + self.aliases.get_wlst_attribute_name_and_value(self.location, PASSWORD_ENCRYPTED, self._encrypted_password) |
| 72 | + self.assertEqual(wlst_name, self._wlst_password_encrypted_name) |
| 73 | + |
| 74 | + # using unencrypted password |
| 75 | + wlst_name, wlst_value = \ |
| 76 | + self.aliases.get_wlst_attribute_name_and_value(self.location, PASSWORD_ENCRYPTED, self._password) |
| 77 | + self.assertEquals(wlst_name, self._wlst_password_encrypted_name) |
| 78 | + |
| 79 | + def testOnlineWlstNames(self): |
| 80 | + # Using online WLST, the PasswordEncrypted model attribute should translate to the PasswordEncrypted WLST |
| 81 | + # attribute if the password is encrypted, otherwise to Password. |
| 82 | + |
| 83 | + # using encrypted password |
| 84 | + wlst_name, wlst_value = \ |
| 85 | + self.online_aliases.get_wlst_attribute_name_and_value(self.location, PASSWORD_ENCRYPTED, |
| 86 | + self._encrypted_password) |
| 87 | + self.assertEqual(wlst_name, self._wlst_password_encrypted_name) |
| 88 | + |
| 89 | + # using unencrypted password |
| 90 | + wlst_name, wlst_value = \ |
| 91 | + self.online_aliases.get_wlst_attribute_name_and_value(self.location, PASSWORD_ENCRYPTED, self._password) |
| 92 | + self.assertEquals(wlst_name, self._wlst_password_name) |
0 commit comments