|
| 1 | +""" |
| 2 | +Copyright (c) 2019, Oracle Corporation and/or its affiliates. All rights reserved. |
| 3 | +Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl. |
| 4 | +""" |
| 5 | +import unittest |
| 6 | + |
| 7 | +from wlsdeploy.aliases.aliases import Aliases |
| 8 | +from wlsdeploy.aliases.location_context import LocationContext |
| 9 | +from wlsdeploy.aliases.model_constants import JDBC_DRIVER_PARAMS |
| 10 | +from wlsdeploy.aliases.model_constants import JDBC_RESOURCE |
| 11 | +from wlsdeploy.aliases.model_constants import JDBC_SYSTEM_RESOURCE |
| 12 | +from wlsdeploy.aliases.model_constants import PASSWORD_ENCRYPTED |
| 13 | +from wlsdeploy.aliases.wlst_modes import WlstModes |
| 14 | +from wlsdeploy.logging.platform_logger import PlatformLogger |
| 15 | +from wlsdeploy.util.cla_utils import CommandLineArgUtil |
| 16 | +from wlsdeploy.util.model_context import ModelContext |
| 17 | + |
| 18 | + |
| 19 | +class AliasEncryptedModelTestCase(unittest.TestCase): |
| 20 | + """ |
| 21 | + Test cases for a the -use_encryption feature. |
| 22 | + """ |
| 23 | + |
| 24 | + _logger = PlatformLogger('wlsdeploy.aliases') |
| 25 | + _wls_version = '12.2.1.3' |
| 26 | + _wlst_password_name = "Password" |
| 27 | + _wlst_password_encrypted_name = "PasswordEncrypted" |
| 28 | + |
| 29 | + _passphrase = 'RE a drop of golden sun' |
| 30 | + _password = 'welcome1' |
| 31 | + _encrypted_password = '{AES}UC9rZld3blZFUnMraW12cHkydmtmdmpSZmNNMWVHajA6VERPYlJoeWxXU09IaHVrQzpBeWsrd2ZacVkyVT0=' |
| 32 | + |
| 33 | + def setUp(self): |
| 34 | + # construct aliases as if the -use_encryption and -passphrase switches were used |
| 35 | + model_context = ModelContext("test", {CommandLineArgUtil.USE_ENCRYPTION_SWITCH: 'true', |
| 36 | + CommandLineArgUtil.PASSPHRASE_SWITCH: self._passphrase}) |
| 37 | + self.aliases = Aliases(model_context, wlst_mode=WlstModes.OFFLINE, wls_version=self._wls_version) |
| 38 | + self.online_aliases = Aliases(model_context, wlst_mode=WlstModes.ONLINE, wls_version=self._wls_version) |
| 39 | + |
| 40 | + self.location = LocationContext() |
| 41 | + self.location.append_location(JDBC_SYSTEM_RESOURCE) |
| 42 | + self.location.add_name_token(self.aliases.get_name_token(self.location), "Mine") |
| 43 | + self.location.append_location(JDBC_RESOURCE) |
| 44 | + self.location.append_location(JDBC_DRIVER_PARAMS) |
| 45 | + |
| 46 | + def testOfflineWlstNames(self): |
| 47 | + # Using offline WLST, the PasswordEncrypted model attribute should translate to the PasswordEncrypted WLST |
| 48 | + # attribute, regardless of whether the password is encrypted. The password value should be plain text. |
| 49 | + |
| 50 | + # using encrypted password |
| 51 | + wlst_name, wlst_value = \ |
| 52 | + self.aliases.get_wlst_attribute_name_and_value(self.location, PASSWORD_ENCRYPTED, self._encrypted_password) |
| 53 | + self.assertEqual(wlst_name, self._wlst_password_encrypted_name) |
| 54 | + self.assertEqual(wlst_value, self._password) |
| 55 | + |
| 56 | + # using unencrypted password |
| 57 | + wlst_name, wlst_value = \ |
| 58 | + self.aliases.get_wlst_attribute_name_and_value(self.location, PASSWORD_ENCRYPTED, self._password) |
| 59 | + self.assertEquals(wlst_name, self._wlst_password_encrypted_name) |
| 60 | + self.assertEqual(wlst_value, self._password) |
| 61 | + |
| 62 | + def testOnlineWlstNames(self): |
| 63 | + # Using online WLST, the PasswordEncrypted model attribute should always translate to the Password WLST |
| 64 | + # attribute, and the value should translate to the unencrypted value. |
| 65 | + |
| 66 | + # using encrypted password |
| 67 | + wlst_name, wlst_value = \ |
| 68 | + self.online_aliases.get_wlst_attribute_name_and_value(self.location, PASSWORD_ENCRYPTED, |
| 69 | + self._encrypted_password) |
| 70 | + self.assertEqual(wlst_name, self._wlst_password_name) |
| 71 | + self.assertEqual(wlst_value, self._password) |
| 72 | + |
| 73 | + # using unencrypted password |
| 74 | + wlst_name, wlst_value = \ |
| 75 | + self.online_aliases.get_wlst_attribute_name_and_value(self.location, PASSWORD_ENCRYPTED, self._password) |
| 76 | + self.assertEquals(wlst_name, self._wlst_password_name) |
| 77 | + self.assertEqual(wlst_value, self._password) |
0 commit comments