Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
federicaagostini committed Nov 14, 2024
1 parent 25007dd commit 7f333e7
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.log;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.redirectedUrl;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

import java.util.Date;
Expand Down Expand Up @@ -765,4 +766,29 @@ public void aupUpdateWorks() throws Exception {
assertThat(updatedAup.getSignatureValidityInDays(), equalTo(31L));
}

@Test
public void anonymousAupSignLinkRedirectsToLoginPage() throws Exception {
mvc.perform(get("/iam/aup/sign"))
.andExpect(status().is3xxRedirection())
.andExpect(redirectedUrl("http://localhost/login"));
}

@Test
@WithMockUser(username = "actuator-user", roles = {"ACTUATOR"})
public void aupSignLinkForbiddenToActuatorUser() throws Exception {
mvc.perform(get("/iam/aup/sign")).andExpect(status().isForbidden());
}

@Test
@WithMockUser(username = "test", roles = {"USER"})
public void aupSignLinkAllowedToUsers() throws Exception {
mvc.perform(get("/iam/aup/sign")).andExpect(status().isOk());
}

@Test
@WithMockUser(username = "admin", roles = {"ADMIN", "USER"})
public void aupSignLinkAllowedToAdmins() throws Exception {
mvc.perform(get("/iam/aup/sign")).andExpect(status().isOk());
}

}

0 comments on commit 7f333e7

Please sign in to comment.