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

SLVS-1818 Upgrade SLCore to 10.14.0.80189 and adapt RPC changes for SQC multi-region #5985

Merged
merged 5 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 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) && x.region == SonarCloudRegion.EU));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a helper method to check the region, i.e. IsExpectedRegion

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really see the point of creating a method to replace one equals expression

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this occurs in multiple places. And if something changes, it would be easier to just modify one helper method instead of multiple places.

}

[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 => x.credentials.Left.token == token && x.region == SonarCloudRegion.EU))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
connectionConfigurationSlCoreService.ListUserOrganizationsAsync(Arg.Is<ListUserOrganizationsParams>(x => x.credentials.Left.token == token && x.region == SonarCloudRegion.EU))
connectionConfigurationSlCoreService.ListUserOrganizationsAsync(Arg.Is<ListUserOrganizationsParams>(x => IsExpectedCredentials(x.credentials, token) && IsExpectedRegion(x.region)))

.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 => x.credentials.Left.token == token && x.region == SonarCloudRegion.EU))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
connectionConfigurationSlCoreService.ListUserOrganizationsAsync(Arg.Is<ListUserOrganizationsParams>(x => x.credentials.Left.token == token && x.region == SonarCloudRegion.EU))
connectionConfigurationSlCoreService.ListUserOrganizationsAsync(Arg.Is<ListUserOrganizationsParams>(x => IsExpectedCredentials(x.credentials, token) && IsExpectedRegion(x.region)))

.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
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);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* 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.Common.Models;
using SonarLint.VisualStudio.SLCore.Service.Connection.Models;

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

[TestClass]
public class TransientSonarCloudConnectionDtoTests
{
[DataRow("my org", SonarCloudRegion.US, """
{
"organization": "my org",
"credentials": {
"token": "abctoken"
},
"region": "US"
}
""")]
[DataRow("my org two", SonarCloudRegion.EU, """
{
"organization": "my org two",
"credentials": {
"token": "abctoken"
},
"region": "EU"
}
""")]
[DataTestMethod]
public void Serialized_Token_AsExpected(string organization, SonarCloudRegion region, string expected) =>
JsonConvert.SerializeObject(new TransientSonarCloudConnectionDto(organization, new TokenDto("abctoken"), region), Formatting.Indented).Should().Be(expected);

[DataRow("my org", SonarCloudRegion.US, """
{
"organization": "my org",
"credentials": {
"username": "usr",
"password": "pwd"
},
"region": "US"
}
""")]
[DataRow("my org two", SonarCloudRegion.EU, """
{
"organization": "my org two",
"credentials": {
"username": "usr",
"password": "pwd"
},
"region": "EU"
}
""")]
[DataTestMethod]
public void Serialized_UsernameAndPassword_AsExpected(string organization, SonarCloudRegion region, string expected) =>
JsonConvert.SerializeObject(new TransientSonarCloudConnectionDto(organization, new UsernamePasswordDto("usr", "pwd"), region), Formatting.Indented).Should().Be(expected);
}
Loading