Skip to content

Commit 89e2eaa

Browse files
authored
Wdt 677 - atp_helper not handling multiple descriptions for ATP DG url case (#1217)
* The tnsnames.ora from ATP can contain multiple addresses for DG, adding best effort to fix unwanted spaces but preserve the server cert dn * add unit test for atp_helper fixing url
1 parent 3645ff1 commit 89e2eaa

File tree

2 files changed

+79
-15
lines changed

2 files changed

+79
-15
lines changed

core/src/main/python/wlsdeploy/tool/create/atp_helper.py

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -98,26 +98,39 @@ def get_atp_connect_string(tnsnames_ora_path, tns_sid_name):
9898

9999
def cleanup_connect_string(connect_string):
100100
"""
101-
Formats connect string for ATP DB by removing unwanted whitespaces.
101+
Formats connect string for ATP DB by removing unwanted whitespaces. It appears the wallet's tnsnames.ora file in
102+
the wallet has various whitespaces from various periods. The cie code somehow parses this connection string also,
103+
so this is the best effort to remove the spaces.
104+
102105
Input:
103-
(description= (address=(protocol=tcps)(port=1522)(host=adb-preprod.us-phoenix-1.oraclecloud.com))(connect_data=(service_name=uq7p1eavz8qlvts_watsh01_medium.atp.oraclecloud.com))(security=(ssl_server_cert_dn= "CN=adwc-preprod.uscom-east-1.oraclecloud.com,OU=Oracle BMCS US,O=Oracle Corporation,L=Redwood City,ST=California,C=US")) )
106+
(description= (address=(protocol=tcps)(port=1522)(host=*******.oraclecloud.com))(connect_data=(service_name=someservice-in.oraclecloud.com))(security=(ssl_server_cert_dn= "CN=somewhere-in.oraclecloud.com,OU=Oracle BMCS US,O=Oracle Corporation,L=Redwood City,ST=California,C=US")) )
104107
Output Parts:
105-
1. (description=(address=(protocol=tcps)(port=1522)(host=adb-preprod.us-phoenix-1.oraclecloud.com))(connect_data=(service_name=uq7p1eavz8qlvts_watsh01_medium.atp.oraclecloud.com))(security=(
108+
1. (description=(address=(protocol=tcps)(port=1522)(host=*******.oraclecloud.com))(connect_data=(service_name=someservice-in.oraclecloud.com))(security=(
106109
2. ssl_server_cert_dn=
107-
3. "CN=adwc-preprod.uscom-east-1.oraclecloud.com,OU=Oracle BMCS US,O=Oracle Corporation,L=Redwood City,ST=California,C=US"
110+
3. "CN=somewhere-in.oraclecloud.com,OU=Oracle BMCS US,O=Oracle Corporation,L=Redwood City,ST=California,C=US"
108111
4. )))
109112
:param connect_string:
110113
:return:
111114
"""
115+
116+
toks = connect_string.split('(description=')
112117
pattern = "(.*)(ssl_server_cert_dn=)\s*(\".*\")(.*)"
113-
match = re.search(pattern, connect_string)
114-
115-
if match:
116-
part1 = match.group(1).replace(' ','')
117-
part2 = match.group(2).replace(' ', '')
118-
# We don't want to remove the spaces from serverDN part.
119-
part3 = match.group(3)
120-
part4 = match.group(4).replace(' ', '')
121-
connect_string = "%s%s%s%s" % (part1, part2, part3, part4)
122-
# if no match then return original one
123-
return connect_string
118+
result = ''
119+
for token in toks:
120+
if token.find("(ssl_server_cert_dn=") > 0:
121+
match = re.search(pattern, token)
122+
if match:
123+
part1 = match.group(1).replace(' ','')
124+
part2 = match.group(2).replace(' ', '')
125+
# We don't want to remove the spaces from serverDN part.
126+
part3 = match.group(3)
127+
part4 = match.group(4).replace(' ', '')
128+
result += "(description=%s%s%s%s" % (part1, part2, part3, part4)
129+
else:
130+
result += token.replace(' ', '')
131+
132+
if result == '':
133+
result = connect_string
134+
135+
return result
136+
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
"""
2+
Copyright (c) 2022, Oracle and/or its affiliates.
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.tool.create import atp_helper
8+
9+
class AtpHelperTestCase(unittest.TestCase):
10+
11+
def testFixingDescriptionList(self):
12+
src_url = '(description_list=(failover=on)(load_balance=off)(description=(retry_count=15)(retry_delay=3)' \
13+
'(address=(protocol=tcps)(port=1522)(host=somewhere-in.oraclecloud.com))' \
14+
'(connect_data=(service_name=some-service-in.oraclecloud.com))' \
15+
'(security=(ssl_server_cert_dn="CN=some-cn-in.oraclecloud.com, OU=Oracle BMCS US, O=Oracle Corporation, L=Redwood City, ST=California, C=US")))' \
16+
'(description=(retry_count=15)(retry_delay=3)(address=(protocol=tcps)(port=1522)(host=somewhere2-in.oraclecloud.com))' \
17+
'(connect_data=(service_name=some-service-in.oraclecloud.com))' \
18+
'(security=(ssl_server_cert_dn="CN=some-cn-in.oraclecloud.com, OU=Oracle BMCS US, O=Oracle Corporation, L=Redwood City, ST=California, C=US")))' \
19+
'(description=(retry_count=15)(retry_delay=3)(address=(protocol=tcps)(port=1523)(host=somewhere2-in.oraclecloud.com))' \
20+
'(connect_data=(service_name=some-service-in.oraclecloud.com))' \
21+
'(security=(ssl_server_cert_dn="CN=some-cn-in.oraclecloud.com, OU=Oracle BMCS US, O=Oracle Corporation, L=Redwood City, ST=California, C=US")) ) )'
22+
23+
expected_url = '(description_list=(failover=on)(load_balance=off)(description=(retry_count=15)(retry_delay=3)' \
24+
'(address=(protocol=tcps)(port=1522)(host=somewhere-in.oraclecloud.com))' \
25+
'(connect_data=(service_name=some-service-in.oraclecloud.com))' \
26+
'(security=(ssl_server_cert_dn="CN=some-cn-in.oraclecloud.com, OU=Oracle BMCS US, O=Oracle Corporation, L=Redwood City, ST=California, C=US")))' \
27+
'(description=(retry_count=15)(retry_delay=3)(address=(protocol=tcps)(port=1522)(host=somewhere2-in.oraclecloud.com))' \
28+
'(connect_data=(service_name=some-service-in.oraclecloud.com))' \
29+
'(security=(ssl_server_cert_dn="CN=some-cn-in.oraclecloud.com, OU=Oracle BMCS US, O=Oracle Corporation, L=Redwood City, ST=California, C=US")))' \
30+
'(description=(retry_count=15)(retry_delay=3)(address=(protocol=tcps)(port=1523)(host=somewhere2-in.oraclecloud.com))' \
31+
'(connect_data=(service_name=some-service-in.oraclecloud.com))' \
32+
'(security=(ssl_server_cert_dn="CN=some-cn-in.oraclecloud.com, OU=Oracle BMCS US, O=Oracle Corporation, L=Redwood City, ST=California, C=US"))))'
33+
34+
35+
fixed_url = atp_helper.cleanup_connect_string(src_url)
36+
self.assertEqual(fixed_url, expected_url)
37+
return
38+
39+
def testFixingNonDescriptionList(self):
40+
src_url = '(description= (address=(protocol=tcps)(port=1522)(host=some-cn-in.oraclecloud.com))' \
41+
'(connect_data=(service_name=some-service-in.oraclecloud.com))' \
42+
'(security=(ssl_server_cert_dn= "CN=some-cn-in.oraclecloud.com,OU=Oracle BMCS US,O=Oracle Corporation,L=Redwood City,ST=California,C=US")) )'
43+
44+
expected_url = '(description=(address=(protocol=tcps)(port=1522)(host=some-cn-in.oraclecloud.com))' \
45+
'(connect_data=(service_name=some-service-in.oraclecloud.com))' \
46+
'(security=(ssl_server_cert_dn="CN=some-cn-in.oraclecloud.com,OU=Oracle BMCS US,O=Oracle Corporation,L=Redwood City,ST=California,C=US")))'
47+
48+
fixed_url = atp_helper.cleanup_connect_string(src_url)
49+
50+
self.assertEqual(fixed_url, expected_url)
51+
return

0 commit comments

Comments
 (0)