Search in sources :

Example 36 with ValuesWsResponse

use of org.sonarqube.ws.Settings.ValuesWsResponse in project sonarqube by SonarSource.

the class ValuesActionTest method return_inherited_values_on_global_setting.

@Test
public void return_inherited_values_on_global_setting() {
    logIn();
    definitions.addComponents(asList(PropertyDefinition.builder("defaultProperty").defaultValue("default").build(), PropertyDefinition.builder("globalProperty").build()));
    propertyDb.insertProperties(null, null, null, null, newGlobalPropertyDto().setKey("globalProperty").setValue("global"));
    ValuesWsResponse result = executeRequestForGlobalProperties("defaultProperty", "globalProperty");
    assertThat(result.getSettingsList()).hasSize(2);
    assertSetting(result.getSettings(0), "defaultProperty", "default", true);
    assertSetting(result.getSettings(1), "globalProperty", "global", false);
}
Also used : ValuesWsResponse(org.sonarqube.ws.Settings.ValuesWsResponse) Test(org.junit.Test)

Example 37 with ValuesWsResponse

use of org.sonarqube.ws.Settings.ValuesWsResponse in project sonarqube by SonarSource.

the class ValuesActionTest method return_secured_settings_in_property_set_when_system_admin.

@Test
public void return_secured_settings_in_property_set_when_system_admin() {
    logInAsAdmin();
    definitions.addComponent(PropertyDefinition.builder("foo").type(PropertyType.PROPERTY_SET).fields(asList(PropertyFieldDefinition.build("key").name("Key").build(), PropertyFieldDefinition.build("secret.secured").name("Secured").build())).build());
    propertyDb.insertPropertySet("foo", null, ImmutableMap.of("key", "key1", "secret.secured", "123456"));
    ValuesWsResponse result = executeRequestForGlobalProperties();
    assertFieldValues(result.getSettings(0), ImmutableMap.of("key", "key1", "secret.secured", "123456"));
}
Also used : ValuesWsResponse(org.sonarqube.ws.Settings.ValuesWsResponse) Test(org.junit.Test)

Example 38 with ValuesWsResponse

use of org.sonarqube.ws.Settings.ValuesWsResponse in project sonarqube by SonarSource.

the class ValuesActionTest method return_secured_settings_even_if_not_defined_when_project_admin.

@Test
public void return_secured_settings_even_if_not_defined_when_project_admin() {
    logInAsProjectAdmin();
    propertyDb.insertProperties(null, project.getKey(), project.name(), project.qualifier(), newComponentPropertyDto(project).setKey("not-defined.secured").setValue("123"));
    ValuesWsResponse result = executeRequestForProjectProperties("not-defined.secured");
    assertThat(result.getSettingsList()).extracting(Settings.Setting::getKey).isEmpty();
    assertThat(result.getSetSecuredSettingsList()).containsOnly("not-defined.secured");
}
Also used : ValuesWsResponse(org.sonarqube.ws.Settings.ValuesWsResponse) Settings(org.sonarqube.ws.Settings) MapSettings(org.sonar.api.config.internal.MapSettings) Test(org.junit.Test)

Example 39 with ValuesWsResponse

use of org.sonarqube.ws.Settings.ValuesWsResponse in project sonarqube by SonarSource.

the class ValuesActionTest method global_secured_properties_require_system_admin_permission.

@Test
public void global_secured_properties_require_system_admin_permission() {
    PropertyDefinition securedDef = PropertyDefinition.builder("my.password.secured").build();
    PropertyDefinition standardDef = PropertyDefinition.builder("my.property").build();
    definitions.addComponents(asList(securedDef, standardDef));
    propertyDb.insertProperties(null, null, null, null, newGlobalPropertyDto().setKey(securedDef.key()).setValue("securedValue"), newGlobalPropertyDto().setKey(standardDef.key()).setValue("standardValue"));
    // anonymous
    WsActionTester tester = newTester();
    ValuesWsResponse response = executeRequest(tester, null, securedDef.key(), standardDef.key());
    assertThat(response.getSettingsList()).extracting(Settings.Setting::getKey).containsExactly("my.property");
    // only scan global permission
    userSession.logIn().addPermission(GlobalPermission.SCAN);
    response = executeRequest(tester, null, securedDef.key(), standardDef.key());
    assertThat(response.getSetSecuredSettingsList()).contains("my.password.secured");
    // global administrator
    userSession.logIn().addPermission(GlobalPermission.ADMINISTER);
    response = executeRequest(tester, null, securedDef.key(), standardDef.key());
    assertThat(response.getSetSecuredSettingsList()).contains("my.password.secured");
    // system administrator
    userSession.logIn().setSystemAdministrator();
    response = executeRequest(tester, null, securedDef.key(), standardDef.key());
    assertThat(response.getSetSecuredSettingsList()).contains("my.password.secured");
}
Also used : ValuesWsResponse(org.sonarqube.ws.Settings.ValuesWsResponse) PropertyDefinition(org.sonar.api.config.PropertyDefinition) WsActionTester(org.sonar.server.ws.WsActionTester) Settings(org.sonarqube.ws.Settings) MapSettings(org.sonar.api.config.internal.MapSettings) Test(org.junit.Test)

Example 40 with ValuesWsResponse

use of org.sonarqube.ws.Settings.ValuesWsResponse in project sonarqube by SonarSource.

the class ValuesActionTest method do_not_return_secured_settings_in_property_set_when_not_authenticated.

@Test
public void do_not_return_secured_settings_in_property_set_when_not_authenticated() {
    definitions.addComponent(PropertyDefinition.builder("foo").type(PropertyType.PROPERTY_SET).fields(asList(PropertyFieldDefinition.build("key").name("Key").build(), PropertyFieldDefinition.build("secret.secured").name("Secured").build())).build());
    propertyDb.insertPropertySet("foo", null, ImmutableMap.of("key", "key1", "secret.secured", "123456"));
    ValuesWsResponse result = executeRequestForGlobalProperties();
    assertFieldValues(result.getSettings(0), ImmutableMap.of("key", "key1"));
}
Also used : ValuesWsResponse(org.sonarqube.ws.Settings.ValuesWsResponse) Test(org.junit.Test)

Aggregations

ValuesWsResponse (org.sonarqube.ws.Settings.ValuesWsResponse)46 Test (org.junit.Test)43 Settings (org.sonarqube.ws.Settings)25 MapSettings (org.sonar.api.config.internal.MapSettings)18 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 PipedInputStream (java.io.PipedInputStream)2 PipedOutputStream (java.io.PipedOutputStream)2 ComponentDto (org.sonar.db.component.ComponentDto)2 Setting (org.sonarqube.ws.Settings.Setting)2 SonarLintWsClient (org.sonarsource.sonarlint.core.container.connected.SonarLintWsClient)2 CheckForNull (javax.annotation.CheckForNull)1 PropertyDefinition (org.sonar.api.config.PropertyDefinition)1 Profiler (org.sonar.api.utils.log.Profiler)1 WsActionTester (org.sonar.server.ws.WsActionTester)1 Value (org.sonarqube.ws.Settings.FieldValues.Value)1 GetRequest (org.sonarqube.ws.client.GetRequest)1 GlobalProperties (org.sonarsource.sonarlint.core.proto.Sonarlint.GlobalProperties)1 Builder (org.sonarsource.sonarlint.core.proto.Sonarlint.ModuleConfiguration.Builder)1 WsResponse (org.sonarsource.sonarlint.core.util.ws.WsResponse)1