Skip to content

Commit

Permalink
Do not hardcode invite API path
Browse files Browse the repository at this point in the history
  • Loading branch information
oharsta committed Sep 16, 2024
1 parent 0e96b3c commit ac46b54
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>org.openconext</groupId>
<artifactId>voot-service</artifactId>
<version>6.1.0-SNAPSHOT</version>
<version>6.1.0</version>
<packaging>jar</packaging>

<name>voot-service</name>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/voot/provider/InviteProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class InviteProvider extends AbstractProvider {

public InviteProvider(Configuration configuration) {
super(configuration);
groupMembershipsUrlTemplate = "%s/api/voot/%s";
groupMembershipsUrlTemplate = String.format("%s", configuration.url.endsWith("/") ? configuration.url : (configuration.url + "/"));
}

@Override
Expand All @@ -39,7 +39,7 @@ public boolean isExternalGroupProvider() {
public Set<Group> getGroupMemberships(String uid) {
LOG.debug("Calling getGroupMemberships for " + uid);

String uri = String.format(groupMembershipsUrlTemplate, configuration.url, uid);
String uri = groupMembershipsUrlTemplate + uid;
RequestEntity<List<Map<String, String>>> requestEntity = new RequestEntity<>(HttpMethod.GET, URI.create(uri));
return restTemplate.exchange(requestEntity, new ParameterizedTypeReference<List<Map<String, String>>>() {
}).getBody().stream()
Expand Down
21 changes: 19 additions & 2 deletions src/test/java/voot/provider/InviteProviderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
class InviteProviderTest extends AbstractTest {

private final InviteProvider subject = new InviteProvider(
new Provider.Configuration(GroupProviderType.INVITE, "http://localhost:8889",
new Provider.Configuration(GroupProviderType.INVITE, "http://localhost:8889/api/external/v1/voot",
new Provider.Configuration.Credentials("user", "password"),
2000, "N/A", "invite"));

@Test
void getGroupMemberships() throws IOException {
String json = IOUtils.readInputStreamToString(new ClassPathResource("json/invite/group_memberships.json").getInputStream());
String urn = "urn:collab:person:example.com:admin";
stubFor(get(urlPathEqualTo("/api/voot/" + urn))
stubFor(get(urlPathEqualTo("/api/external/v1/voot/" + urn))
.willReturn(aResponse()
.withStatus(200)
.withHeader("Content-type", "application/json").
Expand All @@ -34,6 +34,23 @@ void getGroupMemberships() throws IOException {
assertEquals(2, groupMemberships.size());
}

@Test
void getGroupMembershipsMissingSlash() throws IOException {
InviteProvider inviteProvider = new InviteProvider(
new Provider.Configuration(GroupProviderType.INVITE, "http://localhost:8889/api/voot/",
new Provider.Configuration.Credentials("user", "password"),
2000, "N/A", "invite"));
String json = IOUtils.readInputStreamToString(new ClassPathResource("json/invite/group_memberships.json").getInputStream());
String urn = "urn:collab:person:example.com:admin";
stubFor(get(urlPathEqualTo("/api/voot/" + urn))
.willReturn(aResponse()
.withStatus(200)
.withHeader("Content-type", "application/json").
withBody(json)));
Set<Group> groupMemberships = inviteProvider.getGroupMemberships(urn);
assertEquals(2, groupMemberships.size());
}

@Test
void getAllGroups() {
assertEquals(0, subject.getAllGroups().size());
Expand Down

0 comments on commit ac46b54

Please sign in to comment.