Skip to content

Commit 235d185

Browse files
committed
SONARMSBRU-194 Allow using SonarQube tokens for authentication
1 parent c3bd4e4 commit 235d185

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

SonarQube.TeamBuild.PreProcessor/WebClientDownloader.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,13 @@ public WebClientDownloader(string username, string password)
2121
// SONARMSBRU-169 Support TLS versions 1.0, 1.1 and 1.2
2222
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
2323

24+
if (password == null)
25+
{
26+
password = "";
27+
}
28+
2429
this.client = new WebClient();
25-
if (username != null && password != null)
30+
if (username != null)
2631
{
2732
if (username.Contains(':'))
2833
{

Tests/SonarQube.TeamBuild.PreProcessor.Tests/WebClientDownloaderTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ public void Credentials()
2424
downloader = new WebClientDownloader(null, null);
2525
Assert.AreEqual(null, downloader.GetHeader(HttpRequestHeader.Authorization));
2626

27-
downloader = new WebClientDownloader("admin", null);
28-
Assert.AreEqual(null, downloader.GetHeader(HttpRequestHeader.Authorization));
27+
downloader = new WebClientDownloader("da39a3ee5e6b4b0d3255bfef95601890afd80709", null);
28+
Assert.AreEqual("Basic ZGEzOWEzZWU1ZTZiNGIwZDMyNTViZmVmOTU2MDE4OTBhZmQ4MDcwOTo=", downloader.GetHeader(HttpRequestHeader.Authorization));
2929

3030
downloader = new WebClientDownloader(null, "password");
3131
Assert.AreEqual(null, downloader.GetHeader(HttpRequestHeader.Authorization));

0 commit comments

Comments
 (0)