1414
1515import java .io .InputStream ;
1616
17+ import com .fasterxml .jackson .databind .JsonNode ;
1718import com .fasterxml .jackson .databind .ObjectMapper ;
1819import org .apache .commons .codec .CharEncoding ;
1920import org .apache .commons .io .IOUtils ;
@@ -55,7 +56,6 @@ public class ClarinShibbolethSpecialGroupsIT extends AbstractControllerIntegrati
5556 public static final String [] SHIB_ONLY = {"org.dspace.authenticate.clarin.ClarinShibAuthentication" };
5657 private static final String NET_ID_TEST_EPERSON = "123456789" ;
5758 private static final String IDP_TEST_EPERSON = "Test Idp" ;
58- private static final String AUTHORIZATION_TYPE = "Bearer " ;
5959
6060 private EPerson clarinEperson ;
6161 private Bitstream restrictedBitstream ;
@@ -146,10 +146,11 @@ public void shouldKeepSpecialGroupsAfterLoginTokenRefresh() throws Exception {
146146 .andExpect (status ().isOk ());
147147
148148 // Refresh the login token on a stateless request (no shibboleth session/headers)
149- String refreshedToken = getClient (loginToken ).perform (post ("/api/authn/login" ))
149+ String refreshedAuthHeader = getClient (loginToken ).perform (post ("/api/authn/login" ))
150150 .andExpect (status ().isOk ())
151- .andReturn ().getResponse ().getHeader ("Authorization" )
152- .replace (AUTHORIZATION_TYPE , "" );
151+ .andReturn ().getResponse ().getHeader (AUTHORIZATION_HEADER );
152+ assertNotNull ("The token refresh must return the Authorization header" , refreshedAuthHeader );
153+ String refreshedToken = refreshedAuthHeader .replace (AUTHORIZATION_TYPE , "" );
153154
154155 // The restricted bitstream must still be readable with the refreshed token
155156 getClient (refreshedToken ).perform (get ("/api/core/bitstreams/" + restrictedBitstream .getID () + "/content" ))
@@ -162,7 +163,7 @@ private String shibLogin() throws Exception {
162163 .header ("Shib-Identity-Provider" , IDP_TEST_EPERSON )
163164 .header ("SHIB-NETID" , NET_ID_TEST_EPERSON ))
164165 .andExpect (status ().is3xxRedirection ())
165- .andReturn ().getResponse ().getHeader ("Authorization" );
166+ .andReturn ().getResponse ().getHeader (AUTHORIZATION_HEADER );
166167 assertNotNull ("The shibboleth login must return the Authorization header" , authHeader );
167168 return authHeader .replace (AUTHORIZATION_TYPE , "" );
168169 }
@@ -173,6 +174,8 @@ private String getShortLivedToken(String loginToken) throws Exception {
173174 .andExpect (status ().isOk ())
174175 .andReturn ();
175176 String content = mvcResult .getResponse ().getContentAsString ();
176- return mapper .readTree (content ).get ("token" ).asText ();
177+ JsonNode token = mapper .readTree (content ).get ("token" );
178+ assertNotNull ("The shortlivedtokens response must contain the token field" , token );
179+ return token .asText ();
177180 }
178181}
0 commit comments