예제 #1
0
  @Test(expected = ForbiddenException.class)
  public void check_component_uuid_permission_ko() {
    UserSession session = newServerUserSession().setLogin("marius").setUserId(1);

    ComponentDto project = ComponentTesting.newProjectDto();
    ComponentDto file = ComponentTesting.newFileDto(project, "file-uuid");
    when(resourceDao.selectResource("file-uuid"))
        .thenReturn(new ResourceDto().setProjectUuid(project.uuid()));
    when(authorizationDao.selectAuthorizedRootProjectsUuids(1, UserRole.USER))
        .thenReturn(newArrayList(project.uuid()));

    session.checkComponentUuidPermission(UserRole.USER, "another-uuid");
  }
예제 #2
0
  @Test
  public void app() throws Exception {
    userSessionRule
        .login("john")
        .addComponentPermission(UserRole.USER, SUB_PROJECT_KEY, COMPONENT_KEY);
    ComponentDto project = newProject();

    ComponentDto file =
        ComponentTesting.newFileDto(project)
            .setId(10L)
            .setKey(COMPONENT_KEY)
            .setUuid(COMPONENT_UUID)
            .setName("Plugin.java")
            .setProjectUuid("THE_PROJECT")
            .setLongName("src/main/java/org/sonar/api/Plugin.java")
            .setPath("src/main/java/org/sonar/api/Plugin.java")
            .setParentProjectId(5L);
    when(componentDao.selectByUuid(session, COMPONENT_UUID)).thenReturn(Optional.of(file));
    when(componentDao.selectOrFailById(session, 5L))
        .thenReturn(
            new ComponentDto()
                .setId(5L)
                .setLongName("SonarQube :: Plugin API")
                .setKey(SUB_PROJECT_KEY));
    when(componentDao.selectOrFailByUuid(session, project.uuid())).thenReturn(project);
    when(propertiesDao.selectByQuery(any(PropertyQuery.class), eq(session)))
        .thenReturn(newArrayList(new PropertyDto()));

    WsTester.TestRequest request =
        tester.newGetRequest("api/components", "app").setParam("uuid", COMPONENT_UUID);
    request.execute().assertJson(getClass(), "app.json");
  }
예제 #3
0
 private ComponentDto newProject() {
   return ComponentTesting.newProjectDto()
       .setId(1L)
       .setName("SonarQube")
       .setUuid(PROJECT_UUID)
       .setLongName("SonarQube")
       .setKey("org.codehaus.sonar:sonar");
 }
예제 #4
0
  @Test(expected = ForbiddenException.class)
  public void check_component_dto_permission_ko() {
    UserSession session = newServerUserSession().setLogin("marius").setUserId(1);

    ComponentDto project = ComponentTesting.newProjectDto();
    when(authorizationDao.selectAuthorizedRootProjectsKeys(1, UserRole.USER))
        .thenReturn(newArrayList(project.uuid()));

    session.checkComponentPermission(UserRole.USER, "another");
  }
예제 #5
0
  @Test
  public void check_project_uuid_permission_ok() {
    UserSession session = newServerUserSession().setLogin("marius").setUserId(1);

    ComponentDto project = ComponentTesting.newProjectDto();
    when(authorizationDao.selectAuthorizedRootProjectsUuids(1, UserRole.USER))
        .thenReturn(newArrayList(project.uuid()));

    session.checkProjectUuidPermission(UserRole.USER, project.uuid());
  }
  @Test
  public void compute_no_symbol() throws Exception {
    initReport();

    step.execute(
        new ComputationContext(
            new BatchReportReader(reportDir), ComponentTesting.newProjectDto("PROJECT_A")));

    assertThat(step.getSyntaxHighlightingByLine()).isEmpty();
  }
예제 #7
0
 private ComponentDto newComponent(ComponentDto project) {
   ComponentDto file =
       ComponentTesting.newFileDto(project)
           .setId(10L)
           .setQualifier("FIL")
           .setKey(COMPONENT_KEY)
           .setUuid(COMPONENT_UUID)
           .setProjectUuid(PROJECT_UUID)
           .setName("Plugin.java")
           .setLongName("src/main/java/org/sonar/api/Plugin.java")
           .setPath("src/main/java/org/sonar/api/Plugin.java")
           .setParentProjectId(5L);
   when(componentDao.selectByUuid(session, COMPONENT_UUID)).thenReturn(Optional.of(file));
   when(componentDao.selectOrFailById(session, 5L))
       .thenReturn(
           new ComponentDto()
               .setId(5L)
               .setLongName("SonarQube :: Plugin API")
               .setKey(SUB_PROJECT_KEY));
   when(componentDao.selectOrFailByUuid(session, project.uuid())).thenReturn(project);
   return file;
 }