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-1460 Hardening 8.4 #5721

Merged
merged 6 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 1 addition & 9 deletions src/CFamily.UnitTests/Subprocess/ProcessRunnerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,7 @@
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using FluentAssertions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SonarLint.VisualStudio.CFamily.Helpers.UnitTests;
using SonarLint.VisualStudio.Core;
using SonarLint.VisualStudio.TestInfrastructure;
Expand Down Expand Up @@ -394,7 +387,6 @@ xxx yyy
}

[TestMethod]
[Ignore] // https://sonarsource.atlassian.net/browse/SLVS-1428
public void Execute_CancellationTokenCancelledMidway_CancelledDuringWritingRequest_ProcessKilled()
{
var exeName = WriteBatchFileForTest(TestContext, @"
Expand Down Expand Up @@ -492,7 +484,7 @@ private static void AssertTextDoesNotAppearInLog(string text, TestLogger logger)
private static string WriteBatchFileForTest(TestContext context, string content)
{
var testPath = CreateTestSpecificFolder(context);
var fileName = Path.Combine(testPath, context.TestName + ".bat");
var fileName = Path.Combine(testPath, "test.bat");
File.Exists(fileName).Should().BeFalse("Not expecting a batch file to already exist: {0}", fileName);
File.WriteAllText(fileName, content);
return fileName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,33 +27,33 @@
namespace SonarLint.VisualStudio.ConnectedMode.UnitTests.Persistence;

[TestClass]
public class BindingDtoConverterTests
public class BindingJsonModelConverterTests
{
private BindingDtoConverter testSubject;
private BindingJsonModelConverter testSubject;

[TestInitialize]
public void TestInitialize()
{
testSubject = new BindingDtoConverter();
testSubject = new BindingJsonModelConverter();
}

[TestMethod]
public void MefCtor_CheckIsExported()
{
MefTestHelpers.CheckTypeCanBeImported<BindingDtoConverter, IBindingDtoConverter>();
MefTestHelpers.CheckTypeCanBeImported<BindingJsonModelConverter, IBindingJsonModelConverter>();
}

[TestMethod]
public void MefCtor_CheckIsSingleton()
{
MefTestHelpers.CheckIsSingletonMefComponent<BindingDtoConverter>();
MefTestHelpers.CheckIsSingletonMefComponent<BindingJsonModelConverter>();
}

[TestMethod]
public void ConvertFromDto_ConvertsCorrectly()
public void ConvertFromModel_ConvertsCorrectly()
{
const string localBindingKey = "solution123";
var bindingDto = new BindingDto
var bindingModel = new BindingJsonModel
{
ProjectKey = "project123",
Profiles = new Dictionary<Language, ApplicableQualityProfile>(),
Expand All @@ -64,55 +64,55 @@ public void ConvertFromDto_ConvertsCorrectly()
};
var connection = new ServerConnection.SonarCloud("myorg");

var boundServerProject = testSubject.ConvertFromDto(bindingDto, connection, localBindingKey);
var boundServerProject = testSubject.ConvertFromModel(bindingModel, connection, localBindingKey);

boundServerProject.ServerConnection.Should().BeSameAs(connection);
boundServerProject.LocalBindingKey.Should().BeSameAs(localBindingKey);
boundServerProject.ServerProjectKey.Should().BeSameAs(bindingDto.ProjectKey);
boundServerProject.Profiles.Should().BeSameAs(bindingDto.Profiles);
boundServerProject.ServerProjectKey.Should().BeSameAs(bindingModel.ProjectKey);
boundServerProject.Profiles.Should().BeSameAs(bindingModel.Profiles);
}

[TestMethod]
public void ConvertToDto_SonarCloudConnection_ConvertsCorrectly()
public void ConvertToModel_SonarCloudConnection_ConvertsCorrectly()
{
var boundServerProject = new BoundServerProject("localBinding", "serverProject", new ServerConnection.SonarCloud("myorg"))
{
Profiles = new Dictionary<Language, ApplicableQualityProfile>()
};

var bindingDto = testSubject.ConvertToDto(boundServerProject);
var bindingModel = testSubject.ConvertToModel(boundServerProject);

bindingDto.ProjectKey.Should().BeSameAs(boundServerProject.ServerProjectKey);
bindingDto.ProjectName.Should().BeNull();
bindingDto.ServerUri.Should().BeEquivalentTo(boundServerProject.ServerConnection.ServerUri);
bindingDto.Organization.Key.Should().BeSameAs(((ServerConnection.SonarCloud)boundServerProject.ServerConnection).OrganizationKey);
bindingDto.ServerConnectionId.Should().BeSameAs(boundServerProject.ServerConnection.Id);
bindingDto.Profiles.Should().BeSameAs(boundServerProject.Profiles);
bindingModel.ProjectKey.Should().BeSameAs(boundServerProject.ServerProjectKey);
bindingModel.ProjectName.Should().BeNull();
bindingModel.ServerUri.Should().BeEquivalentTo(boundServerProject.ServerConnection.ServerUri);
bindingModel.Organization.Key.Should().BeSameAs(((ServerConnection.SonarCloud)boundServerProject.ServerConnection).OrganizationKey);
bindingModel.ServerConnectionId.Should().BeSameAs(boundServerProject.ServerConnection.Id);
bindingModel.Profiles.Should().BeSameAs(boundServerProject.Profiles);
}

[TestMethod]
public void ConvertToDto_SonarQubeConnection_ConvertsCorrectly()
public void ConvertToModel_SonarQubeConnection_ConvertsCorrectly()
{
var boundServerProject = new BoundServerProject("localBinding", "serverProject", new ServerConnection.SonarQube(new Uri("http://mysq")))
{
Profiles = new Dictionary<Language, ApplicableQualityProfile>()
};

var bindingDto = testSubject.ConvertToDto(boundServerProject);
var bindingModel = testSubject.ConvertToModel(boundServerProject);

bindingDto.ProjectKey.Should().BeSameAs(boundServerProject.ServerProjectKey);
bindingDto.ProjectName.Should().BeNull();
bindingDto.ServerUri.Should().BeEquivalentTo(boundServerProject.ServerConnection.ServerUri);
bindingDto.Organization.Should().BeNull();
bindingDto.ServerConnectionId.Should().BeSameAs(boundServerProject.ServerConnection.Id);
bindingDto.Profiles.Should().BeSameAs(boundServerProject.Profiles);
bindingModel.ProjectKey.Should().BeSameAs(boundServerProject.ServerProjectKey);
bindingModel.ProjectName.Should().BeNull();
bindingModel.ServerUri.Should().BeEquivalentTo(boundServerProject.ServerConnection.ServerUri);
bindingModel.Organization.Should().BeNull();
bindingModel.ServerConnectionId.Should().BeSameAs(boundServerProject.ServerConnection.Id);
bindingModel.Profiles.Should().BeSameAs(boundServerProject.Profiles);
}

[TestMethod]
public void ConvertFromDtoToLegacy_ConvertsCorrectly()
public void ConvertFromModelToLegacy_ConvertsCorrectly()
{
var credentials = Substitute.For<ICredentials>();
var bindingDto = new BindingDto
var bindingModel = new BindingJsonModel
{
Organization = new SonarQubeOrganization("org", "my org"),
ServerUri = new Uri("http://localhost"),
Expand All @@ -122,12 +122,12 @@ public void ConvertFromDtoToLegacy_ConvertsCorrectly()
ServerConnectionId = "ignored",
};

var legacyBinding = testSubject.ConvertFromDtoToLegacy(bindingDto, credentials);
var legacyBinding = testSubject.ConvertFromModelToLegacy(bindingModel, credentials);

legacyBinding.ProjectKey.Should().BeSameAs(bindingDto.ProjectKey);
legacyBinding.ProjectName.Should().BeSameAs(bindingDto.ProjectName);
legacyBinding.ServerUri.Should().BeSameAs(bindingDto.ServerUri);
legacyBinding.Organization.Should().BeSameAs(bindingDto.Organization);
legacyBinding.ProjectKey.Should().BeSameAs(bindingModel.ProjectKey);
legacyBinding.ProjectName.Should().BeSameAs(bindingModel.ProjectName);
legacyBinding.ServerUri.Should().BeSameAs(bindingModel.ServerUri);
legacyBinding.Organization.Should().BeSameAs(bindingModel.Organization);
legacyBinding.Profiles.Should().BeSameAs(legacyBinding.Profiles);
legacyBinding.Credentials.Should().BeSameAs(credentials);
}
Expand Down
Loading
Loading