Skip to content

Commit

Permalink
Fixing #2245 by checking for and removing https:// if supplied so the…
Browse files Browse the repository at this point in the history
… user can either supply or not
  • Loading branch information
klcodanr committed Apr 2, 2020
1 parent 50e85a5 commit d27bd31
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ public String getClientSecret() {

@Override
public String getEndpointHost() {
if(endpointHost.startsWith("https://")){
return endpointHost.substring(8);
}
return endpointHost;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void init() {

configrr = Mockito.mock(ConfigurationResourceResolver.class);
Mockito.when(configrr.getResourceCollection(Mockito.any(), Mockito.any(), Mockito.any()))
.thenReturn(Collections.singletonList(context.resourceResolver().getResource("/conf/test")));
.thenReturn(Collections.singletonList(context.resourceResolver().getResource("/conf/test/default")));
context.registerService(ConfigurationResourceResolver.class, configrr);

}
Expand All @@ -68,7 +68,7 @@ public void testConfigMgr() {
@Test
public void testConfig() {
MarketoClientConfiguration mcc = Optional
.ofNullable(context.resourceResolver().getResource("/conf/test/jcr:content"))
.ofNullable(context.resourceResolver().getResource("/conf/test/default/jcr:content"))
.map(r -> r.adaptTo(MarketoClientConfiguration.class)).orElse(null);
assertNotNull(mcc);
assertEquals("123", mcc.getClientId());
Expand All @@ -79,9 +79,19 @@ public void testConfig() {
assertEquals(48721, mcc.hashCode());

MarketoClientConfiguration mcc2 = Optional
.ofNullable(context.resourceResolver().getResource("/conf/test/jcr:content"))
.ofNullable(context.resourceResolver().getResource("/conf/test/default/jcr:content"))
.map(r -> r.adaptTo(MarketoClientConfiguration.class)).orElse(null);
assertEquals(mcc, mcc2);
assertNotEquals(mcc, null);
}


@Test
public void testHttps() {
MarketoClientConfiguration mcc = Optional
.ofNullable(context.resourceResolver().getResource("/conf/test/https/jcr:content"))
.map(r -> r.adaptTo(MarketoClientConfiguration.class)).orElse(null);
assertNotNull(mcc);
assertEquals("test.mktorest.com", mcc.getEndpointHost());
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
{
"jcr:primaryType": "cq:Page",
"jcr:content": {
"jcr:primaryType": "cq:PageContent",
"jcr:title": "Test Cloud Config",
"cq:template": "/apps/acs-commons/templates/utilities/marketocloudconfig",
"sling:resourceType": "page",
"endpointHost": "test.mktorest.com",
"serverInstance": "//test.marketo.com",
"munchkinId": "123-456-789",
"clientId": "123",
"clientSecret": "456"
"jcr:primaryType": "sling:Folder",
"default": {
"jcr:primaryType": "cq:Page",
"jcr:content": {
"jcr:primaryType": "cq:PageContent",
"jcr:title": "Test Cloud Config",
"cq:template": "/apps/acs-commons/templates/utilities/marketocloudconfig",
"sling:resourceType": "page",
"endpointHost": "test.mktorest.com",
"serverInstance": "//test.marketo.com",
"munchkinId": "123-456-789",
"clientId": "123",
"clientSecret": "456"
}
},
"https": {
"jcr:primaryType": "cq:Page",
"jcr:content": {
"jcr:primaryType": "cq:PageContent",
"jcr:title": "Test Cloud Config",
"cq:template": "/apps/acs-commons/templates/utilities/marketocloudconfig",
"sling:resourceType": "page",
"endpointHost": "https://test.mktorest.com",
"serverInstance": "//test.marketo.com",
"munchkinId": "123-456-789",
"clientId": "123",
"clientSecret": "456"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"jcr:content": {
"jcr:primaryType": "cq:PageContent",
"jcr:title": "English",
"cq:conf": "/conf/test",
"cq:conf": "/conf/test/default",
"sling:resourceType": "weretail/components/structure/page",
"root": {
"jcr:primaryType": "nt:unstructured",
Expand Down

0 comments on commit d27bd31

Please sign in to comment.