static List<PropertyDefinition> all() { return singletonList( PropertyDefinition.builder(CoreProperties.CORE_FORCE_AUTHENTICATION_PROPERTY) .defaultValue(Boolean.toString(CoreProperties.CORE_FORCE_AUTHENTICATION_DEFAULT_VALUE)) .name("Force user authentication") .description( "Forcing user authentication prevents anonymous users from accessing the SonarQube UI, or project data via the Web API. " + "Some specific read-only Web APIs, including those required to prompt authentication, are still available anonymously.") .type(PropertyType.BOOLEAN) .category(CoreProperties.CATEGORY_SECURITY) .build()); } }
public static List<PropertyDefinition> properties() { return Collections.singletonList( PropertyDefinition.builder(REPORT_PATHS_PROPERTY_KEY) .name("Issues report paths") .description("List of comma-separated paths (absolute or relative) containing report with issues created by external rule engines.") .category(CoreProperties.CATEGORY_EXTERNAL_ISSUES) .onQualifiers(Qualifiers.PROJECT) .build()); }
public static ImmutableList<PropertyDefinition> properties() { return ImmutableList.of( PropertyDefinition.builder(REPORT_PATHS_PROPERTY_KEY) .name("Coverage report paths") .description("List of comma-separated paths (absolute or relative) containing coverage report.") .category(CATEGORY_CODE_COVERAGE) .onQualifiers(Qualifiers.PROJECT) .multiValues(true) .deprecatedKey(OLD_COVERAGE_REPORT_PATHS_PROPERTY_KEY) .build()); }
@Test public void fail_when_property_set_has_field_with_incorrect_type() { definitions.addComponent(PropertyDefinition .builder("my.key") .name("foo") .description("desc") .category("cat") .subCategory("subCat") .type(PropertyType.PROPERTY_SET) .defaultValue("default") .fields(newArrayList( PropertyFieldDefinition.build("field") .name("Field") .type(PropertyType.INTEGER) .build())) .build()); expectedException.expect(BadRequestException.class); expectedException.expectMessage("Error when validating setting with key 'my.key'. Field 'field' has incorrect value 'notAnInt'."); callForGlobalPropertySet("my.key", newArrayList(GSON.toJson(ImmutableMap.of("field", "notAnInt")))); }
@Test public void fail_when_property_set_on_component_of_global_setting() { definitions.addComponent(PropertyDefinition .builder("my.key") .name("foo") .description("desc") .category("cat") .subCategory("subCat") .type(PropertyType.PROPERTY_SET) .defaultValue("default") .fields(newArrayList(PropertyFieldDefinition.build("firstField").name("First Field").type(PropertyType.STRING).build())) .build()); i18n.put("qualifier." + Qualifiers.PROJECT, "Project"); ComponentDto project = db.components().insertPrivateProject(); logInAsProjectAdministrator(project); expectedException.expect(BadRequestException.class); expectedException.expectMessage("Setting 'my.key' cannot be set on a Project"); callForComponentPropertySet("my.key", newArrayList( GSON.toJson(ImmutableMap.of("firstField", "firstValue"))), project.getDbKey()); }
@Test public void fail_when_property_set_has_a_null_field_value() { definitions.addComponent(PropertyDefinition .builder("my.key") .name("foo") .description("desc") .category("cat") .subCategory("subCat") .type(PropertyType.PROPERTY_SET) .defaultValue("default") .fields(newArrayList( PropertyFieldDefinition.build("field") .name("Field") .type(PropertyType.STRING) .build())) .build()); expectedException.expect(BadRequestException.class); expectedException.expectMessage("A non empty value must be provided"); callForGlobalPropertySet("my.key", newArrayList("{\"field\": null}")); }
@Test public void fail_when_property_set_with_unknown_field() { definitions.addComponent(PropertyDefinition .builder("my.key") .name("foo") .description("desc") .category("cat") .subCategory("subCat") .type(PropertyType.PROPERTY_SET) .defaultValue("default") .fields(newArrayList( PropertyFieldDefinition.build("field") .name("Field") .type(PropertyType.STRING) .build())) .build()); expectedException.expect(BadRequestException.class); expectedException.expectMessage("Unknown field key 'unknownField' for setting 'my.key'"); callForGlobalPropertySet("my.key", newArrayList(GSON.toJson(ImmutableMap.of("field", "value", "unknownField", "anotherValue")))); }
@Test public void set_leak_on_branch() { ComponentDto project = db.components().insertMainBranch(); logInAsProjectAdministrator(project); ComponentDto branch = db.components().insertProjectBranch(project); String leakKey = "sonar.leak.period"; definitions.addComponent(PropertyDefinition.builder(leakKey) .name("Leak") .description("desc") .onQualifiers(Qualifiers.PROJECT) .build()); propertyDb.insertProperties(newComponentPropertyDto(leakKey, "1", branch)); ws.newRequest() .setParam("key", leakKey) .setParam("value", "2") .setParam("component", branch.getKey()) .setParam("branch", branch.getBranch()) .execute(); assertComponentSetting(leakKey, "2", branch.getId()); }
@Test public void fail_when_property_with_definition_when_component_qualifier_does_not_match() { ComponentDto project = randomPublicOrPrivateProject(); ComponentDto file = db.components().insertComponent(ComponentTesting.newFileDto(project)); definitions.addComponent(PropertyDefinition .builder("my.key") .name("foo") .description("desc") .category("cat") .subCategory("subCat") .type(PropertyType.STRING) .defaultValue("default") .onQualifiers(Qualifiers.PROJECT) .build()); i18n.put("qualifier." + file.qualifier(), "CptLabel"); logInAsProjectAdministrator(project); expectedException.expect(BadRequestException.class); expectedException.expectMessage("Setting 'my.key' cannot be set on a CptLabel"); callForProjectSettingByKey("my.key", "My Value", file.getDbKey()); }
@Test public void persist_multi_value_with_type_metric() { definitions.addComponent(PropertyDefinition .builder("my_key") .name("foo") .description("desc") .category("cat") .subCategory("subCat") .type(PropertyType.METRIC) .defaultValue("default") .multiValues(true) .build()); dbClient.metricDao().insert(dbSession, newMetricDto().setKey("metric_key_1")); dbClient.metricDao().insert(dbSession, newMetricDto().setKey("metric_key_2")); dbSession.commit(); callForMultiValueGlobalSetting("my_key", newArrayList("metric_key_1", "metric_key_2")); assertGlobalSetting("my_key", "metric_key_1,metric_key_2"); }
@Test public void fail_when_view_property_when_on_projects_only() { definitions.addComponent(PropertyDefinition .builder("my.key") .name("foo") .description("desc") .category("cat") .subCategory("subCat") .type(PropertyType.STRING) .defaultValue("default") .onQualifiers(Qualifiers.PROJECT) .build()); ComponentDto view = db.components().insertComponent(newView(db.getDefaultOrganization(), "view-uuid")); i18n.put("qualifier." + Qualifiers.VIEW, "View"); expectedException.expect(BadRequestException.class); expectedException.expectMessage("Setting 'my.key' cannot be set on a View"); logInAsProjectAdministrator(view); callForProjectSettingByKey("my.key", "My Value", view.getDbKey()); }
@Test public void fail_when_data_and_login_type_with_invalid_logIn() { definitions.addComponent(PropertyDefinition .builder("my.key") .name("foo") .description("desc") .category("cat") .subCategory("subCat") .type(PropertyType.USER_LOGIN) .defaultValue("default") .multiValues(true) .build()); db.users().insertUser(newUserDto().setLogin("login.1")); db.users().insertUser(newUserDto().setLogin("login.2").setActive(false)); expectedException.expect(BadRequestException.class); expectedException.expectMessage("Error when validating login setting with key 'my.key' and values [login.1, login.2]. A value is not a valid login."); callForMultiValueGlobalSetting("my.key", newArrayList("login.1", "login.2")); }
@Test public void persist_multi_value_with_type_logIn() { definitions.addComponent(PropertyDefinition .builder("my.key") .name("foo") .description("desc") .category("cat") .subCategory("subCat") .type(PropertyType.USER_LOGIN) .defaultValue("default") .multiValues(true) .build()); db.users().insertUser(newUserDto().setLogin("login.1")); db.users().insertUser(newUserDto().setLogin("login.2")); callForMultiValueGlobalSetting("my.key", newArrayList("login.1", "login.2")); assertGlobalSetting("my.key", "login.1,login.2"); }
@Test public void persist_global_property_with_deprecated_key() { definitions.addComponent(PropertyDefinition .builder("my.key") .deprecatedKey("my.old.key") .name("foo") .description("desc") .category("cat") .subCategory("subCat") .type(PropertyType.STRING) .defaultValue("default") .build()); callForGlobalSetting("my.old.key", "My Value"); assertGlobalSetting("my.key", "My Value"); }
@Test public void fail_when_global_with_property_only_on_projects() { definitions.addComponent(PropertyDefinition .builder("my.key") .name("foo") .description("desc") .category("cat") .subCategory("subCat") .type(PropertyType.INTEGER) .defaultValue("default") .onlyOnQualifiers(Qualifiers.PROJECT) .build()); expectedException.expect(BadRequestException.class); expectedException.expectMessage("Setting 'my.key' cannot be global"); callForGlobalSetting("my.key", "42"); }
@Test public void fail_when_data_and_type_do_not_match() { definitions.addComponent(PropertyDefinition .builder("my.key") .name("foo") .description("desc") .category("cat") .subCategory("subCat") .type(PropertyType.INTEGER) .defaultValue("default") .build()); i18n.put("property.error.notInteger", "Not an integer error message"); expectedException.expect(BadRequestException.class); expectedException.expectMessage("Not an integer error message"); callForGlobalSetting("my.key", "My Value"); }
@Test public void fail_when_data_and_type_do_not_match_with_unknown_error_key() { definitions.addComponent(PropertyDefinition .builder("my.key") .name("foo") .description("desc") .category("cat") .subCategory("subCat") .type(PropertyType.INTEGER) .defaultValue("default") .build()); expectedException.expect(BadRequestException.class); expectedException.expectMessage("Error when validating setting with key 'my.key' and value [My Value, My Other Value]"); callForMultiValueGlobalSetting("my.key", newArrayList("My Value", "My Other Value")); }
@Test public void fail_when_single_definition_and_multi_value_provided() { definitions.addComponent(PropertyDefinition .builder("my.key") .name("foo") .description("desc") .category("cat") .type(PropertyType.STRING) .multiValues(false) .build()); expectedException.expect(BadRequestException.class); expectedException.expectMessage("Parameter 'value' must be used for single value setting. Parameter 'values' must be used for multi value setting."); callForMultiValueGlobalSetting("my.key", newArrayList("My Value")); }
@Test public void fail_when_multi_definition_and_single_value_provided() { definitions.addComponent(PropertyDefinition .builder("my.key") .name("foo") .description("desc") .category("cat") .type(PropertyType.STRING) .multiValues(true) .build()); expectedException.expect(BadRequestException.class); expectedException.expectMessage("Parameter 'value' must be used for single value setting. Parameter 'values' must be used for multi value setting."); callForGlobalSetting("my.key", "My Value"); }
public static ImmutableList<PropertyDefinition> properties() { return ImmutableList.of( PropertyDefinition.builder(REPORT_PATHS_PROPERTY_KEY) .name("Unit tests results report paths") .description("List of comma-separated paths (absolute or relative) containing unit tests results report.") .category(CATEGORY_CODE_COVERAGE) .onQualifiers(Qualifiers.PROJECT) .multiValues(true) .deprecatedKey(OLD_UNIT_TEST_REPORT_PATHS_PROPERTY_KEY) .build()); }