public async Task FindPackagesByIdTest() { string packageId = string.Format("TestV2FeedFindPackagesById.{0}", DateTime.UtcNow.Ticks); TestOutputHelper.WriteLine("Uploading package '{0}'", packageId); await _clientSdkHelper.UploadNewPackage(packageId, "1.0.0"); TestOutputHelper.WriteLine("Uploaded package '{0}'", packageId); await _clientSdkHelper.UploadNewPackage(packageId, "2.0.0"); // Wait for the packages to be available in V2 (due to async validation) await _clientSdkHelper.VerifyPackageExistsInV2Async(packageId, "1.0.0"); await _clientSdkHelper.VerifyPackageExistsInV2Async(packageId, "2.0.0"); string url = UrlHelper.V2FeedRootUrl + @"/FindPackagesById()?id='" + packageId + "'&$orderby=Version"; string[] expectedTexts = { @"<id>" + UrlHelper.V2FeedRootUrl + "Packages(Id='" + packageId + "',Version='1.0.0')</id>", @"<id>" + UrlHelper.V2FeedRootUrl + "Packages(Id='" + packageId + "',Version='2.0.0')</id>" }; var containsResponseText = await _odataHelper.ContainsResponseText(url, expectedTexts); Assert.True(containsResponseText); }
public async Task LockedPackageCannotBeModified() { // Arrange string version = "2.0.0"; var packageCreationHelper = new PackageCreationHelper(TestOutputHelper); var location = await packageCreationHelper.CreatePackage(LockedPackageId, version); // Act & Assert // 1. Try to upload package TestOutputHelper.WriteLine($"1. Trying to upload package '{LockedPackageId}', version '{version}' to locked package id."); var processResult = await _commandlineHelper.UploadPackageAsync(location, UrlHelper.V2FeedPushSourceUrl); Assert.True(processResult.ExitCode != 0, "Package push succeeded, although was expected to fail."); Assert.Contains("locked", processResult.StandardError); // 2. Try unlisting the locked package // Perform a sanity check that the package exists await _clientSdkHelper.VerifyPackageExistsInV2Async(LockedPackageId, LockedPackageVersion); TestOutputHelper.WriteLine($"5. Trying to unlist locked package '{LockedPackageId}', version '{LockedPackageVersion}'."); processResult = await _commandlineHelper.DeletePackageAsync(LockedPackageId, LockedPackageVersion, UrlHelper.V2FeedPushSourceUrl); Assert.True(processResult.ExitCode != 0, "Package delete succeeded, although was expected to fail."); Assert.Contains("locked", processResult.StandardError); }
public async Task ScopedApiKeysCanOnlyPushAndUnlistWithCorrectScopes() { // Arrange var packageCreationHelper = new PackageCreationHelper(TestOutputHelper); var commandlineHelper = new CommandlineHelper(TestOutputHelper); var packageId = UploadHelper.GetUniquePackageId(nameof(ScopedApiKeysCanOnlyPushAndUnlistWithCorrectScopes)); var version1 = "1.0.0"; var version2 = "2.0.0"; // 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."); await _clientSdkHelper.UploadNewPackage(packageId, version1, apiKey : EnvironmentSettings.TestAccountApiKey_Unlist, success : false); // 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."); await _clientSdkHelper.UploadNewPackage(packageId, version1, apiKey : EnvironmentSettings.TestAccountApiKey_PushVersion, success : false); // 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.UploadNewPackage(packageId, version1, apiKey : 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.UploadNewPackage(packageId, version2, apiKey : 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 failure TestOutputHelper.WriteLine($"5. Trying to unlist package '{packageId}', version '{version1}' using 'push' API key. Expected result: failure."); await _clientSdkHelper.UnlistPackage(packageId, version1, EnvironmentSettings.TestAccountApiKey_Push, success : false); // 6. Try unlisting package version2 using 'push version' api key => expect failure TestOutputHelper.WriteLine($"6. Trying to unlist package '{packageId}', version '{version2}' using 'push' API key. Expected result: failure."); await _clientSdkHelper.UnlistPackage(packageId, version2, EnvironmentSettings.TestAccountApiKey_PushVersion, success : false); // 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); }
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); }
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); } }