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"));
}
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");
}
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");
}
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");
}
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");
}
}
Aggregations