Skip to content

Commit d17915e

Browse files
milanmajchrakclaude
andcommitted
ZCU-DATA/test: resolve Copilot review comments
- reuse AUTHORIZATION_HEADER/AUTHORIZATION_TYPE from AbstractControllerIntegrationTest - assert the Authorization header and the token field are present before using them Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 76ecb40 commit d17915e

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
import java.io.InputStream;
1616

17+
import com.fasterxml.jackson.databind.JsonNode;
1718
import com.fasterxml.jackson.databind.ObjectMapper;
1819
import org.apache.commons.codec.CharEncoding;
1920
import 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

Comments
 (0)