Skip to content

Commit 09c2eb9

Browse files
committed
Issue #484 - Separated encrypted model unit test from password test
1 parent f0df27b commit 09c2eb9

File tree

2 files changed

+83
-8
lines changed

2 files changed

+83
-8
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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)

core/src/test/python/alias_password_test.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
Copyright (c) 2018, 2019, Oracle Corporation and/or its affiliates. All rights reserved.
33
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
44
"""
5-
import jarray
65
import unittest
76

87
from wlsdeploy.aliases.aliases import Aliases
@@ -13,25 +12,24 @@
1312
from wlsdeploy.aliases.model_constants import PASSWORD_ENCRYPTED
1413
from wlsdeploy.aliases.wlst_modes import WlstModes
1514
from wlsdeploy.logging.platform_logger import PlatformLogger
16-
from wlsdeploy.util.cla_utils import CommandLineArgUtil
1715
from wlsdeploy.util.model_context import ModelContext
1816

1917

2018
class AliasPasswordTestCase(unittest.TestCase):
19+
"""
20+
Test domain-encrypted passwords in a model.
21+
"""
2122

2223
_logger = PlatformLogger('wlsdeploy.aliases')
2324
_wls_version = '12.2.1.3'
2425
_wlst_password_name = "Password"
2526
_wlst_password_encrypted_name = "PasswordEncrypted"
2627

27-
_passphrase = 'RE a drop of golden sun'
2828
_password = 'welcome1'
2929
_encrypted_password = '{AES}UC9rZld3blZFUnMraW12cHkydmtmdmpSZmNNMWVHajA6VERPYlJoeWxXU09IaHVrQzpBeWsrd2ZacVkyVT0='
30-
_encrypted_password_bytes = jarray.array(_encrypted_password, 'b')
3130

3231
def setUp(self):
33-
model_context = ModelContext("test", {CommandLineArgUtil.USE_ENCRYPTION_SWITCH: 'true',
34-
CommandLineArgUtil.PASSPHRASE_SWITCH: self._passphrase})
32+
model_context = ModelContext("test", {})
3533
self.aliases = Aliases(model_context, wlst_mode=WlstModes.OFFLINE, wls_version=self._wls_version)
3634
self.online_aliases = Aliases(model_context, wlst_mode=WlstModes.ONLINE, wls_version=self._wls_version)
3735

@@ -73,7 +71,7 @@ def testOfflineWlstNames(self):
7371
wlst_name, wlst_value = \
7472
self.aliases.get_wlst_attribute_name_and_value(self.location, PASSWORD_ENCRYPTED, self._encrypted_password)
7573
self.assertEqual(wlst_name, self._wlst_password_encrypted_name)
76-
self.assertEqual(wlst_value, self._password)
74+
self.assertEqual(wlst_value, self._encrypted_password)
7775

7876
# using unencrypted password
7977
wlst_name, wlst_value = \
@@ -89,7 +87,7 @@ def testOnlineWlstNames(self):
8987
self.online_aliases.get_wlst_attribute_name_and_value(self.location, PASSWORD_ENCRYPTED,
9088
self._encrypted_password)
9189
self.assertEqual(wlst_name, self._wlst_password_encrypted_name)
92-
self.assertEqual(wlst_value, self._password)
90+
self.assertEqual(wlst_value, self._encrypted_password)
9391

9492
# using unencrypted password
9593
wlst_name, wlst_value = \

0 commit comments

Comments
 (0)