Search in sources :

Example 1 with SubjectAware

use of com.github.sdorra.shiro.SubjectAware in project scm-review-plugin by scm-manager.

the class PermissionCheckTest method shouldAllowModificationsForAuthor.

@Test
@SubjectAware(username = "trillian", password = "secret")
public void shouldAllowModificationsForAuthor() {
    BasicComment comment = createComment("trillian");
    boolean modificationsAllowed = PermissionCheck.mayModifyComment(createRepository(), comment);
    assertTrue(modificationsAllowed);
}
Also used : BasicComment(com.cloudogu.scm.review.comment.service.BasicComment) Test(org.junit.Test) SubjectAware(com.github.sdorra.shiro.SubjectAware)

Example 2 with SubjectAware

use of com.github.sdorra.shiro.SubjectAware in project scm-review-plugin by scm-manager.

the class PermissionCheckTest method shouldDisallowModificationsForNonAuthorWithoutPermission.

@Test
@SubjectAware(username = "trillian", password = "secret")
public void shouldDisallowModificationsForNonAuthorWithoutPermission() {
    BasicComment comment = createComment("other");
    boolean modificationsAllowed = PermissionCheck.mayModifyComment(createRepository(), comment);
    assertFalse(modificationsAllowed);
}
Also used : BasicComment(com.cloudogu.scm.review.comment.service.BasicComment) Test(org.junit.Test) SubjectAware(com.github.sdorra.shiro.SubjectAware)

Example 3 with SubjectAware

use of com.github.sdorra.shiro.SubjectAware in project scm-review-plugin by scm-manager.

the class PermissionCheckTest method shouldFailOnModificationsForNonAuthorWithoutPermission.

@Test(expected = UnauthorizedException.class)
@SubjectAware(username = "trillian", password = "secret")
public void shouldFailOnModificationsForNonAuthorWithoutPermission() {
    BasicComment comment = createComment("other");
    PermissionCheck.checkModifyComment(createRepository(), comment);
}
Also used : BasicComment(com.cloudogu.scm.review.comment.service.BasicComment) Test(org.junit.Test) SubjectAware(com.github.sdorra.shiro.SubjectAware)

Example 4 with SubjectAware

use of com.github.sdorra.shiro.SubjectAware in project scm-review-plugin by scm-manager.

the class CommentRootResourceTest method shouldNotThrowConflictExceptionIfNoExpectationsInUrl.

@Test
@SubjectAware(username = "slarti", password = "secret")
public void shouldNotThrowConflictExceptionIfNoExpectationsInUrl() throws URISyntaxException, UnsupportedEncodingException {
    when(pullRequestService.get(any(), any(), any())).thenReturn(PULL_REQUEST);
    when(branchRevisionResolver.getRevisions(any(), eq(PULL_REQUEST))).thenReturn(new BranchRevisionResolver.RevisionResult("source", "target"));
    byte[] commentJson = "{\"comment\" : \"this is my comment\"}".getBytes();
    MockHttpRequest request = MockHttpRequest.post("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/space/name/1/comments").content(commentJson).contentType(MediaType.APPLICATION_JSON);
    dispatcher.invoke(request, response);
    assertEquals(HttpServletResponse.SC_CREATED, response.getStatus());
}
Also used : MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) BranchRevisionResolver(com.cloudogu.scm.review.pullrequest.dto.BranchRevisionResolver) Test(org.junit.Test) SubjectAware(com.github.sdorra.shiro.SubjectAware)

Example 5 with SubjectAware

use of com.github.sdorra.shiro.SubjectAware in project scm-review-plugin by scm-manager.

the class CommentRootResourceTest method shouldNotThrowConflictExceptionIfOnlyOneExpectationInUrl.

@Test
@SubjectAware(username = "slarti", password = "secret")
public void shouldNotThrowConflictExceptionIfOnlyOneExpectationInUrl() throws URISyntaxException, UnsupportedEncodingException {
    when(pullRequestService.get(any(), any(), any())).thenReturn(PULL_REQUEST);
    when(branchRevisionResolver.getRevisions(any(), eq(PULL_REQUEST))).thenReturn(new BranchRevisionResolver.RevisionResult("source", "target"));
    byte[] commentJson = "{\"comment\" : \"this is my comment\"}".getBytes();
    MockHttpRequest request = MockHttpRequest.post("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/space/name/1/comments?sourceRevision=source").content(commentJson).contentType(MediaType.APPLICATION_JSON);
    dispatcher.invoke(request, response);
    assertEquals(HttpServletResponse.SC_CREATED, response.getStatus());
}
Also used : MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) BranchRevisionResolver(com.cloudogu.scm.review.pullrequest.dto.BranchRevisionResolver) Test(org.junit.Test) SubjectAware(com.github.sdorra.shiro.SubjectAware)

Aggregations

SubjectAware (com.github.sdorra.shiro.SubjectAware)91 Test (org.junit.Test)91 MockHttpRequest (org.jboss.resteasy.mock.MockHttpRequest)45 Comment.createComment (com.cloudogu.scm.review.comment.service.Comment.createComment)27 JsonNode (com.fasterxml.jackson.databind.JsonNode)18 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)16 PullRequest (com.cloudogu.scm.review.pullrequest.service.PullRequest)14 Reply.createReply (com.cloudogu.scm.review.comment.service.Reply.createReply)12 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)12 TestData.createPullRequest (com.cloudogu.scm.review.TestData.createPullRequest)11 Repository (sonia.scm.repository.Repository)9 BasicComment (com.cloudogu.scm.review.comment.service.BasicComment)6 BranchRevisionResolver (com.cloudogu.scm.review.pullrequest.dto.BranchRevisionResolver)6 HalEnricherContext (sonia.scm.api.v2.resources.HalEnricherContext)6 NamespaceAndName (sonia.scm.repository.NamespaceAndName)6 DisplayUser (sonia.scm.user.DisplayUser)6 User (sonia.scm.user.User)6 Changeset (sonia.scm.repository.Changeset)5 Comment (com.cloudogu.scm.review.comment.service.Comment)4 ShiroRule (com.github.sdorra.shiro.ShiroRule)3