Skip to content

Commit

Permalink
fix(NotificationUtils): Encode user email to retrieve push devices.
Browse files Browse the repository at this point in the history
  • Loading branch information
binh-dam-ibigroup committed Dec 19, 2023
1 parent fd0d143 commit eaf4f27
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@

import java.io.IOException;
import java.net.URI;
import java.net.URLEncoder;
import java.util.Map;

import static java.nio.charset.StandardCharsets.UTF_8;
import static org.opentripplanner.middleware.utils.ConfigUtils.getConfigPropertyAsText;

/**
Expand Down Expand Up @@ -327,7 +329,7 @@ public static int getPushInfo(String toUser) {
try {
Map<String, String> headers = Map.of("Accept", "application/json");
var httpResponse = HttpUtils.httpRequestRawResponse(
URI.create(PUSH_API_URL + "/devices/get?api_key=" + PUSH_API_KEY + "&user=" + toUser),
URI.create(getPushDevicesUrl(PUSH_API_URL + "/devices/get?api_key=" + PUSH_API_KEY + "&user=", toUser)),
1000,
HttpMethod.GET,
headers,
Expand All @@ -346,6 +348,10 @@ public static int getPushInfo(String toUser) {
return 0;
}

static String getPushDevicesUrl(String baseUrl, String toUser) {
return baseUrl + URLEncoder.encode(toUser, UTF_8);
}

/**
* Poll the push middleware for the number of devices registered to receive push notifications
* for the specified user, and update the corresponding field in memory and Mongo.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.junit.jupiter.params.provider.NullSource;
import org.junit.jupiter.params.provider.ValueSource;

import static org.opentripplanner.middleware.utils.NotificationUtils.getPushDevicesUrl;
import static org.opentripplanner.middleware.utils.NotificationUtils.getTwilioLocale;

/**
Expand All @@ -30,4 +31,14 @@ void canGetTwilioLocale() {
void twilioLocaleDefaultsToEnglish(String locale) {
Assertions.assertEquals("en", getTwilioLocale(locale));
}

@Test
void testGetPushDevicesUrl() {
String email = "[email protected]";
String base = "https://get.example.com/devices/?user=";
Assertions.assertEquals(
"https://get.example.com/devices/?user=first.last%2Bsuffix%40example.com",
getPushDevicesUrl(base, email)
);
}
}

0 comments on commit eaf4f27

Please sign in to comment.