Search in sources :

Example 51 with SubjectAware

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

the class PullRequestRootResourceTest method shouldGetUnauthorizedExceptionWhenMissingPermissionOnCreatePR.

@Test
@SubjectAware(username = "trillian")
public void shouldGetUnauthorizedExceptionWhenMissingPermissionOnCreatePR() throws URISyntaxException, IOException {
    byte[] pullRequestJson = loadJson("com/cloudogu/scm/review/pullRequest.json");
    MockHttpRequest request = MockHttpRequest.post("/" + PullRequestRootResource.PULL_REQUESTS_PATH_V2 + "/space/name").content(pullRequestJson).contentType(PullRequestMediaType.PULL_REQUEST);
    dispatcher.invoke(request, response);
    assertEquals(HttpServletResponse.SC_FORBIDDEN, response.getStatus());
}
Also used : MockHttpRequest(org.jboss.resteasy.mock.MockHttpRequest) Test(org.junit.Test) SubjectAware(com.github.sdorra.shiro.SubjectAware)

Example 52 with SubjectAware

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

the class PermissionCheckTest method shouldNotFailOnModificationsForAuthor.

@Test
@SubjectAware(username = "trillian", password = "secret")
public void shouldNotFailOnModificationsForAuthor() {
    BasicComment comment = createComment("trillian");
    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 53 with SubjectAware

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

the class PermissionCheckTest method shouldAllowModificationsForPushPermission.

@Test
@SubjectAware(username = "slarti", password = "secret")
public void shouldAllowModificationsForPushPermission() {
    BasicComment comment = createComment("author");
    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 54 with SubjectAware

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

the class PermissionCheckTest method shouldNotFailOnModificationsForPushPermission.

@Test
@SubjectAware(username = "slarti", password = "secret")
public void shouldNotFailOnModificationsForPushPermission() {
    BasicComment comment = createComment("trillian");
    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 55 with SubjectAware

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

the class PullRequestInformationHookTest method shouldSendMessageWithoutCreateLinks.

@Test
@SubjectAware(username = "dent")
public void shouldSendMessageWithoutCreateLinks() throws Exception {
    when(branchProvider.getCreatedOrModified()).thenReturn(singletonList("branch_1"));
    when(service.getBranchesCommand()).thenReturn(branchesCommand);
    Branches branches = new Branches(Branch.defaultBranch("main", "", 0L));
    when(branchesCommand.getBranches()).thenReturn(branches);
    hook.checkForInformation(event);
    List<String> sentMessages = messageCaptor.getAllValues();
    assertThat(sentMessages).filteredOn(s -> s.length() > 0).isEmpty();
}
Also used : Branch(sonia.scm.repository.Branch) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BranchesCommandBuilder(sonia.scm.repository.api.BranchesCommandBuilder) ShiroRule(com.github.sdorra.shiro.ShiroRule) Mock(org.mockito.Mock) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) HookContext(sonia.scm.repository.api.HookContext) Captor(org.mockito.Captor) Repository(sonia.scm.repository.Repository) PullRequest(com.cloudogu.scm.review.pullrequest.service.PullRequest) Collections.singletonList(java.util.Collections.singletonList) ArgumentCaptor(org.mockito.ArgumentCaptor) Arrays.asList(java.util.Arrays.asList) RepositoryServiceFactory(sonia.scm.repository.api.RepositoryServiceFactory) RepositoryService(sonia.scm.repository.api.RepositoryService) PullRequestService(com.cloudogu.scm.review.pullrequest.service.PullRequestService) Branches(sonia.scm.repository.Branches) HookMessageProvider(sonia.scm.repository.api.HookMessageProvider) Before(org.junit.Before) InjectMocks(org.mockito.InjectMocks) ScmConfiguration(sonia.scm.config.ScmConfiguration) Command(sonia.scm.repository.api.Command) MESSAGE_PROVIDER(sonia.scm.repository.api.HookFeature.MESSAGE_PROVIDER) Test(org.junit.Test) IOException(java.io.IOException) Mockito.doNothing(org.mockito.Mockito.doNothing) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) List(java.util.List) Mockito.never(org.mockito.Mockito.never) SubjectAware(com.github.sdorra.shiro.SubjectAware) Rule(org.junit.Rule) HookBranchProvider(sonia.scm.repository.api.HookBranchProvider) PostReceiveRepositoryHookEvent(sonia.scm.repository.PostReceiveRepositoryHookEvent) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Collections(java.util.Collections) PullRequestStatus(com.cloudogu.scm.review.pullrequest.service.PullRequestStatus) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Branches(sonia.scm.repository.Branches) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) 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