Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
package org.openmrs.module.openconceptlab;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.text.StringEscapeUtils;
Comment thread
ibacher marked this conversation as resolved.
import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.criterion.Order;
Expand Down Expand Up @@ -363,13 +364,13 @@ public Subscription getSubscription() {
return null;
}
Subscription subscription = new Subscription();
subscription.setUrl(url);
subscription.setUrl(StringEscapeUtils.unescapeHtml4(url));

String uuid = adminService.getGlobalProperty(OpenConceptLabConstants.GP_SUBSCRIPTION_UUID);
subscription.setUuid(uuid);

String token = adminService.getGlobalProperty(OpenConceptLabConstants.GP_TOKEN);
subscription.setToken(token);
subscription.setToken(StringEscapeUtils.unescapeHtml4(token));

String validationType = adminService.getGlobalProperty(OpenConceptLabConstants.GP_VALIDATION_TYPE);
if (StringUtils.isNotBlank(validationType)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,27 @@ public void saveSubscription_shouldSaveSubscription() throws Exception {
assertThat(subscription, is(newSubscription));
}

/**
* @see ImportServiceImpl#getSubscription()
* @Verifies unescapes HTML entities in token and URL from global properties
*/
@Test
public void getSubscription_shouldUnescapeHtmlEntitiesInTokenAndUrl() throws Exception {
String escapedToken = "abc&def<ghi";
String expectedToken = "abc&def<ghi";
String escapedUrl = "http://api.openconceptlab.com/orgs/test?a=1&amp;b=2";
String expectedUrl = "http://api.openconceptlab.com/orgs/test?a=1&b=2";

Context.getAdministrationService()
.setGlobalProperty(OpenConceptLabConstants.GP_SUBSCRIPTION_URL, escapedUrl);
Context.getAdministrationService()
.setGlobalProperty(OpenConceptLabConstants.GP_TOKEN, escapedToken);

Subscription subscription = importService.getSubscription();
assertThat(subscription.getUrl(), is(expectedUrl));
assertThat(subscription.getToken(), is(expectedToken));
}

/*
* These ignored tests are working fine,
* but it takes too much time to finish them
Expand Down
Loading