forked from DSpace/DSpace
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ufal/be-shibboleth-headers-encoding (#464)
* givenname and last name values are converted to UTF-8 encoding * Delete eperson in tests
- Loading branch information
1 parent
e2322c5
commit c01af03
Showing
4 changed files
with
115 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -446,15 +446,18 @@ public void testRedirectToGivenUntrustedUrl() throws Exception { | |
} | ||
|
||
@Test | ||
public void testUTF8ShibHeaders() throws Exception { | ||
public void testISOShibHeaders() throws Exception { | ||
String testMail = "[email protected]"; | ||
String testIdp = IDP_TEST_EPERSON + "test"; | ||
String testNetId = NET_ID_TEST_EPERSON + "000"; | ||
// NOTE: The initial call to /shibboleth comes *from* an external Shibboleth site. So, it is always | ||
// unauthenticated, but it must include some expected SHIB attributes. | ||
// SHIB-MAIL attribute is the default email header sent from Shibboleth after a successful login. | ||
// In this test we are simply mocking that behavior by setting it to an existing EPerson. | ||
String token = getClient().perform(get("/api/authn/shibboleth") | ||
.header("SHIB-MAIL", clarinEperson.getEmail()) | ||
.header("Shib-Identity-Provider", IDP_TEST_EPERSON) | ||
.header("SHIB-NETID", NET_ID_TEST_EPERSON) | ||
.header("SHIB-MAIL", testMail) | ||
.header("Shib-Identity-Provider", testIdp) | ||
.header("SHIB-NETID", testNetId) | ||
.header("SHIB-GIVENNAME", "knihovna KůÅ\u0088 test ŽluÅ¥ouÄ\u008Dký")) | ||
.andExpect(status().is3xxRedirection()) | ||
.andExpect(redirectedUrl("http://localhost:4000")) | ||
|
@@ -466,6 +469,56 @@ public void testUTF8ShibHeaders() throws Exception { | |
.andExpect(jsonPath("$.authenticated", is(true))) | ||
.andExpect(jsonPath("$.authenticationMethod", is("shibboleth"))); | ||
|
||
// Check if was created a user with such email and netid. | ||
EPerson ePerson = ePersonService.findByNetid(context, Util.formatNetId(testNetId, testIdp)); | ||
assertTrue(Objects.nonNull(ePerson)); | ||
assertEquals(ePerson.getEmail(), testMail); | ||
assertEquals(ePerson.getFirstName(), "knihovna Kůň test Žluťoučký"); | ||
|
||
EPersonBuilder.deleteEPerson(ePerson.getID()); | ||
|
||
getClient(token).perform( | ||
get("/api/authz/authorizations/search/object") | ||
.param("embed", "feature") | ||
.param("feature", feature) | ||
.param("uri", utils.linkToSingleResource(ePersonRest, "self").getHref())) | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("$.page.totalElements", is(0))) | ||
.andExpect(jsonPath("$._embedded").doesNotExist()); | ||
} | ||
|
||
@Test | ||
public void testUTF8ShibHeaders() throws Exception { | ||
String testMail = "[email protected]"; | ||
String testIdp = IDP_TEST_EPERSON + "test"; | ||
String testNetId = NET_ID_TEST_EPERSON + "000"; | ||
// NOTE: The initial call to /shibboleth comes *from* an external Shibboleth site. So, it is always | ||
// unauthenticated, but it must include some expected SHIB attributes. | ||
// SHIB-MAIL attribute is the default email header sent from Shibboleth after a successful login. | ||
// In this test we are simply mocking that behavior by setting it to an existing EPerson. | ||
String token = getClient().perform(get("/api/authn/shibboleth") | ||
.header("SHIB-MAIL", testMail) | ||
.header("Shib-Identity-Provider", testIdp) | ||
.header("SHIB-NETID", testNetId) | ||
.header("SHIB-GIVENNAME", "knihovna Kůň test Žluťoučký")) | ||
.andExpect(status().is3xxRedirection()) | ||
.andExpect(redirectedUrl("http://localhost:4000")) | ||
.andReturn().getResponse().getHeader("Authorization"); | ||
|
||
|
||
getClient(token).perform(get("/api/authn/status")) | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("$.authenticated", is(true))) | ||
.andExpect(jsonPath("$.authenticationMethod", is("shibboleth"))); | ||
|
||
// Check if was created a user with such email and netid. | ||
EPerson ePerson = ePersonService.findByNetid(context, Util.formatNetId(testNetId, testIdp)); | ||
assertTrue(Objects.nonNull(ePerson)); | ||
assertEquals(ePerson.getEmail(), testMail); | ||
assertEquals(ePerson.getFirstName(), "knihovna Kůň test Žluťoučký"); | ||
|
||
EPersonBuilder.deleteEPerson(ePerson.getID()); | ||
|
||
getClient(token).perform( | ||
get("/api/authz/authorizations/search/object") | ||
.param("embed", "feature") | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters