-
-
Notifications
You must be signed in to change notification settings - Fork 0
Bugfix/statusbar and naming #16
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
a068e76
Security hardening: trust management, signatures, onboarding
Hefaistos68 ebec183
several corrections
Hefaistos68 27aaa37
some more corrections
Hefaistos68 0842777
removed preview flag
Hefaistos68 ef30cab
Fix for a wrong status in the statusbar after full trust
Hefaistos68 cc467f4
Merge branch 'master' into bugfix/statusbar-and-naming
Hefaistos68 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
MSBuildGuard.VisualStudio.Tests/ToolWindows/BuildBlockDialogViewModelTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.IO; | ||
| using MSBuildGuard.Core; | ||
| using MSBuildGuard.Core.Trust; | ||
| using MSBuildGuard.VisualStudio.ToolWindows; | ||
| using NUnit.Framework; | ||
| using Shouldly; | ||
|
|
||
| namespace MSBuildGuard.VisualStudio.ToolWindows.Tests | ||
| { | ||
| /// <summary> | ||
| /// Unit tests for the <see cref="BuildBlockDialogViewModel"/> class. | ||
| /// </summary> | ||
| [TestFixture] | ||
| public sealed class BuildBlockDialogViewModelTests | ||
| { | ||
| private string tempDir = string.Empty; | ||
|
|
||
| /// <summary> | ||
| /// Sets up the test environment. | ||
| /// </summary> | ||
| [SetUp] | ||
| public void SetUp() | ||
| { | ||
| this.tempDir = Path.Combine(Path.GetTempPath(), "MSBuildGuardTests", Guid.NewGuid().ToString("N")); | ||
|
|
||
| Directory.CreateDirectory(this.tempDir); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Tears down the test environment. | ||
| /// </summary> | ||
| [TearDown] | ||
| public void TearDown() | ||
| { | ||
| if (Directory.Exists(this.tempDir)) | ||
| { | ||
| try | ||
| { | ||
| Directory.Delete(this.tempDir, true); | ||
| } | ||
| catch | ||
| { | ||
| // Ignore clean up errors. | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Verifies that risk score calculation correctly ignores trusted findings. | ||
| /// </summary> | ||
| [Test] | ||
| public void Constructor_WithTrustedFindings_CalculatesCorrectRiskScore() | ||
| { | ||
| var report = new ScanReport(); | ||
|
|
||
| report.Target.TargetPath = Path.Combine(this.tempDir, "TestSolution.sln"); | ||
| report.Target.TargetKind = TargetKind.Solution; | ||
|
|
||
| var finding = new Finding | ||
| { | ||
| Id = "MBG001", | ||
| Title = "Test Finding", | ||
| Severity = FindingSeverity.Medium, | ||
| FilePath = Path.Combine(this.tempDir, "TestProj.csproj"), | ||
| Fingerprint = "fingerprint-1" | ||
| }; | ||
|
|
||
| report.Findings.Add(finding); | ||
|
|
||
| var fileRecord = new MsBuildFileRecord | ||
| { | ||
| Path = finding.FilePath, | ||
| NormalizedSha256 = "sha256-hash-value" | ||
| }; | ||
|
|
||
| report.FilesScanned.Add(fileRecord); | ||
|
|
||
| var userTrustPath = new TrustStoreService().GetDefaultUserTrustPath(); | ||
| var model = new BuildBlockDialogViewModel(report, this.tempDir); | ||
|
|
||
| // Initially, the finding is not trusted. | ||
| model.RiskScore.ShouldBe(20); | ||
|
|
||
| // Now we write a trust entry for it. | ||
| var trustStoreService = new TrustStoreService(); | ||
| var userTrustStore = trustStoreService.Load(userTrustPath); | ||
| var originalDecisions = new List<TrustDecisionEntry>(userTrustStore.Decisions); | ||
|
Hefaistos68 marked this conversation as resolved.
|
||
|
|
||
| try | ||
| { | ||
| trustStoreService.AddDecision(userTrustPath, new TrustDecisionEntry | ||
| { | ||
| DecisionId = Guid.NewGuid().ToString("N"), | ||
| Scope = "Finding", | ||
| SubjectHash = "fingerprint-1", | ||
| Decision = "Trust", | ||
| Reason = "Test trust", | ||
| UserSid = "TestSid", | ||
| CreatedAtUtc = DateTimeOffset.UtcNow | ||
| }); | ||
|
|
||
| var model2 = new BuildBlockDialogViewModel(report, this.tempDir); | ||
|
|
||
| model2.RiskScore.ShouldBe(0); | ||
| model2.RecommendedAction.ShouldBe(RecommendedAction.Allow.ToString()); | ||
| } | ||
| finally | ||
| { | ||
| // Restore the original user trust store to not pollute the host. | ||
| userTrustStore.Decisions.Clear(); | ||
|
|
||
| foreach (var d in originalDecisions) | ||
| { | ||
| userTrustStore.Decisions.Add(d); | ||
| } | ||
|
|
||
| trustStoreService.Save(userTrustPath, userTrustStore); | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.