Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Api token support #10

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -40,6 +40,7 @@ public class HubPropertyConstants {
public static final String HUB_URL = HUB_SONAR_PREFIX + "url";
public static final String HUB_USERNAME = HUB_SONAR_PREFIX + "username";
public static final String HUB_PASSWORD = HUB_SONAR_PREFIX + "password";
public static final String HUB_API_TOKEN = HUB_SONAR_PREFIX + "token";
public static final String HUB_TIMEOUT = HUB_SONAR_PREFIX + "timeout";
public static final String HUB_TRUST_SSL_CERT = HUB_SONAR_PREFIX + "trust.ssl.cert";

Expand Down
Expand Up @@ -58,6 +58,7 @@ public Optional<BlackDuckServerConfig> getBlackDuckServerConfigFromSettings() {
configBuilder.setUrl(getValue(HubPropertyConstants.HUB_URL));
configBuilder.setUsername(getValue(HubPropertyConstants.HUB_USERNAME));
configBuilder.setPassword(getValue(HubPropertyConstants.HUB_PASSWORD));
configBuilder.setApiToken(getValue(HubPropertyConstants.HUB_API_TOKEN));
configBuilder.setTimeoutInSeconds(getValue(HubPropertyConstants.HUB_TIMEOUT));
configBuilder.setTrustCert(Boolean.parseBoolean(getValue(HubPropertyConstants.HUB_TRUST_SSL_CERT)));

Expand Down
Expand Up @@ -23,12 +23,17 @@
*/
package com.blackducksoftware.integration.hub.sonar.manager;

import static com.blackducksoftware.integration.hub.sonar.HubPropertyConstants.HUB_API_TOKEN;
import static com.blackducksoftware.integration.hub.sonar.HubPropertyConstants.HUB_URL;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.io.File;
import java.util.Optional;

import com.synopsys.integration.blackduck.configuration.BlackDuckServerConfig;
import org.junit.Before;
import org.junit.Test;
import org.sonar.api.batch.sensor.SensorContext;
Expand Down Expand Up @@ -118,8 +123,7 @@ public void getValuesTest() {
@Test
public void getHubPluginVersionTest() {
SonarManager manager = new SonarManager(sensorContext);

assertTrue("<unknown>" != manager.getHubPluginVersionFromFile("/plugin.properties"));
assertNotEquals("<unknown>", manager.getHubPluginVersionFromFile("/plugin.properties"));
}

@Test
Expand All @@ -128,4 +132,18 @@ public void getHubPluginVersionUnknownTest() {

assertEquals("<unknown>", manager.getHubPluginVersionFromFile("/NULL"));
}

@Test
public void getBlackDuckServerConfigFromSettingsTest() {
MapSettings settings = new MapSettings();
settings.setProperty(HUB_URL, "http://127.0.0.1/valid/url");
settings.setProperty(HUB_API_TOKEN, HUB_API_TOKEN + ".testValue");

sensorContext = new MockSensorContext(settings.asConfig(), new MockFileSystem(baseDir));
SonarManager manager = new SonarManager(sensorContext);

Optional<BlackDuckServerConfig> blackDuckServerConfig = manager.getBlackDuckServerConfigFromSettings();
assertTrue(blackDuckServerConfig.isPresent());
assertEquals(settings.asConfig().get(HUB_API_TOKEN), blackDuckServerConfig.get().getApiToken());
}
}