From 0cf45c919f6885c17afda241d5e565dad3de0e20 Mon Sep 17 00:00:00 2001 From: ashitsalesforce Date: Fri, 15 Nov 2024 16:32:03 -0800 Subject: [PATCH] fix for W-17247728 Fix for W-17247728 - sfdc.endpoint property (legacy property to specify Auth endpoint) is not correctly handled. --- .../dataloader/config/AppConfig.java | 19 +++++++----------- .../dataloader/config/ConfigTest.java | 20 +++++++++++++++++++ .../testfiles/conf/config.properties | 2 +- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/salesforce/dataloader/config/AppConfig.java b/src/main/java/com/salesforce/dataloader/config/AppConfig.java index 4ca23821..74d8894a 100644 --- a/src/main/java/com/salesforce/dataloader/config/AppConfig.java +++ b/src/main/java/com/salesforce/dataloader/config/AppConfig.java @@ -252,8 +252,8 @@ public class AppConfig { public static final String PROP_USERNAME = "sfdc.username"; //$NON-NLS-1$ public static final String PROP_PASSWORD = "sfdc.password"; //$NON-NLS-1$ public static final String PROP_AUTH_ENDPOINT_LEGACY = "sfdc.endpoint"; - public static final String PROP_AUTH_ENDPOINT_PROD = "sfdc.endpoint.production"; //$NON-NLS-1$ - public static final String PROP_AUTH_ENDPOINT_SANDBOX = "sfdc.endpoint.sandbox"; //$NON-NLS-1$ + public static final String PROP_AUTH_ENDPOINT_PROD = "sfdc.endpoint." + SERVER_PROD_ENVIRONMENT_VAL; //$NON-NLS-1$ + public static final String PROP_AUTH_ENDPOINT_SANDBOX = "sfdc.endpoint." + SERVER_SB_ENVIRONMENT_VAL; //$NON-NLS-1$ public static final String PROP_PROXY_HOST = "sfdc.proxyHost"; //$NON-NLS-1$ public static final String PROP_PROXY_PORT = "sfdc.proxyPort"; //$NON-NLS-1$ public static final String PROP_PROXY_USERNAME = "sfdc.proxyUsername"; //$NON-NLS-1$ @@ -626,16 +626,6 @@ private AppConfig(String filename, Map commandLineOptionsMap) th // Properties initialization completed. Configure OAuth environment next setServerEnvironment(getString(PROP_SELECTED_SERVER_ENVIRONMENT)); ConfigPropertyMetadata.generateCSV(this); - if (getString(PROP_AUTH_ENDPOINT_LEGACY) != null && - !getString(PROP_AUTH_ENDPOINT_LEGACY).isBlank()) { - String propToSet = PROP_AUTH_ENDPOINT_LEGACY + "." + getString(PROP_SELECTED_SERVER_ENVIRONMENT); - String currentValue = getString(propToSet); - if (currentValue == null || currentValue.isBlank() - || currentValue.startsWith(DEFAULT_ENDPOINT_URL_PROD) - || currentValue.startsWith(DEFAULT_ENDPOINT_URL_SANDBOX)) { - setValue(propToSet, getString(PROP_AUTH_ENDPOINT_LEGACY)); - } - } } private String getLastRunPrefix() { @@ -1381,6 +1371,11 @@ public String getAuthEndpointForCurrentEnv() { } else { endpoint = getString(AppConfig.PROP_AUTH_ENDPOINT_PROD); } + + // try with legacy endpoint property + if (endpoint == null || endpoint.isBlank()) { + endpoint = getString(PROP_AUTH_ENDPOINT_LEGACY); + } if (endpoint == null || endpoint.isBlank()) { endpoint = getDefaultAuthEndpointForCurrentEnv(); } diff --git a/src/test/java/com/salesforce/dataloader/config/ConfigTest.java b/src/test/java/com/salesforce/dataloader/config/ConfigTest.java index 3bff7132..4b9b6ad4 100644 --- a/src/test/java/com/salesforce/dataloader/config/ConfigTest.java +++ b/src/test/java/com/salesforce/dataloader/config/ConfigTest.java @@ -143,4 +143,24 @@ public void testProperty_OAUTH_REDIRECTURI() { fail("Failed to get config instance:", e); } } + + @Test + public void testProperty_PROP_AUTH_ENDPOINT_LEGACY() { + // This is to verify that legacy way to set the Auth endpoint continues to work. + try { + Map testConfigMap = getTestConfig(); + testConfigMap.put(AppConfig.PROP_AUTH_ENDPOINT_LEGACY, "https://mylegacyendpoint"); + AppConfig appConfig = AppConfig.getInstance(testConfigMap); + + // clear prod endpoint property so that legacy endpoint property is used + appConfig.setValue(AppConfig.PROP_AUTH_ENDPOINT_PROD, ""); + String configuredAuthEndpoint = appConfig.getAuthEndpointForCurrentEnv(); + assertTrue(configuredAuthEndpoint.startsWith("https://mylegacyendpoint")); + } catch (ConfigInitializationException + | FactoryConfigurationError + | IOException e) { + logger.error("Failed to get config instance: " + e.getMessage()); + fail("Failed to get config instance:", e); + } + } } diff --git a/src/test/resources/testfiles/conf/config.properties b/src/test/resources/testfiles/conf/config.properties index 2e3e19c4..d55164ca 100644 --- a/src/test/resources/testfiles/conf/config.properties +++ b/src/test/resources/testfiles/conf/config.properties @@ -1,6 +1,6 @@ ## config.properties used by dataloader tests -sfdc.endpoint.production=${test.endpoint} +sfdc.endpoint.Production=${test.endpoint} sfdc.resetUrlOnLogin=${test.redirect} sfdc.username=${test.user.default} sfdc.password=${test.password}