Skip to content

Wdt 677 - atp_helper not handling multiple descriptions for ATP DG url case #1217

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 28 additions & 15 deletions core/src/main/python/wlsdeploy/tool/create/atp_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,26 +98,39 @@ def get_atp_connect_string(tnsnames_ora_path, tns_sid_name):

def cleanup_connect_string(connect_string):
"""
Formats connect string for ATP DB by removing unwanted whitespaces.
Formats connect string for ATP DB by removing unwanted whitespaces. It appears the wallet's tnsnames.ora file in
the wallet has various whitespaces from various periods. The cie code somehow parses this connection string also,
so this is the best effort to remove the spaces.

Input:
(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")) )
(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")) )
Output Parts:
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=(
1. (description=(address=(protocol=tcps)(port=1522)(host=*******.oraclecloud.com))(connect_data=(service_name=someservice-in.oraclecloud.com))(security=(
2. ssl_server_cert_dn=
3. "CN=adwc-preprod.uscom-east-1.oraclecloud.com,OU=Oracle BMCS US,O=Oracle Corporation,L=Redwood City,ST=California,C=US"
3. "CN=somewhere-in.oraclecloud.com,OU=Oracle BMCS US,O=Oracle Corporation,L=Redwood City,ST=California,C=US"
4. )))
:param connect_string:
:return:
"""

toks = connect_string.split('(description=')
pattern = "(.*)(ssl_server_cert_dn=)\s*(\".*\")(.*)"
match = re.search(pattern, connect_string)

if match:
part1 = match.group(1).replace(' ','')
part2 = match.group(2).replace(' ', '')
# We don't want to remove the spaces from serverDN part.
part3 = match.group(3)
part4 = match.group(4).replace(' ', '')
connect_string = "%s%s%s%s" % (part1, part2, part3, part4)
# if no match then return original one
return connect_string
result = ''
for token in toks:
if token.find("(ssl_server_cert_dn=") > 0:
match = re.search(pattern, token)
if match:
part1 = match.group(1).replace(' ','')
part2 = match.group(2).replace(' ', '')
# We don't want to remove the spaces from serverDN part.
part3 = match.group(3)
part4 = match.group(4).replace(' ', '')
result += "(description=%s%s%s%s" % (part1, part2, part3, part4)
else:
result += token.replace(' ', '')

if result == '':
result = connect_string

return result

51 changes: 51 additions & 0 deletions core/src/test/python/atp_helper_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"""
Copyright (c) 2022, Oracle and/or its affiliates.
Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
"""
import unittest

from wlsdeploy.tool.create import atp_helper

class AtpHelperTestCase(unittest.TestCase):

def testFixingDescriptionList(self):
src_url = '(description_list=(failover=on)(load_balance=off)(description=(retry_count=15)(retry_delay=3)' \
'(address=(protocol=tcps)(port=1522)(host=somewhere-in.oraclecloud.com))' \
'(connect_data=(service_name=some-service-in.oraclecloud.com))' \
'(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")))' \
'(description=(retry_count=15)(retry_delay=3)(address=(protocol=tcps)(port=1522)(host=somewhere2-in.oraclecloud.com))' \
'(connect_data=(service_name=some-service-in.oraclecloud.com))' \
'(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")))' \
'(description=(retry_count=15)(retry_delay=3)(address=(protocol=tcps)(port=1523)(host=somewhere2-in.oraclecloud.com))' \
'(connect_data=(service_name=some-service-in.oraclecloud.com))' \
'(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")) ) )'

expected_url = '(description_list=(failover=on)(load_balance=off)(description=(retry_count=15)(retry_delay=3)' \
'(address=(protocol=tcps)(port=1522)(host=somewhere-in.oraclecloud.com))' \
'(connect_data=(service_name=some-service-in.oraclecloud.com))' \
'(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")))' \
'(description=(retry_count=15)(retry_delay=3)(address=(protocol=tcps)(port=1522)(host=somewhere2-in.oraclecloud.com))' \
'(connect_data=(service_name=some-service-in.oraclecloud.com))' \
'(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")))' \
'(description=(retry_count=15)(retry_delay=3)(address=(protocol=tcps)(port=1523)(host=somewhere2-in.oraclecloud.com))' \
'(connect_data=(service_name=some-service-in.oraclecloud.com))' \
'(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"))))'


fixed_url = atp_helper.cleanup_connect_string(src_url)
self.assertEqual(fixed_url, expected_url)
return

def testFixingNonDescriptionList(self):
src_url = '(description= (address=(protocol=tcps)(port=1522)(host=some-cn-in.oraclecloud.com))' \
'(connect_data=(service_name=some-service-in.oraclecloud.com))' \
'(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")) )'

expected_url = '(description=(address=(protocol=tcps)(port=1522)(host=some-cn-in.oraclecloud.com))' \
'(connect_data=(service_name=some-service-in.oraclecloud.com))' \
'(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")))'

fixed_url = atp_helper.cleanup_connect_string(src_url)

self.assertEqual(fixed_url, expected_url)
return