diff --git a/tests/NuGetGallery.FunctionalTests.Core/EnvironmentSettings.cs b/tests/NuGetGallery.FunctionalTests.Core/EnvironmentSettings.cs index 5dba41eb0a..b35e70c1f6 100644 --- a/tests/NuGetGallery.FunctionalTests.Core/EnvironmentSettings.cs +++ b/tests/NuGetGallery.FunctionalTests.Core/EnvironmentSettings.cs @@ -2,6 +2,8 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; +using System.Collections.Generic; +using System.Linq; namespace NuGetGallery.FunctionalTests { @@ -18,6 +20,7 @@ public class EnvironmentSettings private static string _testEmailServerHost; private static string _runFunctionalTests; private static string _readOnlyMode; + private static List _trustedHttpsCertificates; /// /// Option to enable or disable functional tests from the current run. @@ -213,5 +216,42 @@ public static string TestEmailServerHost return _testEmailServerHost; } } + + public static IEnumerable TrustedHttpsCertificates + { + get + { + if (_trustedHttpsCertificates == null) + { + var unparsedValued = Environment.GetEnvironmentVariable("TrustedHttpsCertificates") ?? string.Empty; + + List pieces; + if (unparsedValued.Length == 0) + { + // This list will need to be modified as DEV, INT, and PROD certificates change and are + // renewed. These values are easily and publicly discoverable by inspecting the certificate + // returned from HTTPS browser interactions with the gallery. + pieces = new List + { + "8c11c16610b7a147d10bbcc6a65ce23d321c12c2", // *.nugettest.org + "9d984f91f40d8b3a1fb29153179415523c4e64d1", // *.int.nugettest.org + "3751cb513b93ee67ec9f18a1f2aec1eac87af9bc" // *.nuget.org + }; + } + else + { + pieces = unparsedValued + .Split(',') + .Select(p => p.Trim()) + .Where(p => p.Length > 0) + .ToList(); + } + + _trustedHttpsCertificates = pieces; + } + + return _trustedHttpsCertificates; + } + } } } diff --git a/tests/NuGetGallery.FunctionalTests.Core/Helpers/CommandlineHelper.cs b/tests/NuGetGallery.FunctionalTests.Core/Helpers/CommandlineHelper.cs index c2b442bc7c..179dabcc0c 100644 --- a/tests/NuGetGallery.FunctionalTests.Core/Helpers/CommandlineHelper.cs +++ b/tests/NuGetGallery.FunctionalTests.Core/Helpers/CommandlineHelper.cs @@ -156,7 +156,13 @@ public async Task InvokeNugetProcess(List arguments, stri var nugetProcess = new Process(); var pathToNugetExe = Path.Combine(Environment.CurrentDirectory, NugetExePath); + foreach (var trustedCertificate in EnvironmentSettings.TrustedHttpsCertificates) + { + arguments.AddRange(new[] { "-TrustedHttpsCertificate", trustedCertificate }); + } + arguments.Add(NonInteractiveSwitchString); + var argumentsString = string.Join(" ", arguments); WriteLine("The NuGet.exe command to be executed is: " + pathToNugetExe + " " + argumentsString); diff --git a/tests/NuGetGallery.FunctionalTests/Commandline/NuGetCommandLineTests.cs b/tests/NuGetGallery.FunctionalTests/Commandline/NuGetCommandLineTests.cs index ce53a67c4a..6dbe9d771b 100644 --- a/tests/NuGetGallery.FunctionalTests/Commandline/NuGetCommandLineTests.cs +++ b/tests/NuGetGallery.FunctionalTests/Commandline/NuGetCommandLineTests.cs @@ -13,8 +13,6 @@ namespace NuGetGallery.FunctionalTests.Commandline /// /// Tries to download and upload package from the gallery using NuGet.exe client. /// - // All the tests in this class fail due to the following error - // The package upload via Nuget.exe didn't succeed properly OR package download from V2 feed didn't work. Could not establish trust relationship for the SSL/TLS secure channel public class NugetCommandLineTests : GalleryTestBase { @@ -36,17 +34,13 @@ public NugetCommandLineTests(ITestOutputHelper testOutputHelper) [Category("P0Tests")] public async Task DownloadPackageWithNuGetCommandLineTest() { - // Temporary work around for the SSL issue, which keeps the upload tests from working on sites with cloudapp.net - if (UrlHelper.BaseUrl.Contains("nugettest.org") || UrlHelper.BaseUrl.Contains("nuget.org")) - { - string packageId = Constants.TestPackageId; //try to download a pre-defined test package. - _clientSdkHelper.ClearLocalPackageFolder(packageId, ClientSdkHelper.GetLatestStableVersion(packageId)); + string packageId = Constants.TestPackageId; //try to download a pre-defined test package. + _clientSdkHelper.ClearLocalPackageFolder(packageId, ClientSdkHelper.GetLatestStableVersion(packageId)); - var result = await _commandlineHelper.InstallPackageAsync(packageId, UrlHelper.V2FeedRootUrl, Environment.CurrentDirectory); + var result = await _commandlineHelper.InstallPackageAsync(packageId, UrlHelper.V2FeedRootUrl, Environment.CurrentDirectory); - Assert.True(result.ExitCode == 0, Constants.PackageDownloadFailureMessage); - Assert.True(_clientSdkHelper.CheckIfPackageInstalled(packageId), Constants.PackageInstallFailureMessage); - } + Assert.True(result.ExitCode == 0, Constants.PackageDownloadFailureMessage); + Assert.True(_clientSdkHelper.CheckIfPackageInstalled(packageId), Constants.PackageInstallFailureMessage); } [Fact] @@ -55,10 +49,7 @@ public async Task DownloadPackageWithNuGetCommandLineTest() [Category("P0Tests")] public async Task UploadPackageWithNuGetCommandLineTest() { - if (UrlHelper.BaseUrl.Contains("nugettest.org") || UrlHelper.BaseUrl.Contains("nuget.org")) - { - await _clientSdkHelper.UploadNewPackageAndVerify(DateTime.Now.Ticks.ToString()); - } + await _clientSdkHelper.UploadNewPackageAndVerify(DateTime.Now.Ticks.ToString()); } [Fact] @@ -67,28 +58,25 @@ public async Task UploadPackageWithNuGetCommandLineTest() [Category("P0Tests")] public async Task UploadAndDownLoadPackageWithMinClientVersion() { - if (UrlHelper.BaseUrl.Contains("nugettest.org") || UrlHelper.BaseUrl.Contains("nuget.org")) - { - string packageId = DateTime.Now.Ticks + "PackageWithDotCsNames.Cs"; - string version = "1.0.0"; - string packageFullPath = await _packageCreationHelper.CreatePackageWithMinClientVersion(packageId, version, "2.3"); + string packageId = DateTime.Now.Ticks + "PackageWithDotCsNames.Cs"; + string version = "1.0.0"; + string packageFullPath = await _packageCreationHelper.CreatePackageWithMinClientVersion(packageId, version, "2.3"); - var processResult = await _commandlineHelper.UploadPackageAsync(packageFullPath, UrlHelper.V2FeedPushSourceUrl); + var processResult = await _commandlineHelper.UploadPackageAsync(packageFullPath, UrlHelper.V2FeedPushSourceUrl); - Assert.True(processResult.ExitCode == 0, Constants.UploadFailureMessage); + Assert.True(processResult.ExitCode == 0, Constants.UploadFailureMessage); - var packageVersionExistsInSource = _clientSdkHelper.CheckIfPackageVersionExistsInSource(packageId, version, UrlHelper.V2FeedRootUrl); - var userMessage = string.Format(Constants.PackageNotFoundAfterUpload, packageId, UrlHelper.V2FeedRootUrl); - Assert.True(packageVersionExistsInSource, userMessage); + var packageVersionExistsInSource = _clientSdkHelper.CheckIfPackageVersionExistsInSource(packageId, version, UrlHelper.V2FeedRootUrl); + var userMessage = string.Format(Constants.PackageNotFoundAfterUpload, packageId, UrlHelper.V2FeedRootUrl); + Assert.True(packageVersionExistsInSource, userMessage); - //Delete package from local disk so once it gets uploaded - if (File.Exists(packageFullPath)) - { - File.Delete(packageFullPath); - Directory.Delete(Path.GetFullPath(Path.GetDirectoryName(packageFullPath)), true); - } - _clientSdkHelper.DownloadPackageAndVerify(packageId); + //Delete package from local disk so once it gets uploaded + if (File.Exists(packageFullPath)) + { + File.Delete(packageFullPath); + Directory.Delete(Path.GetFullPath(Path.GetDirectoryName(packageFullPath)), true); } + _clientSdkHelper.DownloadPackageAndVerify(packageId); } } } diff --git a/tests/NuGetGallery.FunctionalTests/ODataFeeds/CuratedFeedTest.cs b/tests/NuGetGallery.FunctionalTests/ODataFeeds/CuratedFeedTest.cs index 0bb7172d57..57b7b5da1c 100644 --- a/tests/NuGetGallery.FunctionalTests/ODataFeeds/CuratedFeedTest.cs +++ b/tests/NuGetGallery.FunctionalTests/ODataFeeds/CuratedFeedTest.cs @@ -48,51 +48,40 @@ public async Task SearchMicrosoftDotNetCuratedFeed() Assert.True(responseText.ToLowerInvariant().Contains(packageUrl.ToLowerInvariant())); } - // This test fails due to the following error - // The package upload via Nuget.exe didnt succeed properly. Could not establish trust relationship for the SSL/TLS secure channel [Fact] [Description("Performs a querystring-based search of the Windows 8 curated feed. Confirms expected packages are returned.")] [Priority(0)] [Category("P0Tests")] public async Task SearchWindows8CuratedFeed() { - // Temporary workaround for the SSL issue, which keeps the upload test from working with cloudapp.net sites - if (UrlHelper.BaseUrl.Contains("nugettest.org") || UrlHelper.BaseUrl.Contains("nuget.org")) - { - string packageName = "NuGetGallery.FunctionalTests.SearchWindows8CuratedFeed"; - string ticks = DateTime.Now.Ticks.ToString(); - string version = new Version(ticks.Substring(0, 6) + "." + ticks.Substring(6, 6) + "." + ticks.Substring(12, 6)).ToString(); + string packageName = "NuGetGallery.FunctionalTests.SearchWindows8CuratedFeed"; + string ticks = DateTime.Now.Ticks.ToString(); + string version = new Version(ticks.Substring(0, 6) + "." + ticks.Substring(6, 6) + "." + ticks.Substring(12, 6)).ToString(); - int exitCode = await UploadPackageToCuratedFeed(packageName, version, FeedType.Windows8CuratedFeed); - Assert.True((exitCode == 0), Constants.UploadFailureMessage); + int exitCode = await UploadPackageToCuratedFeed(packageName, version, FeedType.Windows8CuratedFeed); + Assert.True((exitCode == 0), Constants.UploadFailureMessage); - bool applied = CheckPackageExistInCuratedFeed(packageName, FeedType.Windows8CuratedFeed); - var userMessage = string.Format(Constants.PackageNotFoundAfterUpload, packageName, UrlHelper.Windows8CuratedFeedUrl); - Assert.True(applied, userMessage); - } + bool applied = CheckPackageExistInCuratedFeed(packageName, FeedType.Windows8CuratedFeed); + var userMessage = string.Format(Constants.PackageNotFoundAfterUpload, packageName, UrlHelper.Windows8CuratedFeedUrl); + Assert.True(applied, userMessage); } - // This test fails due to the following error - // The package upload via Nuget.exe didnt succeed properly. Could not establish trust relationship for the SSL/TLS secure channel [Fact] [Description("Performs a querystring-based search of the WebMatrix curated feed. Confirms expected packages are returned.")] [Priority(0)] [Category("P0Tests")] public async Task SearchWebMatrixCuratedFeed() { - if (UrlHelper.BaseUrl.Contains("nugettest.org") || UrlHelper.BaseUrl.Contains("nuget.org")) - { - string packageName = "NuGetGallery.FunctionalTests.SearchWebMatrixCuratedFeed"; - string ticks = DateTime.Now.Ticks.ToString(); - string version = new Version(ticks.Substring(0, 6) + "." + ticks.Substring(6, 6) + "." + ticks.Substring(12, 6)).ToString(); + string packageName = "NuGetGallery.FunctionalTests.SearchWebMatrixCuratedFeed"; + string ticks = DateTime.Now.Ticks.ToString(); + string version = new Version(ticks.Substring(0, 6) + "." + ticks.Substring(6, 6) + "." + ticks.Substring(12, 6)).ToString(); - int exitCode = await UploadPackageToCuratedFeed(packageName, version, FeedType.WebMatrixCuratedFeed); - Assert.True((exitCode == 0), Constants.UploadFailureMessage); + int exitCode = await UploadPackageToCuratedFeed(packageName, version, FeedType.WebMatrixCuratedFeed); + Assert.True((exitCode == 0), Constants.UploadFailureMessage); - bool applied = CheckPackageExistInCuratedFeed(packageName, FeedType.WebMatrixCuratedFeed); - var userMessage = string.Format(Constants.PackageNotFoundAfterUpload, packageName, UrlHelper.WebMatrixCuratedFeedUrl); - Assert.True(applied, userMessage); - } + bool applied = CheckPackageExistInCuratedFeed(packageName, FeedType.WebMatrixCuratedFeed); + var userMessage = string.Format(Constants.PackageNotFoundAfterUpload, packageName, UrlHelper.WebMatrixCuratedFeedUrl); + Assert.True(applied, userMessage); } [Fact] diff --git a/tests/NuGetGallery.FunctionalTests/ODataFeeds/SearchTest.cs b/tests/NuGetGallery.FunctionalTests/ODataFeeds/SearchTest.cs index 894d2eb947..72797f487f 100644 --- a/tests/NuGetGallery.FunctionalTests/ODataFeeds/SearchTest.cs +++ b/tests/NuGetGallery.FunctionalTests/ODataFeeds/SearchTest.cs @@ -24,7 +24,7 @@ public SearchTest(ITestOutputHelper testOutputHelper) [Category("P0Tests")] public async Task SearchV1Feed() { - await SearchFeedAsync(UrlHelper.V1FeedRootUrl, "ASP.NET Web Helpers Library"); + await SearchFeedAsync(UrlHelper.V1FeedRootUrl, "Json.NET"); } [Fact] @@ -33,12 +33,12 @@ public async Task SearchV1Feed() [Category("P0Tests")] public async Task SearchV2Feed() { - await SearchFeedAsync(UrlHelper.V2FeedRootUrl, "ASP.NET Web Helpers Library"); + await SearchFeedAsync(UrlHelper.V2FeedRootUrl, "Json.NET"); } private async Task SearchFeedAsync(string feedRootUrl, string title) { - var requestUrl = feedRootUrl + @"Search()?$filter=IsLatestVersion&$skip=0&$top=25&searchTerm='web%20helpers'&targetFramework='net40'&includePrerelease=false"; + var requestUrl = feedRootUrl + @"Search()?$filter=IsLatestVersion&$skip=0&$top=25&searchTerm='newtonsoft%20json'&targetFramework='net40'&includePrerelease=false"; TestOutputHelper.WriteLine("Request: GET " + requestUrl); var request = WebRequest.Create(requestUrl); @@ -52,7 +52,7 @@ private async Task SearchFeedAsync(string feedRootUrl, string title) responseText = await sr.ReadToEndAsync(); } - var expectedUrl = feedRootUrl + "package/Microsoft.AspNet.WebHelpers/"; + var expectedUrl = feedRootUrl + "package/Newtonsoft.Json/"; Assert.True(responseText.Contains(@"" + title + @"") || responseText.Contains(@"" + title + @""), "The expected package title '" + title + "' wasn't found in the feed. Feed contents: " + responseText); diff --git a/tests/NuGetGallery.FunctionalTests/ODataFeeds/V2FeedExtendedTests.cs b/tests/NuGetGallery.FunctionalTests/ODataFeeds/V2FeedExtendedTests.cs index e8a717a361..ab8a47d7f1 100644 --- a/tests/NuGetGallery.FunctionalTests/ODataFeeds/V2FeedExtendedTests.cs +++ b/tests/NuGetGallery.FunctionalTests/ODataFeeds/V2FeedExtendedTests.cs @@ -30,39 +30,29 @@ public V2FeedExtendedTests(ITestOutputHelper testOutputHelper) _packageCreationHelper = new PackageCreationHelper(TestOutputHelper); } - private bool CanUploadToSite() - { - // Temporary workaround for the SSL issue, which keeps the upload test from working with cloudapp.net sites - return UrlHelper.BaseUrl.Contains("nugettest.org") || UrlHelper.BaseUrl.Contains("nuget.org") || - UrlHelper.BaseUrl.Contains("nuget.localtest.me"); - } - [Fact] [Description("Upload two packages and then issue the FindPackagesById request, expect to return both versions")] [Priority(1)] [Category("P0Tests")] public async Task FindPackagesByIdTest() { - if (CanUploadToSite()) - { - string packageId = string.Format("TestV2FeedFindPackagesById.{0}", DateTime.UtcNow.Ticks); + string packageId = string.Format("TestV2FeedFindPackagesById.{0}", DateTime.UtcNow.Ticks); - TestOutputHelper.WriteLine("Uploading package '{0}'", packageId); - await _clientSdkHelper.UploadNewPackage(packageId); + TestOutputHelper.WriteLine("Uploading package '{0}'", packageId); + await _clientSdkHelper.UploadNewPackage(packageId); - TestOutputHelper.WriteLine("Uploaded package '{0}'", packageId); - await _clientSdkHelper.UploadNewPackage(packageId, "2.0.0"); + TestOutputHelper.WriteLine("Uploaded package '{0}'", packageId); + await _clientSdkHelper.UploadNewPackage(packageId, "2.0.0"); - // "&$orderby=Version" is appended to bypass the search hijacker - string url = UrlHelper.V2FeedRootUrl + @"/FindPackagesById()?id='" + packageId + "'&$orderby=Version"; - string[] expectedTexts = - { + // "&$orderby=Version" is appended to bypass the search hijacker + string url = UrlHelper.V2FeedRootUrl + @"/FindPackagesById()?id='" + packageId + "'&$orderby=Version"; + string[] expectedTexts = + { @"" + UrlHelper.V2FeedRootUrl + "Packages(Id='" + packageId + "',Version='1.0.0')", @"" + UrlHelper.V2FeedRootUrl + "Packages(Id='" + packageId + "',Version='2.0.0')" }; - var containsResponseText = await _odataHelper.ContainsResponseText(url, expectedTexts); - Assert.True(containsResponseText); - } + var containsResponseText = await _odataHelper.ContainsResponseText(url, expectedTexts); + Assert.True(containsResponseText); } private const int PackagesInOrderNumPackages = 10; @@ -76,32 +66,28 @@ public async Task PackagesAppearInFeedInOrderTest() // This test uploads/unlists packages in a particular order to test the timestamps of the packages in the feed. // Because it waits for previous requests to finish before starting new ones, it will only catch ordering issues if these issues are greater than a second or two. // This is consistent with the time frame in which we've seen these issues in the past, but if new issues arise that are on a smaller scale, this test will not catch it! + var packageIds = new List(PackagesInOrderNumPackages); + var startingTime = DateTime.UtcNow; - if (CanUploadToSite()) + // Upload the packages in order. + var uploadStartTimestamp = DateTime.UtcNow.AddMinutes(-1); + for (var i = 0; i < PackagesInOrderNumPackages; i++) { - var packageIds = new List(PackagesInOrderNumPackages); - var startingTime = DateTime.UtcNow; - - // Upload the packages in order. - var uploadStartTimestamp = DateTime.UtcNow.AddMinutes(-1); - for (var i = 0; i < PackagesInOrderNumPackages; i++) - { - var packageId = GetPackagesAppearInFeedInOrderPackageId(startingTime, i); - await _clientSdkHelper.UploadNewPackage(packageId); - packageIds.Add(packageId); - } - - await CheckPackageTimestampsInOrder(packageIds, "Created", uploadStartTimestamp); + var packageId = GetPackagesAppearInFeedInOrderPackageId(startingTime, i); + await _clientSdkHelper.UploadNewPackage(packageId); + packageIds.Add(packageId); + } - // Unlist the packages in order. - var unlistStartTimestamp = DateTime.UtcNow.AddMinutes(-1); - for (var i = 0; i < PackagesInOrderNumPackages; i++) - { - await _clientSdkHelper.UnlistPackage(packageIds[i]); - } - - await CheckPackageTimestampsInOrder(packageIds, "LastEdited", unlistStartTimestamp); + await CheckPackageTimestampsInOrder(packageIds, "Created", uploadStartTimestamp); + + // Unlist the packages in order. + var unlistStartTimestamp = DateTime.UtcNow.AddMinutes(-1); + for (var i = 0; i < PackagesInOrderNumPackages; i++) + { + await _clientSdkHelper.UnlistPackage(packageIds[i]); } + + await CheckPackageTimestampsInOrder(packageIds, "LastEdited", unlistStartTimestamp); } private static string GetPackagesAppearInFeedInOrderPackageId(DateTime startingTime, int i) diff --git a/tests/NuGetGallery.WebUITests.P0/UploadAndDownload/UploadPackageFromUI.cs b/tests/NuGetGallery.WebUITests.P0/UploadAndDownload/UploadPackageFromUI.cs index 8bd16ee880..ee3254ffa3 100644 --- a/tests/NuGetGallery.WebUITests.P0/UploadAndDownload/UploadPackageFromUI.cs +++ b/tests/NuGetGallery.WebUITests.P0/UploadAndDownload/UploadPackageFromUI.cs @@ -21,10 +21,6 @@ public UploadPackageFromUI() public override IEnumerator GetRequestEnumerator() { - // Temporary workaround for the SSL issue, which keeps the upload test from working with cloudapp.net sites - if (!UrlHelper.BaseUrl.Contains("nugettest.org") && !UrlHelper.BaseUrl.Contains("nuget.org")) - yield break; - var defaultExtractionRule = AssertAndValidationHelper.GetDefaultExtractHiddenFields(); // Do initial login diff --git a/tests/Scripts/DownloadLatestNuGetExeRelease.ps1 b/tests/Scripts/DownloadLatestNuGetExeRelease.ps1 index 7819471b63..2f79516249 100644 --- a/tests/Scripts/DownloadLatestNuGetExeRelease.ps1 +++ b/tests/Scripts/DownloadLatestNuGetExeRelease.ps1 @@ -1,4 +1,11 @@ -$sourceNugetExe = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" -$targetNugetExe = ".\nuget.exe" +$sourceNugetExeUrl = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" +$sourceNuGetExePath = Join-Path $PSScriptRoot "nuget.exe" +$targetNugetExePath = ".\nuget.exe" -Invoke-WebRequest $sourceNugetExe -OutFile $targetNugetExe \ No newline at end of file +if (-Not (Test-Path $targetNugetExePath)) { + if (Test-Path $sourceNuGetExePath) { + Copy-Item $sourceNuGetExePath $targetNugetExePath + } else { + Invoke-WebRequest $sourceNugetExeUrl -OutFile $targetNugetExePath + } +} diff --git a/tests/Scripts/NuGet.exe b/tests/Scripts/NuGet.exe new file mode 100644 index 0000000000..f92b74fbb7 Binary files /dev/null and b/tests/Scripts/NuGet.exe differ