Skip to content

Commit 0e3a5a1

Browse files
authored
Refactor nuspec scrubbing to use XML parsing (#6)
* XML-based scrubbing * Add test to ensure scrubbers are opt-in * Add test cases to cover missing attributes for repository scrubbing
1 parent 79dfbd4 commit 0e3a5a1

File tree

29 files changed

+332
-161
lines changed

29 files changed

+332
-161
lines changed

Tests/Verify.Nupkg.Tests/NuspecScrubbingTests.AddGitExtensionToRepoUrl/manifest.verified.nuspec

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
2-
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
1+
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
32
<metadata>
43
<id>SimplePackage</id>
54
<version>********</version>

Tests/Verify.Nupkg.Tests/NuspecScrubbingTests.DoNotScrubGitExtensionOnRepoUrl/manifest.verified.nuspec

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
2-
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
1+
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
32
<metadata>
43
<id>PackageWithRepoGitExtension</id>
54
<version>********</version>

Tests/Verify.Nupkg.Tests/NuspecScrubbingTests.DoNotScrubNonGitHubDomainRepoUrl/manifest.verified.nuspec

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
2-
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
1+
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
32
<metadata>
43
<id>PackageWithoutRepoGitHubDomain</id>
54
<version>********</version>

Tests/Verify.Nupkg.Tests/NuspecScrubbingTests.DoNotScrubNonHttpsRepoUrl/manifest.verified.nuspec

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
2-
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
1+
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
32
<metadata>
43
<id>PackageWithoutRepoHttps</id>
54
<version>********</version>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/
2+
|-- PackageWithoutRepoUrlOrCommit.nuspec
3+
|-- lib
4+
|-- net8.0
5+
|-- PackageWithoutRepoUrlOrCommit.dll
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
2+
<metadata>
3+
<id>PackageWithoutRepoUrlOrCommit</id>
4+
<version>********</version>
5+
<authors>PackageWithoutRepoUrlOrCommit</authors>
6+
<description>Package Description</description>
7+
<repository type="git" />
8+
<dependencies>
9+
<group targetFramework="net8.0" />
10+
</dependencies>
11+
</metadata>
12+
</package>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/
2+
|-- PackageWithoutRepoUrlOrCommit.nuspec
3+
|-- lib
4+
|-- net8.0
5+
|-- PackageWithoutRepoUrlOrCommit.dll
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
2+
<metadata>
3+
<id>PackageWithoutRepoUrlOrCommit</id>
4+
<version>********</version>
5+
<authors>PackageWithoutRepoUrlOrCommit</authors>
6+
<description>Package Description</description>
7+
<repository type="git" />
8+
<dependencies>
9+
<group targetFramework="net8.0" />
10+
</dependencies>
11+
</metadata>
12+
</package>

Tests/Verify.Nupkg.Tests/NuspecScrubbingTests.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ public class NuspecScrubbingTests
66
private string _packageWithoutRepoGitExtension = SamplePackages.Instance.PackageWithoutRepoGitExtension.Value.FullName;
77
private string _packageWithoutRepoHttps = SamplePackages.Instance.PackageWithoutRepoHttps.Value.FullName;
88
private string _packageWithoutRepoGitHubDomain = SamplePackages.Instance.PackageWithoutRepoGitHubDomain.Value.FullName;
9+
private string _packageWithoutRepoUrl = SamplePackages.Instance.PackageWithoutRepoUrl.Value.FullName;
10+
private string _packageWithoutRepoCommit = SamplePackages.Instance.PackageWithoutRepoCommit.Value.FullName;
911

1012
[Fact]
1113
public Task DoNotScrubGitExtensionOnRepoUrl()
@@ -46,4 +48,24 @@ public Task DoNotScrubNonGitHubDomainRepoUrl()
4648

4749
return VerifyFile(_packageWithoutRepoGitHubDomain, settings);
4850
}
51+
52+
[Fact]
53+
public Task SkipScrubbingForRepoWithNoCommit()
54+
{
55+
VerifySettings settings = new();
56+
settings.UseUniqueDirectory();
57+
settings.ScrubNuspec();
58+
59+
return VerifyFile(_packageWithoutRepoCommit, settings);
60+
}
61+
62+
[Fact]
63+
public Task SkipScrubbingForRepoWithNoUrl()
64+
{
65+
VerifySettings settings = new();
66+
settings.UseUniqueDirectory();
67+
settings.ScrubNuspec();
68+
69+
return VerifyFile(_packageWithoutRepoUrl, settings);
70+
}
4971
}

Tests/Verify.Nupkg.Tests/SamplePackages/PackageWithoutRepoHttps.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,15 @@ protected override ProjectCreator CreateCore(IDirectoryInfo workingDirectory)
1616
.Property("RepositoryCommit", "0e4d1b598f350b3dc675018d539114d1328189ef");
1717
}
1818
}
19+
20+
internal class PackageWithoutRepoUrlOrCommit : PackageCreator
21+
{
22+
public override string Name => GetType().Name;
23+
24+
protected override ProjectCreator CreateCore(IDirectoryInfo workingDirectory)
25+
{
26+
return ProjectCreator.Templates.SdkCsproj()
27+
.Property("TargetFramework", "net8.0")
28+
.Property("RepositoryType", "git");
29+
}
30+
}

0 commit comments

Comments
 (0)