Skip to content

Commit 6f8fe55

Browse files
authored
Typo-squatting: finish functional tests (#6497)
* Finish typo-squatting functional tests * Refactor Functional Tests * delete string.format * Retry
1 parent dd91e10 commit 6f8fe55

6 files changed

Lines changed: 58 additions & 0 deletions

File tree

tests/NuGetGallery.Facts/Services/PackageUploadServiceFacts.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,7 @@ public async Task RejectIsTyposquattingNewVersion()
770770

771771
Assert.Equal(PackageValidationResultType.Invalid, result.Type);
772772
Assert.Equal(string.Format(Strings.TyposquattingCheckFails, string.Join(",", _typosquattingCheckCollisionIds)), result.Message);
773+
Assert.Contains("similar", result.Message);
773774
Assert.Empty(result.Warnings);
774775
}
775776
}

tests/NuGetGallery.FunctionalTests.Core/GalleryConfiguration.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ public class GalleryConfiguration
3838
public OrganizationConfiguration CollaboratorOrganization { get; private set; }
3939
[JsonProperty]
4040
public BrandingConfiguration Branding { get; private set; }
41+
[JsonProperty]
42+
public bool TyposquattingCheckAndBlockUsers { get; private set; }
4143

4244
static GalleryConfiguration()
4345
{

tests/NuGetGallery.FunctionalTests.Core/NuGetGallery.FunctionalTests.Core.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
<Compile Include="Helpers\NuspecHelper.cs" />
9292
<Compile Include="Helpers\ODataHelper.cs" />
9393
<Compile Include="Helpers\PackageCreationHelper.cs" />
94+
<Compile Include="XunitExtensions\TyposquattingTestFactAttribute.cs" />
9495
<Compile Include="XunitExtensions\PriorityAttribute.cs" />
9596
<Compile Include="Properties\AssemblyInfo.cs" />
9697
<Compile Include="XunitExtensions\CategoryDiscoverer.cs" />
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using Xunit;
5+
6+
namespace NuGetGallery.FunctionalTests.XunitExtensions
7+
{
8+
public class TyposquattingTestFactAttribute : FactAttribute
9+
{
10+
public TyposquattingTestFactAttribute()
11+
{
12+
if (!GalleryConfiguration.Instance.TyposquattingCheckAndBlockUsers)
13+
{
14+
Skip = "Typosquatting checking or user blocking are disabled";
15+
}
16+
}
17+
}
18+
}

tests/NuGetGallery.FunctionalTests/NuGetGallery.FunctionalTests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@
9292
<Compile Include="Security\HttpToHttpsRedirectTests.cs" />
9393
<Compile Include="Statistics\PackageStatisticsTests.cs" />
9494
<Compile Include="ODataFeeds\V2FeedTests.cs" />
95+
<Compile Include="TyposquattingCheck\TyposquattingCheckForUploadPackageTests.cs" />
9596
<Compile Include="WebPages\FluentLinkChecker.cs" />
9697
<Compile Include="WebPages\LinksTests.cs" />
9798
<Compile Include="Properties\AssemblyInfo.cs" />
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System;
5+
using System.Threading.Tasks;
6+
using Xunit;
7+
using Xunit.Abstractions;
8+
using NuGetGallery.FunctionalTests.XunitExtensions;
9+
10+
namespace NuGetGallery.FunctionalTests.TyposquattingCheck
11+
{
12+
public class TyposquattingCheckForUploadPackageTests : GalleryTestBase
13+
{
14+
private readonly CommandlineHelper _commandlineHelper;
15+
private readonly PackageCreationHelper _packageCreationHelper;
16+
public TyposquattingCheckForUploadPackageTests(ITestOutputHelper testOutputHelper) : base(testOutputHelper)
17+
{
18+
_commandlineHelper = new CommandlineHelper(TestOutputHelper);
19+
_packageCreationHelper = new PackageCreationHelper(testOutputHelper);
20+
}
21+
22+
[TyposquattingTestFact]
23+
public async Task UploadTyposquattingPackageAndBlockUser()
24+
{
25+
var packageId = "newtonsoft-json";
26+
string version = "1.0.0";
27+
string packageFullPath = await _packageCreationHelper.CreatePackageWithMinClientVersion(packageId, version, "2.3");
28+
29+
var processResult = await _commandlineHelper.UploadPackageAsync(packageFullPath, UrlHelper.V2FeedPushSourceUrl);
30+
31+
Assert.True(processResult.ExitCode == 1, Constants.UploadFailureMessage);
32+
Assert.Contains("similar", processResult.StandardError);
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)