From 43a62e1a24776cec036a78a766835ba98327372a Mon Sep 17 00:00:00 2001 From: Johnny Shum Date: Fri, 14 Oct 2022 15:20:22 -0500 Subject: [PATCH 1/2] The tnsnames.ora from ATP can contain multiple addresses for DG, adding best effort to fix unwanted spaces but preserve the server cert dn --- .../wlsdeploy/tool/create/atp_helper.py | 37 +++++++++++++------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/core/src/main/python/wlsdeploy/tool/create/atp_helper.py b/core/src/main/python/wlsdeploy/tool/create/atp_helper.py index e14202290..fb5816afe 100644 --- a/core/src/main/python/wlsdeploy/tool/create/atp_helper.py +++ b/core/src/main/python/wlsdeploy/tool/create/atp_helper.py @@ -98,7 +98,10 @@ 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")) ) Output Parts: @@ -109,15 +112,25 @@ def cleanup_connect_string(connect_string): :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 + From e14515996c1312c36bb851fc19aff2836ab2599d Mon Sep 17 00:00:00 2001 From: Johnny Shum Date: Mon, 17 Oct 2022 10:06:20 -0500 Subject: [PATCH 2/2] add unit test for atp_helper fixing url --- .../wlsdeploy/tool/create/atp_helper.py | 6 +-- core/src/test/python/atp_helper_test.py | 51 +++++++++++++++++++ 2 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 core/src/test/python/atp_helper_test.py diff --git a/core/src/main/python/wlsdeploy/tool/create/atp_helper.py b/core/src/main/python/wlsdeploy/tool/create/atp_helper.py index fb5816afe..a8842f224 100644 --- a/core/src/main/python/wlsdeploy/tool/create/atp_helper.py +++ b/core/src/main/python/wlsdeploy/tool/create/atp_helper.py @@ -103,11 +103,11 @@ def cleanup_connect_string(connect_string): 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: diff --git a/core/src/test/python/atp_helper_test.py b/core/src/test/python/atp_helper_test.py new file mode 100644 index 000000000..2c005bfee --- /dev/null +++ b/core/src/test/python/atp_helper_test.py @@ -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