Skip to content
Open
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
12 changes: 6 additions & 6 deletions src/main/java/com/adyen/Service.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,15 @@ protected String createBaseURL(String url) {
}

if (url.contains("/authe/")) {
return url.replaceFirst("https://test.adyen.com/", "https://authe-live.adyen.com/");
return url.replace("https://test.adyen.com/", "https://authe-live.adyen.com/");
}

if (url.contains("pal-")) {
if (config.getLiveEndpointUrlPrefix() == null) {
throw new IllegalArgumentException("please provide a live url prefix in the client");
}
url =
url.replaceFirst(
url.replace(
"https://pal-test.adyen.com/pal/servlet/",
Comment on lines +102 to 103
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

While this change correctly fixes the regex wildcard issue for the pal- block, the same issue exists in the authe block (around line 94 in the full file), which still uses replaceFirst() with a search string containing literal dots (https://test.adyen.com/). Please consider updating that block as well to ensure consistent and correct URL transformation across all service types.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in the latest commit.

"https://"
+ config.getLiveEndpointUrlPrefix()
Expand All @@ -113,14 +113,14 @@ protected String createBaseURL(String url) {
if (url.contains("/possdk/")) {
// Custom handling of POS Mobile API url
url =
url.replaceFirst(
url.replace(
"https://checkout-test.adyen.com/",
"https://"
+ config.getLiveEndpointUrlPrefix()
+ "-checkout-live.adyenpayments.com/");
} else {
url =
url.replaceFirst(
url.replace(
"https://checkout-test.adyen.com/",
"https://"
+ config.getLiveEndpointUrlPrefix()
Expand All @@ -132,11 +132,11 @@ protected String createBaseURL(String url) {
if (config.getTerminalApiRegion() == null
|| config.getTerminalApiRegion().equals(Region.EU)) {
url =
url.replaceFirst(
url.replace(
"https://device-api-test.adyen.com", "https://device-api-live.adyen.com");
} else {
url =
url.replaceFirst(
url.replace(
"https://device-api-test.adyen.com",
String.format(
"https://device-api-live-%s.adyen.com",
Expand Down
15 changes: 15 additions & 0 deletions src/test/java/com/adyen/ServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,21 @@ public void testLivePalUrlWithPrefix() {
assertEquals(expectedUrl, actualUrl);
}

@Test
public void testLivePalUrlOnlyMatchesLiteralDots() {
config.setLiveEndpointUrlPrefix("123456789-company");
// This URL matches pal-test.adyen.com structurally but has non-dot separators.
// The old replaceFirst() would have incorrectly matched it (dots as wildcards).
// String.replace() does exact literal matching so the pal- block leaves it unchanged.
// The final fallback still converts -test to -live as expected.
String urlWithNonDots = "https://pal-testXadyenYcom/pal/servlet/v52/initiate";
String expectedUrl = "https://pal-liveXadyenYcom/pal/servlet/v52/initiate";

String actualUrl = service.createBaseURL(urlWithNonDots);

assertEquals(expectedUrl, actualUrl);
}
Comment on lines +61 to +74
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The test case testLivePalUrlOnlyMatchesLiteralDots does not effectively verify the fix for the regex wildcard issue. The test string https://pal-devXadyenYcom/... would not match the target https://pal-test.adyen.com/... even if dots were treated as wildcards, because dev does not match test. To properly verify that dots are matched literally and not as wildcards, the test should use a string where only the dots are changed, such as https://pal-testXadyenYcom/....

Suggested change
@Test
public void testLivePalUrlOnlyMatchesLiteralDots() {
config.setLiveEndpointUrlPrefix("123456789-company");
// A URL where dots are replaced with other characters should NOT be transformed
// by the pal- block. String.replace() does exact literal matching, so a URL that
// looks like a pal URL but has non-dot separators passes through untouched.
String urlWithNonDots = "https://pal-devXadyenYcom/pal/servlet/v52/initiate";
String actualUrl = service.createBaseURL(urlWithNonDots);
assertEquals(urlWithNonDots, actualUrl);
}
@Test
public void testLivePalUrlOnlyMatchesLiteralDots() {
config.setLiveEndpointUrlPrefix("123456789-company");
// A URL where dots are replaced with other characters should NOT be transformed
// by the pal- block. String.replace() does exact literal matching, so a URL that
// would match if dots were wildcards (regex) but has non-dot separators passes through untouched.
String urlWithNonDots = "https://pal-testXadyenYcom/pal/servlet/v52/initiate";
String actualUrl = service.createBaseURL(urlWithNonDots);
assertEquals(urlWithNonDots, actualUrl);
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the test to use pal-testXadyenYcom so the URL structurally
matches pal-test.adyen.com but with non-dot separators. The expected
value accounts for the final -test → -live fallback.


@Test
public void testLivePalUrlWithoutPrefix() {
String testUrl = "https://pal-test.adyen.com/pal/servlet/v52/initiate";
Expand Down