Search in sources :

Example 86 with ProjectDto

use of org.sonar.db.project.ProjectDto in project sonarqube by SonarSource.

the class SearchBitbucketServerReposActionTest method use_projectKey_to_disambiguate_when_multiple_projects_are_binded_on_one_bitbucketserver_repo.

@Test
public void use_projectKey_to_disambiguate_when_multiple_projects_are_binded_on_one_bitbucketserver_repo() {
    UserDto user = db.users().insertUser();
    userSession.logIn(user).addPermission(PROVISION_PROJECTS);
    AlmSettingDto almSetting = db.almSettings().insertBitbucketAlmSetting();
    db.almPats().insert(dto -> {
        dto.setAlmSettingUuid(almSetting.getUuid());
        dto.setUserUuid(user.getUuid());
    });
    ProjectDto project1 = db.components().insertPrivateProjectDto(p -> p.setDbKey("B"));
    ProjectDto project2 = db.components().insertPrivateProjectDto(p -> p.setDbKey("A"));
    db.almSettings().insertBitbucketProjectAlmSetting(almSetting, project1, s -> s.setAlmRepo("projectKey2"), s -> s.setAlmSlug("repo-slug-2"));
    db.almSettings().insertBitbucketProjectAlmSetting(almSetting, project2, s -> s.setAlmRepo("projectKey2"), s -> s.setAlmSlug("repo-slug-2"));
    AlmIntegrations.SearchBitbucketserverReposWsResponse response = ws.newRequest().setParam("almSetting", almSetting.getKey()).executeProtobuf(SearchBitbucketserverReposWsResponse.class);
    assertThat(response.getIsLastPage()).isTrue();
    assertThat(response.getRepositoriesList()).extracting(AlmIntegrations.BBSRepo::getId, AlmIntegrations.BBSRepo::getName, AlmIntegrations.BBSRepo::getSlug, AlmIntegrations.BBSRepo::getSqProjectKey, AlmIntegrations.BBSRepo::getProjectKey).containsExactlyInAnyOrder(tuple(1L, "repoName1", "repo-slug-1", "", "projectKey1"), tuple(3L, "repoName2", "repo-slug-2", "A", "projectKey2"));
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) UserDto(org.sonar.db.user.UserDto) SearchBitbucketserverReposWsResponse(org.sonarqube.ws.AlmIntegrations.SearchBitbucketserverReposWsResponse) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) AlmIntegrations(org.sonarqube.ws.AlmIntegrations) Test(org.junit.Test)

Example 87 with ProjectDto

use of org.sonar.db.project.ProjectDto in project sonarqube by SonarSource.

the class ListActionTest method fail_when_missing_administer_permission_on_private_project.

@Test
public void fail_when_missing_administer_permission_on_private_project() {
    UserDto user = db.users().insertUser();
    ProjectDto project = db.components().insertPrivateProjectDto();
    userSession.logIn(user).addProjectPermission(USER, project);
    AlmSettingDto githubAlmSetting = db.almSettings().insertGitHubAlmSetting();
    db.almSettings().insertGitHubProjectAlmSetting(githubAlmSetting, project);
    TestRequest request = ws.newRequest().setParam("project", project.getKey());
    assertThatThrownBy(request::execute).isInstanceOf(ForbiddenException.class).hasMessage("Insufficient privileges");
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) ForbiddenException(org.sonar.server.exceptions.ForbiddenException) UserDto(org.sonar.db.user.UserDto) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test)

Example 88 with ProjectDto

use of org.sonar.db.project.ProjectDto in project sonarqube by SonarSource.

the class ListActionTest method fail_when_project_does_not_exist.

@Test
public void fail_when_project_does_not_exist() {
    UserDto user = db.users().insertUser();
    ProjectDto project = db.components().insertPrivateProjectDto();
    userSession.logIn(user).addProjectPermission(ADMIN, project);
    AlmSettingDto githubAlmSetting = db.almSettings().insertGitHubAlmSetting();
    db.almSettings().insertGitHubProjectAlmSetting(githubAlmSetting, project);
    TestRequest request = ws.newRequest().setParam("project", "unknown");
    assertThatThrownBy(request::execute).isInstanceOf(NotFoundException.class).hasMessage("Project 'unknown' not found");
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) UserDto(org.sonar.db.user.UserDto) NotFoundException(org.sonar.server.exceptions.NotFoundException) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test)

Example 89 with ProjectDto

use of org.sonar.db.project.ProjectDto in project sonarqube by SonarSource.

the class ListActionTest method fail_when_missing_administer_permission_on_public_project.

@Test
public void fail_when_missing_administer_permission_on_public_project() {
    UserDto user = db.users().insertUser();
    ProjectDto project = db.components().insertPublicProjectDto();
    userSession.logIn(user).addProjectPermission(SCAN, project);
    AlmSettingDto githubAlmSetting = db.almSettings().insertGitHubAlmSetting();
    db.almSettings().insertGitHubProjectAlmSetting(githubAlmSetting, project);
    TestRequest request = ws.newRequest().setParam("project", project.getKey());
    assertThatThrownBy(request::execute).isInstanceOf(ForbiddenException.class).hasMessage("Insufficient privileges");
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) ForbiddenException(org.sonar.server.exceptions.ForbiddenException) UserDto(org.sonar.db.user.UserDto) AlmSettingDto(org.sonar.db.alm.setting.AlmSettingDto) TestRequest(org.sonar.server.ws.TestRequest) Test(org.junit.Test)

Example 90 with ProjectDto

use of org.sonar.db.project.ProjectDto in project sonarqube by SonarSource.

the class QualityGateActionTest method badge_accessible_on_private_project_with_token.

@Test
@UseDataProvider("publicProject_forceAuth_validToken_accessGranted")
public void badge_accessible_on_private_project_with_token(boolean publicProject, boolean forceAuth, boolean validToken, boolean accessGranted) throws ParseException {
    ComponentDto projectAsComponent = publicProject ? db.components().insertPublicProject() : db.components().insertPrivateProject();
    userSession.registerComponents(projectAsComponent);
    MetricDto metric = createQualityGateMetric();
    db.measures().insertLiveMeasure(projectAsComponent, metric, m -> m.setData(OK.name()));
    ProjectDto project = db.getDbClient().projectDao().selectProjectByKey(db.getSession(), projectAsComponent.getKey()).orElseThrow(() -> new IllegalStateException("project not found"));
    String token = db.getDbClient().projectBadgeTokenDao().insert(db.getSession(), UuidFactoryFast.getInstance().create(), project, "user-uuid", "user-login").getToken();
    db.commit();
    mapSettings.setProperty(CoreProperties.CORE_FORCE_AUTHENTICATION_PROPERTY, forceAuth);
    TestResponse response = ws.newRequest().setParam("project", projectAsComponent.getKey()).setParam("token", validToken ? token : "invalid-token").execute();
    if (accessGranted) {
        checkResponse(response, OK);
    } else {
        checkError(response, "Project has not been found");
    }
}
Also used : ProjectDto(org.sonar.db.project.ProjectDto) MetricDto(org.sonar.db.metric.MetricDto) TestResponse(org.sonar.server.ws.TestResponse) ComponentDto(org.sonar.db.component.ComponentDto) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Aggregations

ProjectDto (org.sonar.db.project.ProjectDto)283 Test (org.junit.Test)215 DbSession (org.sonar.db.DbSession)49 BranchDto (org.sonar.db.component.BranchDto)42 UserDto (org.sonar.db.user.UserDto)39 AlmSettingDto (org.sonar.db.alm.setting.AlmSettingDto)38 QProfileDto (org.sonar.db.qualityprofile.QProfileDto)31 SnapshotDto (org.sonar.db.component.SnapshotDto)27 QualityGateDto (org.sonar.db.qualitygate.QualityGateDto)26 ComponentDto (org.sonar.db.component.ComponentDto)23 ComponentTesting.newPrivateProjectDto (org.sonar.db.component.ComponentTesting.newPrivateProjectDto)20 NotFoundException (org.sonar.server.exceptions.NotFoundException)17 WebhookDto (org.sonar.db.webhook.WebhookDto)15 ApplicationProjectDto (org.sonar.db.project.ApplicationProjectDto)14 WebService (org.sonar.api.server.ws.WebService)13 DbClient (org.sonar.db.DbClient)12 PortfolioProjectDto (org.sonar.db.portfolio.PortfolioProjectDto)12 TestRequest (org.sonar.server.ws.TestRequest)11 TestResponse (org.sonar.server.ws.TestResponse)10 Projects (org.sonarqube.ws.Projects)10