Skip to content

Commit

Permalink
fix for W-17247728
Browse files Browse the repository at this point in the history
Fix for W-17247728 - sfdc.endpoint property (legacy property to specify Auth endpoint) is not correctly handled.
  • Loading branch information
ashitsalesforce committed Nov 16, 2024
1 parent b3a0369 commit 0cf45c9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
19 changes: 7 additions & 12 deletions src/main/java/com/salesforce/dataloader/config/AppConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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$
Expand Down Expand Up @@ -626,16 +626,6 @@ private AppConfig(String filename, Map<String, String> 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() {
Expand Down Expand Up @@ -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();
}
Expand Down
20 changes: 20 additions & 0 deletions src/test/java/com/salesforce/dataloader/config/ConfigTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> 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);
}
}
}
2 changes: 1 addition & 1 deletion src/test/resources/testfiles/conf/config.properties
Original file line number Diff line number Diff line change
@@ -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}
Expand Down

0 comments on commit 0cf45c9

Please sign in to comment.