Skip to content

Commit

Permalink
SLVS-1818 Upgrade SLCore to 10.14.0.80189 and adapt RPC changes for S…
Browse files Browse the repository at this point in the history
  • Loading branch information
georgii-borovinskikh-sonarsource authored Feb 5, 2025
1 parent bf1d0cb commit 3edccfa
Show file tree
Hide file tree
Showing 21 changed files with 278 additions and 61 deletions.
14 changes: 9 additions & 5 deletions src/ConnectedMode.UnitTests/SlCoreConnectionAdapterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ namespace SonarLint.VisualStudio.ConnectedMode.UnitTests;
[TestClass]
public class SlCoreConnectionAdapterTests
{
private const string Token = "token123";
private static readonly TokenAuthCredentials ValidTokenAuth = new ("I_AM_JUST_A_TOKEN".ToSecureString());
private readonly ServerConnection.SonarQube sonarQubeConnection = new(new Uri("http://localhost:9000/"), new ServerConnectionSettings(true), ValidTokenAuth);
private readonly ServerConnection.SonarCloud sonarCloudConnection = new("myOrg", new ServerConnectionSettings(true), ValidTokenAuth);
Expand Down Expand Up @@ -176,7 +177,7 @@ public async Task GetOrganizationsAsync_TokenIsProvided_CallsSlCoreListUserOrgan

await testSubject.GetOrganizationsAsync(new TokenCredentialsModel(token.CreateSecureString()));

await connectionConfigurationSlCoreService.Received(1).ListUserOrganizationsAsync(Arg.Is<ListUserOrganizationsParams>(x=> IsExpectedCredentials(x.credentials, token)));
await connectionConfigurationSlCoreService.Received(1).ListUserOrganizationsAsync(Arg.Is<ListUserOrganizationsParams>(x=> IsExpectedCredentials(x.credentials, token) && IsEuRegion(x)));
}

[TestMethod]
Expand All @@ -192,10 +193,10 @@ public async Task GetOrganizationsAsync_CredentialsIsNull_ReturnsFailedResponseA
[TestMethod]
public async Task GetOrganizationsAsync_NoOrganizationExists_ReturnsSuccessResponseAndEmptyOrganizations()
{
connectionConfigurationSlCoreService.ListUserOrganizationsAsync(Arg.Any<ListUserOrganizationsParams>())
connectionConfigurationSlCoreService.ListUserOrganizationsAsync(Arg.Is<ListUserOrganizationsParams>(x => IsExpectedCredentials(x.credentials, Token) && IsEuRegion(x)))
.Returns(new ListUserOrganizationsResponse([]));

var response = await testSubject.GetOrganizationsAsync(new TokenCredentialsModel("token".CreateSecureString()));
var response = await testSubject.GetOrganizationsAsync(new TokenCredentialsModel(Token.CreateSecureString()));

response.Success.Should().BeTrue();
response.ResponseData.Should().BeEmpty();
Expand All @@ -205,10 +206,11 @@ public async Task GetOrganizationsAsync_NoOrganizationExists_ReturnsSuccessRespo
public async Task GetOrganizationsAsync_OrganizationExists_ReturnsSuccessResponseAndMappedOrganizations()
{
List<OrganizationDto> serverOrganizations = [new OrganizationDto("key", "name", "desc"), new OrganizationDto("key2", "name2", "desc2")];
connectionConfigurationSlCoreService.ListUserOrganizationsAsync(Arg.Any<ListUserOrganizationsParams>())

connectionConfigurationSlCoreService.ListUserOrganizationsAsync(Arg.Is<ListUserOrganizationsParams>(x => IsExpectedCredentials(x.credentials, Token) && IsEuRegion(x)))
.Returns(new ListUserOrganizationsResponse(serverOrganizations));

var response = await testSubject.GetOrganizationsAsync(new TokenCredentialsModel("token".CreateSecureString()));
var response = await testSubject.GetOrganizationsAsync(new TokenCredentialsModel(Token.CreateSecureString()));

response.Success.Should().BeTrue();
response.ResponseData.Should().BeEquivalentTo([
Expand Down Expand Up @@ -466,6 +468,8 @@ private bool IsExpectedSonarQubeConnectionParams(Either<TransientSonarQubeConnec
return transientSonarQubeDto.serverUrl == sonarQubeConnectionInfo.Id && IsExpectedCredentials(transientSonarQubeDto.credentials, username, password);
}

private static bool IsEuRegion(ListUserOrganizationsParams x) => x.region == SonarCloudRegion.EU;

private static bool IsExpectedCredentials(Either<TokenDto, UsernamePasswordDto> credentials, string token)
{
return credentials.Left.token == token;
Expand Down
2 changes: 1 addition & 1 deletion src/EmbeddedSonarAnalyzer.props
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
<EmbeddedSonarHtmlAnalyzerVersion>3.18.0.5605</EmbeddedSonarHtmlAnalyzerVersion>
<EmbeddedSonarSecretsJarVersion>2.20.0.5038</EmbeddedSonarSecretsJarVersion>
<!-- SLOOP: Binaries for SonarLint Out Of Process -->
<EmbeddedSloopVersion>10.13.0.79996</EmbeddedSloopVersion>
<EmbeddedSloopVersion>10.14.0.80189</EmbeddedSloopVersion>
</PropertyGroup>
</Project>
3 changes: 2 additions & 1 deletion src/SLCore.IntegrationTests/InitializationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ public async Task Sloop_StartedAndStoppedWithoutErrors()
VerifyNoErrorsInLogs(testLogger);
VerifyNoErrorsInLogs(slCoreErrorLogger);
VerifyLogMessagesReceived(slCoreLogger);
slCoreLogger.AssertPartialOutputStringExists("SonarLint backend started");
slCoreLogger.AssertPartialOutputStringExists("Telemetry disabled on server startup");
slCoreLogger.AssertPartialOutputStringDoesNotExist("Internal error");
}

[TestMethod]
Expand Down
2 changes: 1 addition & 1 deletion src/SLCore.IntegrationTests/SLCoreTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public void Start()
foldersProvider.GetWorkFolders().Returns(new SLCoreFolders(storageRoot, workDir, userHome));

var connectionProvider = Substitute.For<IServerConnectionsProvider>();
connectionProvider.GetServerConnections().Returns(new Dictionary<string, ServerConnectionConfiguration>());
connectionProvider.GetServerConnections().Returns(new Dictionary<string, ServerConnectionConfigurationDtoBase>());

var jarProvider = Substitute.For<ISLCoreEmbeddedPluginJarLocator>();
jarProvider.ListJarFiles().Returns(DependencyLocator.AnalyzerPlugins);
Expand Down
2 changes: 1 addition & 1 deletion src/SLCore.UnitTests/SLCoreInstanceHandleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ private void SetUpSuccessfulInitialization(out ILifecycleManagementSLCoreService
constantsProvider.TelemetryConstants.Returns(TelemetryConstants);

foldersProvider.GetWorkFolders().Returns(new SLCoreFolders(StorageRoot, WorkDir, UserHome));
connectionsProvider.GetServerConnections().Returns(new Dictionary<string, ServerConnectionConfiguration>
connectionsProvider.GetServerConnections().Returns(new Dictionary<string, ServerConnectionConfigurationDtoBase>
{
{ SonarQubeConnection1.connectionId, SonarQubeConnection1 },
{ SonarQubeConnection2.connectionId, SonarQubeConnection2 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ public void Serialize_WithSonarCloudToken_AsExpected()
"organization": "my-org",
"credentials": {
"token": "super-secret-token"
}
},
"region": "EU"
}
}
""";
Expand Down Expand Up @@ -131,7 +132,8 @@ public void Serialize_WithSonarCloudUsernamePassword_AsExpected()
"credentials": {
"username": "[email protected]",
"password": "betwEEn-me-and-U"
}
},
"region": "EU"
}
}
""";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ public void Serialize_WithSonarCloudToken_AsExpected()
"organization": "my-org",
"credentials": {
"token": "super-secret-token"
}
},
"region": "EU"
},
"projectKeys": [
"project-key-1",
Expand Down Expand Up @@ -149,7 +150,8 @@ public void Serialize_WithSonarCloudUsernamePassword_AsExpected()
"credentials": {
"username": "[email protected]",
"password": "betwEEn-me-and-U"
}
},
"region": "EU"
},
"projectKeys": [
"project-key-1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,43 +22,62 @@
using SonarLint.VisualStudio.SLCore.Common.Models;
using SonarLint.VisualStudio.SLCore.Protocol;
using SonarLint.VisualStudio.SLCore.Service.Connection;
using SonarLint.VisualStudio.SLCore.Service.Connection.Models;

namespace SonarLint.VisualStudio.SLCore.UnitTests.Service.Connection;

[TestClass]
public class ListUserOrganizationsParamsTests
{

[DataRow(SonarCloudRegion.EU, """
{
"credentials": {
"username": "myUser",
"password": "password"
},
"region": "EU"
}
""")]
[DataRow(SonarCloudRegion.US, """
{
"credentials": {
"username": "myUser",
"password": "password"
},
"region": "US"
}
""")]
[TestMethod]
public void Ctor_UsernamePasswordIsUsed_SerializeAsExpected()
public void Ctor_UsernamePasswordIsUsed_SerializeAsExpected(SonarCloudRegion region, string expectedString)
{
var testSubject = new ListUserOrganizationsParams(Either<TokenDto, UsernamePasswordDto>.CreateRight(new UsernamePasswordDto("myUser", "password")));

const string expectedString = """
{
"credentials": {
"username": "myUser",
"password": "password"
}
}
""";
var testSubject = new ListUserOrganizationsParams(new UsernamePasswordDto("myUser", "password"), region);

var serializedString = JsonConvert.SerializeObject(testSubject, Formatting.Indented);

serializedString.Should().Be(expectedString);
}

[TestMethod]
public void Ctor_TokenIsUsed_SerializeAsExpected()
[DataRow(SonarCloudRegion.EU, """
{
"credentials": {
"token": "mytoken"
},
"region": "EU"
}
""")]
[DataRow(SonarCloudRegion.US, """
{
"credentials": {
"token": "mytoken"
},
"region": "US"
}
""")]
[DataTestMethod]
public void Ctor_TokenIsUsed_SerializeAsExpected(SonarCloudRegion region, string expectedString)
{
var testSubject = new ListUserOrganizationsParams(Either<TokenDto, UsernamePasswordDto>.CreateLeft(new TokenDto("mytoken")));

const string expectedString = """
{
"credentials": {
"token": "mytoken"
}
}
""";
var testSubject = new ListUserOrganizationsParams(new TokenDto("mytoken"), region);

var serializedString = JsonConvert.SerializeObject(testSubject, Formatting.Indented);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* SonarLint for Visual Studio
* Copyright (C) 2016-2025 SonarSource SA
* mailto:info AT sonarsource DOT com
*
* This program 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.
*
* This program 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.
*/

using Newtonsoft.Json;
using SonarLint.VisualStudio.SLCore.Service.Connection.Models;

namespace SonarLint.VisualStudio.SLCore.UnitTests.Service.Connection.Models;

[TestClass]
public class SonarCloudConnectionConfigurationDtoTests
{

[DataRow("id", true, "org", SonarCloudRegion.EU, """
{
"organization": "org",
"region": "EU",
"connectionId": "id",
"disableNotification": true
}
""")]
[DataRow("id id id", true, "org", SonarCloudRegion.EU, """
{
"organization": "org",
"region": "EU",
"connectionId": "id id id",
"disableNotification": true
}
""")]
[DataRow("id", false, "org", SonarCloudRegion.EU, """
{
"organization": "org",
"region": "EU",
"connectionId": "id",
"disableNotification": false
}
""")]
[DataRow("id", true, "org org org", SonarCloudRegion.EU, """
{
"organization": "org org org",
"region": "EU",
"connectionId": "id",
"disableNotification": true
}
""")]
[DataRow("id", true, "org", SonarCloudRegion.US, """
{
"organization": "org",
"region": "US",
"connectionId": "id",
"disableNotification": true
}
""")]
[DataTestMethod]
public void Serialize_AsExpected(string id, bool notificationEnabled, string organization, SonarCloudRegion region, string expected) =>
JsonConvert.SerializeObject(new SonarCloudConnectionConfigurationDto(id, notificationEnabled, organization, region), Formatting.Indented).Should().Be(expected);
}
Loading

0 comments on commit 3edccfa

Please sign in to comment.