Skip to content

Commit fa39251

Browse files
author
Luca Giamminonni
committed
[DURACOM-192] Added test
1 parent 6504d74 commit fa39251

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

dspace-server-webapp/src/test/java/org/dspace/app/rest/AuthenticationRestControllerIT.java

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
package org.dspace.app.rest;
99

1010
import static java.lang.Thread.sleep;
11+
import static org.dspace.app.rest.matcher.GroupMatcher.matchGroupWithName;
1112
import static org.dspace.app.rest.utils.RegexUtils.REGEX_UUID;
1213
import static org.hamcrest.Matchers.containsString;
1314
import static org.hamcrest.Matchers.endsWith;
@@ -1641,6 +1642,71 @@ public void testOrcidLoginURL() throws Exception {
16411642
}
16421643
}
16431644

1645+
@Test
1646+
public void testAreSpecialGroupsApplicable() throws Exception {
1647+
context.turnOffAuthorisationSystem();
1648+
1649+
GroupBuilder.createGroup(context)
1650+
.withName("specialGroupPwd")
1651+
.build();
1652+
GroupBuilder.createGroup(context)
1653+
.withName("specialGroupShib")
1654+
.build();
1655+
1656+
configurationService.setProperty("plugin.sequence.org.dspace.authenticate.AuthenticationMethod", SHIB_AND_PASS);
1657+
configurationService.setProperty("authentication-password.login.specialgroup", "specialGroupPwd");
1658+
configurationService.setProperty("authentication-shibboleth.role.faculty", "specialGroupShib");
1659+
configurationService.setProperty("authentication-shibboleth.default-roles", "faculty");
1660+
1661+
context.restoreAuthSystemState();
1662+
1663+
String passwordToken = getAuthToken(eperson.getEmail(), password);
1664+
1665+
getClient(passwordToken).perform(get("/api/authn/status").param("projection", "full"))
1666+
.andExpect(status().isOk())
1667+
.andExpect(jsonPath("$", AuthenticationStatusMatcher.matchFullEmbeds()))
1668+
.andExpect(jsonPath("$", AuthenticationStatusMatcher.matchLinks()))
1669+
.andExpect(content().contentType(contentType))
1670+
.andExpect(jsonPath("$.okay", is(true)))
1671+
.andExpect(jsonPath("$.authenticated", is(true)))
1672+
.andExpect(jsonPath("$.authenticationMethod", is("password")))
1673+
.andExpect(jsonPath("$.type", is("status")))
1674+
.andExpect(jsonPath("$._links.specialGroups.href", startsWith(REST_SERVER_URL)))
1675+
.andExpect(jsonPath("$._embedded.specialGroups._embedded.specialGroups",
1676+
Matchers.containsInAnyOrder(matchGroupWithName("specialGroupPwd"))));
1677+
1678+
getClient(passwordToken).perform(get("/api/authn/status/specialGroups").param("projection", "full"))
1679+
.andExpect(status().isOk())
1680+
.andExpect(content().contentType(contentType))
1681+
.andExpect(jsonPath("$._embedded.specialGroups",
1682+
Matchers.containsInAnyOrder(matchGroupWithName("specialGroupPwd"))));
1683+
1684+
String shibToken = getClient().perform(post("/api/authn/login")
1685+
.requestAttr("SHIB-MAIL", eperson.getEmail())
1686+
.requestAttr("SHIB-SCOPED-AFFILIATION", "faculty;staff"))
1687+
.andExpect(status().isOk())
1688+
.andReturn().getResponse().getHeader(AUTHORIZATION_HEADER).replace(AUTHORIZATION_TYPE, "");
1689+
1690+
getClient(shibToken).perform(get("/api/authn/status").param("projection", "full"))
1691+
.andExpect(status().isOk())
1692+
.andExpect(jsonPath("$", AuthenticationStatusMatcher.matchFullEmbeds()))
1693+
.andExpect(jsonPath("$", AuthenticationStatusMatcher.matchLinks()))
1694+
.andExpect(content().contentType(contentType))
1695+
.andExpect(jsonPath("$.okay", is(true)))
1696+
.andExpect(jsonPath("$.authenticated", is(true)))
1697+
.andExpect(jsonPath("$.authenticationMethod", is("shibboleth")))
1698+
.andExpect(jsonPath("$.type", is("status")))
1699+
.andExpect(jsonPath("$._links.specialGroups.href", startsWith(REST_SERVER_URL)))
1700+
.andExpect(jsonPath("$._embedded.specialGroups._embedded.specialGroups",
1701+
Matchers.containsInAnyOrder(matchGroupWithName("specialGroupShib"))));
1702+
1703+
getClient(shibToken).perform(get("/api/authn/status/specialGroups").param("projection", "full"))
1704+
.andExpect(status().isOk())
1705+
.andExpect(content().contentType(contentType))
1706+
.andExpect(jsonPath("$._embedded.specialGroups",
1707+
Matchers.containsInAnyOrder(matchGroupWithName("specialGroupShib"))));
1708+
}
1709+
16441710
// Get a short-lived token based on an active login token
16451711
private String getShortLivedToken(String loginToken) throws Exception {
16461712
ObjectMapper mapper = new ObjectMapper();

0 commit comments

Comments
 (0)