Skip to content

Commit

Permalink
SLVS-1592 Update TaintStore with taints from SLCore
Browse files Browse the repository at this point in the history
  • Loading branch information
georgii-borovinskikh-sonarsource committed Nov 11, 2024
1 parent 12fa01e commit ccd15a9
Show file tree
Hide file tree
Showing 11 changed files with 651 additions and 801 deletions.
2 changes: 1 addition & 1 deletion src/Core/IFolderWorkspaceMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ public interface IFolderWorkspaceMonitor
/// We need this event since certain parts of our code, i.e. <see cref="IAbsoluteFilePathLocator"/>,
/// rely on VsHierarchy being initialized by the time they're called.
/// </remarks>
event EventHandler FolderWorkspaceInitialized;
event EventHandler FolderWorkspaceInitialized; // todo
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* SonarLint for Visual Studio
* Copyright (C) 2016-2024 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 SonarLint.VisualStudio.IssueVisualization.Security.Taint;
using SonarLint.VisualStudio.SLCore.State;

namespace SonarLint.VisualStudio.IssueVisualization.Security.UnitTests.Taint;

[TestClass]
public class TaintIssuesConfigurationScopeMonitorTests
{
[TestMethod]
public void Ctor_SubscribesToConfigurationScopeEvents()
{
var activeConfigScopeTracker = Substitute.For<IActiveConfigScopeTracker>();

_ = new TaintIssuesConfigurationScopeMonitor(activeConfigScopeTracker, Substitute.For<ITaintIssuesSynchronizer>());

activeConfigScopeTracker.Received().CurrentConfigurationScopeChanged += Arg.Any<EventHandler>();
}

[TestMethod]
public void Dispose_UnsubscribesToConfigurationScopeEvents()
{
var activeConfigScopeTracker = Substitute.For<IActiveConfigScopeTracker>();
var testSubject = new TaintIssuesConfigurationScopeMonitor(activeConfigScopeTracker, Substitute.For<ITaintIssuesSynchronizer>());

testSubject.Dispose();

activeConfigScopeTracker.Received().CurrentConfigurationScopeChanged -= Arg.Any<EventHandler>();
}

[TestMethod]
public void ConfigScopeChangedEvent_CallsTaintSynchronizer()
{
var activeConfigScopeTracker = Substitute.For<IActiveConfigScopeTracker>();
var configurationScope = new ConfigurationScope("config scope");
activeConfigScopeTracker.Current.Returns(configurationScope);
var taintIssuesSynchronizer = Substitute.For<ITaintIssuesSynchronizer>();
_ = new TaintIssuesConfigurationScopeMonitor(activeConfigScopeTracker, taintIssuesSynchronizer);

activeConfigScopeTracker.CurrentConfigurationScopeChanged += Raise.Event<EventHandler>();

taintIssuesSynchronizer.Received(1).UpdateTaintVulnerabilitiesAsync(configurationScope);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* SonarLint for Visual Studio
* Copyright (C) 2016-2024 SonarSource SA
* mailto:info AT sonarsource DOT com
Expand Down Expand Up @@ -694,48 +694,6 @@ public void SetSelectedIssue_ValueIsTheSame_SelectionServiceNotCalled()
selectionService.VerifyNoOtherCalls();
}

[TestMethod]
public void AnalysisInformation_NoAnalysisInformation_Null()
{
var store = new Mock<ITaintStore>();
SetupAnalysisInformation(store, null);

var testSubject = CreateTestSubject(store: store);

testSubject.AnalysisInformation.Should().BeNull();
}

[TestMethod]
public void AnalysisInformation_HasAnalysisInformation_PropertySet()
{
var store = new Mock<ITaintStore>();
var analysisInformation = new AnalysisInformation("some branch", default);
SetupAnalysisInformation(store, analysisInformation);

var testSubject = CreateTestSubject(store: store);

testSubject.AnalysisInformation.Should().BeSameAs(analysisInformation);
}

[TestMethod]
public void AnalysisInformation_IssuesChanged_RaisesPropertyChanged()
{
var store = new Mock<ITaintStore>();
var testSubject = CreateTestSubject(store: store);

var eventHandler = new Mock<PropertyChangedEventHandler>();
testSubject.PropertyChanged += eventHandler.Object;

var analysisInformation = new AnalysisInformation("some branch", default);

SetupAnalysisInformation(store, analysisInformation);
RaiseStoreIssuesChangedEvent(store);

VerifyPropertyChangedWasRaised(eventHandler, nameof(testSubject.AnalysisInformation));

testSubject.AnalysisInformation.Should().BeSameAs(analysisInformation);
}

[TestMethod]
[DataRow(null, ServerType.SonarCloud, nameof(ServerType.SonarCloud), true)]
[DataRow(null, null, "", false)]
Expand Down Expand Up @@ -1011,10 +969,5 @@ private void VerifyPropertyChangedWasRaised(Mock<PropertyChangedEventHandler> ev
It.Is((PropertyChangedEventArgs e) => e.PropertyName == expectedProperty)),
Times.Once);
}

private void SetupAnalysisInformation(Mock<ITaintStore> store, AnalysisInformation analysisInformation)
{
store.Setup(x => x.GetAnalysisInformation()).Returns(analysisInformation);
}
}
}
Loading

0 comments on commit ccd15a9

Please sign in to comment.