コード例 #1
0
        public async Task GetUpdates1199RegressionTest()
        {
            // Use the same package name, but force the version to be unique.
            var packageName      = "NuGetGallery.FunctionalTests.ODataTests.GetUpdates1199RegressionTest";
            var ticks            = DateTime.Now.Ticks.ToString();
            var version1         = new Version(ticks.Substring(0, 6) + "." + ticks.Substring(6, 6) + "." + ticks.Substring(12, 6)).ToString();
            var version2         = new Version(Convert.ToInt32(ticks.Substring(0, 6) + 1) + "." + ticks.Substring(6, 6) + "." + ticks.Substring(12, 6)).ToString();
            var package1Location = await _packageCreationHelper.CreatePackageWithTargetFramework(packageName, version1, "net45");

            var processResult = await _commandlineHelper.UploadPackageAsync(package1Location, UrlHelper.V2FeedPushSourceUrl);

            Assert.True(processResult.ExitCode == 0, Constants.UploadFailureMessage + "Exit Code: " + processResult.ExitCode + ". Error message: \"" + processResult.StandardError + "\"");

            var package2Location = await _packageCreationHelper.CreatePackageWithTargetFramework(packageName, version2, "net40");

            processResult = await _commandlineHelper.UploadPackageAsync(package2Location, UrlHelper.V2FeedPushSourceUrl);

            Assert.True((processResult.ExitCode == 0), Constants.UploadFailureMessage + "Exit Code: " + processResult.ExitCode + ". Error message: \"" + processResult.StandardError + "\"");

            var url = UrlHelper.V2FeedRootUrl + @"/GetUpdates()?packageIds='NuGetGallery.FunctionalTests.ODataTests.GetUpdates1199RegressionTest%7COwin%7CMicrosoft.Web.Infrastructure%7CMicrosoft.AspNet.Identity.Core%7CMicrosoft.AspNet.Identity.EntityFramework%7CMicrosoft.AspNet.Identity.Owin%7CMicrosoft.AspNet.Web.Optimization%7CRespond%7CWebGrease%7CjQuery%7CjQuery.Validation%7CMicrosoft.Owin.Security.Twitter%7CMicrosoft.Owin.Security.OAuth%7CMicrosoft.Owin.Security.MicrosoftAccount%7CMicrosoft.Owin.Security.Google%7CMicrosoft.Owin.Security.Facebook%7CMicrosoft.Owin.Security.Cookies%7CMicrosoft.Owin%7CMicrosoft.Owin.Host.SystemWeb%7CMicrosoft.Owin.Security%7CModernizr%7CMicrosoft.jQuery.Unobtrusive.Validation%7CMicrosoft.AspNet.WebPages%7CMicrosoft.AspNet.Razor%7Cbootstrap%7CAntlr%7CMicrosoft.AspNet.Mvc%7CNewtonsoft.Json%7CEntityFramework'&versions='" + version1 + "%7C1.0%7C1.0.0.0%7C1.0.0%7C1.0.0%7C1.0.0%7C1.1.1%7C1.2.0%7C1.5.2%7C1.10.2%7C1.11.1%7C2.0.0%7C2.0.0%7C2.0.0%7C2.0.0%7C2.0.0%7C2.0.0%7C2.0.0%7C2.0.0%7C2.0.0%7C2.6.2%7C3.0.0%7C3.0.0%7C3.0.0%7C3.0.0%7C3.4.1.9004%7C5.0.0%7C5.0.6%7C6.0.0'&includePrerelease=false&includeAllVersions=false&targetFrameworks='net45'&versionConstraints='%7C%7C%7C%7C%7C%7C%7C%7C%7C%7C%7C%7C%7C%7C%7C%7C%7C%7C%7C%7C%7C%7C%7C%7C%7C%7C%7C%7C'";

            string[] expectedTexts =
            {
                @"<title type=""text"">NuGetGallery.FunctionalTests.ODataTests.GetUpdates1199RegressionTest</title>",
                @"<d:Version>" + version2 + "</d:Version><d:NormalizedVersion>" + version2 + "</d:NormalizedVersion>"
            };
            var containsResponseText = await _odataHelper.ContainsResponseText(url, expectedTexts);

            Assert.True(containsResponseText);
        }
コード例 #2
0
        public async Task GetUpdates1199RegressionTest()
        {
            // Use unique version to make the assertions simpler.
            var ticks            = DateTime.Now.Ticks.ToString();
            var packageId        = $"GetUpdates1199RegressionTest.{ticks}";
            var version1         = "1.0.0";
            var version2         = new Version(Convert.ToInt32(ticks.Substring(0, 6) + 1) + "." + ticks.Substring(6, 6) + "." + ticks.Substring(12, 6)).ToString();
            var package1Location = await _packageCreationHelper.CreatePackageWithTargetFramework(packageId, version1, "net45");

            var processResult = await _commandlineHelper.UploadPackageAsync(package1Location, UrlHelper.V2FeedPushSourceUrl);

            Assert.True(processResult.ExitCode == 0, Constants.UploadFailureMessage + "Exit Code: " + processResult.ExitCode + ". Error message: \"" + processResult.StandardError + "\"");

            var package2Location = await _packageCreationHelper.CreatePackageWithTargetFramework(packageId, version2, "net40");

            processResult = await _commandlineHelper.UploadPackageAsync(package2Location, UrlHelper.V2FeedPushSourceUrl);

            Assert.True((processResult.ExitCode == 0), Constants.UploadFailureMessage + "Exit Code: " + processResult.ExitCode + ". Error message: \"" + processResult.StandardError + "\"");

            // Wait for the packages to be available in V2 (due to async validation)
            await _clientSdkHelper.VerifyPackageExistsInV2Async(packageId, version1);

            await _clientSdkHelper.VerifyPackageExistsInV2Async(packageId, version2);

            var packagesList = new List <string>
            {
                packageId,
                "Microsoft.Bcl.Build",
                "Microsoft.Bcl",
                "Microsoft.Net.Http"
            };
            var versionsList = new List <string>
            {
                version1,
                "1.0.6",
                "1.0.19",
                "2.1.6-rc"
            };
            var url = UrlHelper.V2FeedRootUrl +
                      @"/GetUpdates()?packageIds='" +
                      string.Join("%7C", packagesList) +
                      @"'&versions='" +
                      string.Join("%7C", versionsList) +
                      @"'&includePrerelease=false&includeAllVersions=false&targetFrameworks='net45'&versionConstraints='" +
                      string.Join("%7C", Enumerable.Repeat(string.Empty, packagesList.Count)) +
                      @"'";

            string[] expectedTexts =
            {
                $@"<title type=""text"">{packageId}</title>",
                $@"<d:Version>{version2}</d:Version><d:NormalizedVersion>{version2}</d:NormalizedVersion>"
            };
            var containsResponseText = await _odataHelper.ContainsResponseText(url, expectedTexts);

            Assert.True(containsResponseText);
        }
        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");

                var processResult = await _commandlineHelper.UploadPackageAsync(packageFullPath, UrlHelper.V2FeedPushSourceUrl);

                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);

                //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);
            }
        }
コード例 #4
0
        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 uploadedPackageIds = new List <string>();
            var version            = "1.0.0";
            var startingTime       = DateTime.UtcNow;

            // Upload the packages in order.
            var uploadStartTimestamp = DateTime.UtcNow.AddMinutes(-1);

            for (var i = 0; i < PackagesInOrderNumPackages; i++)
            {
                var packageId       = UploadHelper.GetUniquePackageId();
                var packageFullPath = await _packageCreationHelper.CreatePackage(packageId, version);

                var commandOutput = await _commandlineHelper.UploadPackageAsync(packageFullPath, UrlHelper.V2FeedPushSourceUrl);

                Assert.True(
                    commandOutput.ExitCode == 0,
                    $"Push failed with exit code {commandOutput.ExitCode}{Environment.NewLine}{commandOutput.StandardError}");

                uploadedPackageIds.Add(packageId);
            }

            await Task.WhenAll(uploadedPackageIds.Select(id => _clientSdkHelper.VerifyPackageExistsInV2Async(id, version, listed: true)));

            await CheckPackageTimestampsInOrder(uploadedPackageIds, "Created", uploadStartTimestamp, version);

            // Unlist the packages in order.
            var unlistedPackageIds   = new List <string>();
            var unlistStartTimestamp = DateTime.UtcNow.AddMinutes(-1);

            foreach (var uploadedPackageId in uploadedPackageIds)
            {
                await _commandlineHelper.DeletePackageAsync(uploadedPackageId, version, UrlHelper.V2FeedPushSourceUrl);

                unlistedPackageIds.Add(uploadedPackageId);
            }

            await Task.WhenAll(unlistedPackageIds.Select(id => _clientSdkHelper.VerifyPackageExistsInV2Async(id, version, listed: false)));

            await CheckPackageTimestampsInOrder(unlistedPackageIds, "LastEdited", unlistStartTimestamp, version);
        }
コード例 #5
0
        public async Task UploadInValidPackageWithLicenseExpression()
        {
            // Arrange
            var packageName    = $"TestPackageWithLicense.{Guid.NewGuid():N}";
            var packageVersion = "1.0.0";

            var licenseUrl           = "https://testNugetLicenseUrl";
            var licenseExpression    = "MIT";
            var expectedErrorMessage = "when a license expression is specified, <licenseUrl> must be set to";

            // Act
            string packageFullPath = await _packageCreationHelper.CreatePackageWithLicenseExpression(packageName, packageVersion, licenseUrl, licenseExpression);

            var processResult = await _commandlineHelper.UploadPackageAsync(packageFullPath, UrlHelper.V2FeedPushSourceUrl);

            // Assert
            Assert.True(processResult.ExitCode == 1, Constants.UploadFailureMessage);
            Assert.Contains(expectedErrorMessage, processResult.StandardError);
        }
コード例 #6
0
        public async Task UploadAndDownloadPackageWithMinClientVersion()
        {
            string packageId       = $"{Guid.NewGuid():N}PackageWithDotCsNames.Cs";
            string version         = "1.0.0";
            string packageFullPath = await _packageCreationHelper.CreatePackageWithMinClientVersion(packageId, version, "2.3");

            var processResult = await _commandlineHelper.UploadPackageAsync(packageFullPath, UrlHelper.V2FeedPushSourceUrl);

            Assert.True(processResult.ExitCode == 0, Constants.UploadFailureMessage);

            await _clientSdkHelper.VerifyPackageExistsInV2AndV3Async(packageId, version);

            //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, version);
        }
コード例 #7
0
        public async Task UploadTyposquattingPackageAndBlockUser()
        {
            var    packageId       = "newtonsoft-json";
            string version         = "1.0.0";
            string packageFullPath = await _packageCreationHelper.CreatePackageWithMinClientVersion(packageId, version, "2.3");

            var processResult = await _commandlineHelper.UploadPackageAsync(packageFullPath, UrlHelper.V2FeedPushSourceUrl);

            Assert.True(processResult.ExitCode == 1, Constants.UploadFailureMessage);
            Assert.Contains("similar", processResult.StandardError);
        }
        private async Task <int> UploadPackageToCuratedFeed(string packageName, string version, FeedType feedType)
        {
            string packageFullPath = string.Empty;

            switch (feedType)
            {
            case FeedType.Windows8CuratedFeed:
                packageFullPath = await _packageCreationHelper.CreateWindows8CuratedPackage(packageName, version);

                break;

            case FeedType.WebMatrixCuratedFeed:
                packageFullPath = await _packageCreationHelper.CreateWindows8CuratedPackage(packageName, version);

                break;
            }
            var processResult = await _commandlineHelper.UploadPackageAsync(packageFullPath, UrlHelper.V2FeedPushSourceUrl);

            return(processResult.ExitCode);
        }
コード例 #9
0
        public async Task VerifyScopedApiKeys()
        {
            // Arrange
            var packageCreationHelper = new PackageCreationHelper(TestOutputHelper);
            var commandlineHelper     = new CommandlineHelper(TestOutputHelper);

            var packageId = "ScopedApiKeysTest_" + DateTime.Now.Ticks;
            var version1  = "1.0.0";
            var version2  = "2.0.0";

            string package1FullPath = null;
            string package2FullPath = null;

            try
            {
                package1FullPath = await packageCreationHelper.CreatePackage(packageId, version1);

                package2FullPath = await packageCreationHelper.CreatePackage(packageId, version2);

                // 1. Try to upload package using 'unlist' api key => expect failure
                TestOutputHelper.WriteLine($"1. Trying to upload package '{packageId}', version '{version1}' using 'unlist' API key. Expected result: failure.");
                var processResult = await commandlineHelper.UploadPackageAsync(package1FullPath, UrlHelper.V2FeedPushSourceUrl, EnvironmentSettings.TestAccountApiKey_Unlist);

                Assert.True(processResult.ExitCode != 0, "Package push succeeded, although was expected to fail.");

                // 2. Try to upload package using 'push version' api key => expect failure
                TestOutputHelper.WriteLine($"2. Trying to upload package '{packageId}', version '{version1}' using 'push version' API key. Expected result: failure.");
                processResult = await commandlineHelper.UploadPackageAsync(package1FullPath, UrlHelper.V2FeedPushSourceUrl, EnvironmentSettings.TestAccountApiKey_PushVersion);

                Assert.True(processResult.ExitCode != 0, "Package push succeeded, although was expected to fail.");

                // 3. Upload package using 'push' api key => expect success
                TestOutputHelper.WriteLine($"3. Trying to upload package '{packageId}', version '{version1}' using 'push' API key. Expected result: success.");
                await _clientSdkHelper.UploadExistingPackage(package1FullPath, EnvironmentSettings.TestAccountApiKey_Push);

                // 4. Upload new version of package using 'push version' api key => expect success
                TestOutputHelper.WriteLine($"4. Trying to upload package '{packageId}', version '{version2}' using 'push version' API key. Expected result: success.");
                await _clientSdkHelper.UploadExistingPackage(package2FullPath, EnvironmentSettings.TestAccountApiKey_PushVersion);

                // Verify the existence of the two pushed packages.
                await _clientSdkHelper.VerifyPackageExistsInV2Async(packageId, version1);

                await _clientSdkHelper.VerifyPackageExistsInV2Async(packageId, version2);

                // 5. Try unlisting package version1 using 'push' api key => expect failture
                TestOutputHelper.WriteLine($"5. Trying to unlist package '{packageId}', version '{version1}' using 'push' API key. Expected result: failure.");
                processResult = await commandlineHelper.DeletePackageAsync(packageId, version1, UrlHelper.V2FeedPushSourceUrl, EnvironmentSettings.TestAccountApiKey_Push);

                Assert.True(processResult.ExitCode != 0, "Package delete succeeded, although was expected to fail.");

                // 6. Try unlisting package version2 using 'push version' api key => expect failture
                TestOutputHelper.WriteLine($"6. Trying to unlist package '{packageId}', version '{version2}' using 'push' API key. Expected result: failure.");
                processResult = await commandlineHelper.DeletePackageAsync(packageId, version2, UrlHelper.V2FeedPushSourceUrl, EnvironmentSettings.TestAccountApiKey_PushVersion);

                Assert.True(processResult.ExitCode != 0, "Package delete succeeded, although was expected to fail.");

                // 7. Unlist both packages using 'unlist' api key => expect succees
                TestOutputHelper.WriteLine($"7. Trying to unlist package '{packageId}', version '{version1}' using 'unlist' API key. Expected result: success.");
                await _clientSdkHelper.UnlistPackage(packageId, version1, EnvironmentSettings.TestAccountApiKey_Unlist);

                TestOutputHelper.WriteLine($"8. Trying to unlist package '{packageId}', version '{version2}' using 'unlist' API key. Expected result: success.");
                await _clientSdkHelper.UnlistPackage(packageId, version2, EnvironmentSettings.TestAccountApiKey_Unlist);
            }
            finally
            {
                _clientSdkHelper.CleanCreatedPackage(package1FullPath);
                _clientSdkHelper.CleanCreatedPackage(package2FullPath);
            }
        }