use of org.springframework.security.test.context.support.WithAnonymousUser in project code-chill by CodeChillAlluna.
the class AuthenticationRestControllerTest method successfulAuthenticationWithAnonymousUser.
@Test
@WithAnonymousUser
public void successfulAuthenticationWithAnonymousUser() throws Exception {
JwtAuthenticationRequest jwtAuthenticationRequest = new JwtAuthenticationRequest("user", "password");
this.mvc.perform(post("/auth").contentType(MediaType.APPLICATION_JSON).content(new ObjectMapper().writeValueAsString(jwtAuthenticationRequest))).andExpect(status().is2xxSuccessful());
}
use of org.springframework.security.test.context.support.WithAnonymousUser in project uhgroupings by uhawaii-system-its-ti-iam.
the class HomeControllerTest method loginViaAnonymous.
@Test
@WithAnonymousUser
public void loginViaAnonymous() throws Exception {
MvcResult mvcResult = mockMvc.perform(get("/login")).andExpect(status().is3xxRedirection()).andExpect(status().is(302)).andExpect(redirectedUrlPattern(casLoginUrl + "**")).andReturn();
assertNotNull(mvcResult);
}
use of org.springframework.security.test.context.support.WithAnonymousUser in project pivotal-cla by pivotalsoftware.
the class ClaControllerTests method viewSignedWithRepositoryIdAndPullRequestIdNewUser.
@Test
@WithAnonymousUser
public void viewSignedWithRepositoryIdAndPullRequestIdNewUser() throws Exception {
String repositoryId = "spring-projects/spring-security";
User signingUser = WithSigningUserFactory.create();
when(mockGitHub.getCurrentUser(any())).thenReturn(signingUser);
when(mockGitHub.getShaForPullRequest(any(PullRequestStatus.class))).thenReturn("abc123");
when(mockIndividualSignatureRepository.findSignaturesFor(any(), eq(signingUser), eq(cla.getName()))).thenReturn(Arrays.asList(individualSignature));
when(mockIndividualSignatureRepository.findSignaturesFor(any(), eq(signingUser))).thenReturn(Arrays.asList(individualSignature));
when(mockTokenRepo.findOne(repositoryId)).thenReturn(new AccessToken(repositoryId, "access-token-123"));
int pullRequestId = 123;
SignClaPage home = SignClaPage.go(driver, cla.getName(), repositoryId, pullRequestId);
home.assertAt();
home.assertClaLinksWithPullRequest(cla.getName(), repositoryId, pullRequestId);
home.assertPullRequestLink(repositoryId, pullRequestId);
home.assertImported();
ArgumentCaptor<PullRequestStatus> updatePullRequestCaptor = ArgumentCaptor.forClass(PullRequestStatus.class);
verify(mockGitHub).save(updatePullRequestCaptor.capture());
PullRequestStatus updatePr = updatePullRequestCaptor.getValue();
String commitStatusUrl = "http://localhost/sign/" + cla.getName() + "?repositoryId=" + repositoryId + "&pullRequestId=" + pullRequestId;
assertThat(updatePr.getUrl()).isEqualTo(commitStatusUrl);
assertThat(updatePr.getGitHubUsername()).isEqualTo(signingUser.getGitHubLogin());
assertThat(updatePr.getPullRequestId()).isEqualTo(pullRequestId);
assertThat(updatePr.getRepoId()).isEqualTo(repositoryId);
}
use of org.springframework.security.test.context.support.WithAnonymousUser in project pivotal-cla by pivotalsoftware.
the class IclaControllerTests method view.
@Test
@WithAnonymousUser
public void view() {
when(mockClaRepository.findByNameAndPrimaryTrue(cla.getName())).thenReturn(cla);
ViewIclaPage signPage = ViewIclaPage.go(getDriver(), cla.getName());
assertThat(signPage.getIndividualCla()).isEqualTo(cla.getIndividualContent().getHtml());
}
use of org.springframework.security.test.context.support.WithAnonymousUser in project nixmash-blog by mintster.
the class AdminControllerTests method anonymousCannotAccessAdmin.
@Test
@WithAnonymousUser
public void anonymousCannotAccessAdmin() throws Exception {
// Whereas Erwin is forbidden, anonymous users redirected to login page
RequestBuilder request = get("/admin").with(csrf());
mvc.perform(request).andExpect(status().is3xxRedirection()).andExpect(loginPage());
}
Aggregations