import org.sonar.wsclient.project.NewProject;
import org.sonar.wsclient.services.PropertyUpdateQuery;
+@Ignore
public class ProjectProvisioningTest {
@ClassRule
import java.util.List;
import java.util.Map;
import javax.annotation.CheckForNull;
-import org.sonar.api.CoreProperties;
import org.sonar.api.config.Settings;
import org.sonar.api.utils.MessageException;
import org.sonar.batch.protocol.output.BatchReport;
/**
* Validate project and modules. It will fail in the following cases :
* <ol>
- * <li>property {@link org.sonar.api.CoreProperties#CORE_PREVENT_AUTOMATIC_PROJECT_CREATION} is set to true and project does not exists</li>
* <li>branch is not valid</li>
* <li>project or module key is not valid</li>
* <li>module key already exists in another project (same module key cannot exists in different projects)</li>
List<ComponentDto> baseModules = dbClient.componentDao().selectEnabledModulesFromProjectKey(session, treeRootHolder.getRoot().getKey());
Map<String, ComponentDto> baseModulesByKey = FluentIterable.from(baseModules).uniqueIndex(toKey());
ValidateProjectsVisitor visitor = new ValidateProjectsVisitor(session, dbClient.componentDao(),
- settings.getBoolean(CoreProperties.CORE_PREVENT_AUTOMATIC_PROJECT_CREATION), baseModulesByKey);
+ baseModulesByKey);
new DepthTraversalTypeAwareCrawler(visitor).visit(treeRootHolder.getRoot());
if (!visitor.validationMessages.isEmpty()) {
private class ValidateProjectsVisitor extends TypeAwareVisitorAdapter {
private final DbSession session;
private final ComponentDao componentDao;
- private final boolean preventAutomaticProjectCreation;
private final Map<String, ComponentDto> baseModulesByKey;
private final List<String> validationMessages = new ArrayList<>();
private Component rawProject;
- public ValidateProjectsVisitor(DbSession session, ComponentDao componentDao, boolean preventAutomaticProjectCreation, Map<String, ComponentDto> baseModulesByKey) {
+ public ValidateProjectsVisitor(DbSession session, ComponentDao componentDao, Map<String, ComponentDto> baseModulesByKey) {
super(CrawlerDepthLimit.MODULE, ComponentVisitor.Order.PRE_ORDER);
this.session = session;
this.componentDao = componentDao;
- this.preventAutomaticProjectCreation = preventAutomaticProjectCreation;
this.baseModulesByKey = baseModulesByKey;
}
String rawProjectKey = rawProject.getKey();
Optional<ComponentDto> baseProject = loadBaseComponent(rawProjectKey);
- validateWhenProvisioningEnforced(baseProject, rawProjectKey);
validateProjectKey(baseProject, rawProjectKey);
validateAnalysisDate(baseProject);
}
- private void validateWhenProvisioningEnforced(Optional<ComponentDto> baseProject, String rawProjectKey) {
- if (!baseProject.isPresent() && preventAutomaticProjectCreation) {
- validationMessages.add(String.format("Unable to scan non-existing project '%s'", rawProjectKey));
- }
- }
-
private void validateProjectKey(Optional<ComponentDto> baseProject, String rawProjectKey) {
if (baseProject.isPresent() && !baseProject.get().projectUuid().equals(baseProject.get().uuid())) {
// Project key is already used as a module of another project
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.rules.ExpectedException;
-import org.sonar.api.CoreProperties;
import org.sonar.api.config.Settings;
import org.sonar.api.utils.MessageException;
import org.sonar.api.utils.System2;
underTest = new ValidateProjectStep(dbClient, settings, reportReader, treeRootHolder);
}
- @Test
- public void not_fail_if_provisioning_enforced_and_project_exists() {
- reportReader.setMetadata(BatchReport.Metadata.newBuilder().setAnalysisDate(DEFAULT_ANALYSIS_TIME).build());
- reportReader.putComponent(BatchReport.Component.newBuilder()
- .setRef(1)
- .setType(Constants.ComponentType.PROJECT)
- .setKey(PROJECT_KEY)
- .build());
-
- settings.appendProperty(CoreProperties.CORE_PREVENT_AUTOMATIC_PROJECT_CREATION, "true");
- dbClient.componentDao().insert(dbTester.getSession(), ComponentTesting.newProjectDto("ABCD").setKey(PROJECT_KEY));
- dbTester.getSession().commit();
- treeRootHolder.setRoot(ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").setKey(PROJECT_KEY).build());
-
- underTest.execute();
- }
-
- @Test
- public void fail_if_provisioning_enforced_and_project_does_not_exists() {
- thrown.expect(MessageException.class);
- thrown.expectMessage("Unable to scan non-existing project '" + PROJECT_KEY + "'");
-
- reportReader.setMetadata(BatchReport.Metadata.newBuilder().setAnalysisDate(DEFAULT_ANALYSIS_TIME).build());
- reportReader.putComponent(BatchReport.Component.newBuilder()
- .setRef(1)
- .setType(Constants.ComponentType.PROJECT)
- .setKey(PROJECT_KEY)
- .build());
-
- settings.appendProperty(CoreProperties.CORE_PREVENT_AUTOMATIC_PROJECT_CREATION, "true");
- treeRootHolder.setRoot(ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").setKey(PROJECT_KEY).build());
-
- underTest.execute();
- }
-
- @Test
- public void fail_if_provisioning_not_enforced_and_project_does_not_exists() {
- reportReader.setMetadata(BatchReport.Metadata.newBuilder().setAnalysisDate(DEFAULT_ANALYSIS_TIME).build());
- reportReader.putComponent(BatchReport.Component.newBuilder()
- .setRef(1)
- .setType(Constants.ComponentType.PROJECT)
- .setKey(PROJECT_KEY)
- .build());
-
- settings.appendProperty(CoreProperties.CORE_PREVENT_AUTOMATIC_PROJECT_CREATION, "false");
- treeRootHolder.setRoot(ReportComponent.builder(Component.Type.PROJECT, 1).setUuid("ABCD").setKey(PROJECT_KEY).build());
-
- underTest.execute();
- }
-
@Test
public void not_fail_on_valid_branch() {
reportReader.setMetadata(BatchReport.Metadata.newBuilder()
class AddProvisioningPermissionToScan < ActiveRecord::Migration
class Property < ActiveRecord::Base
+ set_table_name 'properties'
end
class GroupRole < ActiveRecord::Base
--- /dev/null
+#
+# SonarQube, open source software quality management tool.
+# Copyright (C) 2008-2014 SonarSource
+# mailto:contact AT sonarsource DOT com
+#
+# SonarQube is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 3 of the License, or (at your option) any later version.
+#
+# SonarQube is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+
+#
+# SonarQube 5.2
+# SONAR-6861
+#
+class DeletePropertyPreventAutoProjectCreation < ActiveRecord::Migration
+
+ class Property < ActiveRecord::Base
+ set_table_name 'properties'
+ end
+
+ def self.up
+ Property.delete_all(['prop_key=?', 'sonar.preventAutoProjectCreation'])
+ end
+
+end
.description("Forcing user authentication stops un-logged users to access SonarQube.")
.type(PropertyType.BOOLEAN)
.category(CoreProperties.CATEGORY_SECURITY)
- .build(),
-
- PropertyDefinition.builder(CoreProperties.CORE_PREVENT_AUTOMATIC_PROJECT_CREATION)
- .defaultValue(Boolean.toString(false))
- .name("Prevent automatic project creation")
- .description("Set to true to prevent automatic project creation at first analysis and force project provisioning.")
- .type(PropertyType.BOOLEAN)
- .category(CoreProperties.CATEGORY_SECURITY)
.build()
);
public class DatabaseVersion {
- public static final int LAST_VERSION = 935;
+ public static final int LAST_VERSION = 936;
/**
* The minimum supported version which can be upgraded. Lower
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('933');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('934');
INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('935');
+INSERT INTO SCHEMA_MIGRATIONS(VERSION) VALUES ('936');
INSERT INTO USERS(ID, LOGIN, NAME, EMAIL, CRYPTED_PASSWORD, SALT, CREATED_AT, UPDATED_AT, REMEMBER_TOKEN, REMEMBER_TOKEN_EXPIRES_AT) VALUES (1, 'admin', 'Administrator', '', 'a373a0e667abb2604c1fd571eb4ad47fe8cc0878', '48bc4b0d93179b5103fd3885ea9119498e9d161b', '1418215735482', '1418215735482', null, null);
ALTER TABLE USERS ALTER COLUMN ID RESTART WITH 2;
/**
* @since 4.0
+ * @deprecated replaced in 5.2 by the permission 'provisioning'
*/
+ @Deprecated
String CORE_PREVENT_AUTOMATIC_PROJECT_CREATION = "sonar.preventAutoProjectCreation";
/**