public void ClientCertAddCommand_Fail_FileCertificateNotExist() { // Arrange using (var testInfo = new TestInfo()) { var args = new[] { "add", "client-cert", "--configfile", testInfo.ConfigFile, "--package-source", testInfo.PackageSourceName, "--path", @".\MyCertificate.pfx" }; var log = new TestCommandOutputLogger(); // Act var exitCode = Program.MainInternal(args.ToArray(), log); // Assert var expectedError = "A fileCert path specified a file that does not exist"; Assert.Contains(expectedError, log.ShowErrors()); Assert.Equal(1, exitCode); } }
public void Restore_WithMissingConfigFile_Fails() { using (var projectDir = TestFileSystemUtility.CreateRandomTestFolder()) using (var configDir = TestFileSystemUtility.CreateRandomTestFolder()) { var specPath = Path.Combine(projectDir, "XPlatRestoreTests", "project.json"); var spec = XPlatTestUtils.BasicConfigNetCoreApp; XPlatTestUtils.AddDependency(spec, "costura.fody", "1.3.3"); XPlatTestUtils.AddDependency(spec, "fody", "1.29.4"); XPlatTestUtils.WriteJson(spec, specPath); var log = new TestCommandOutputLogger(); var args = new string[] { "restore", projectDir, "--configfile", Path.Combine(configDir, "DoesNotExist.config"), }; // Act var exitCode = Program.MainInternal(args, log); // Assert Assert.Equal(1, exitCode); Assert.Equal(1, log.Errors); Assert.Contains("DoesNotExist.config", log.ShowErrors()); // file does not exist } }
public void ClientCertUpdateCommand_Fail_CertificateSourceNotSpecified() { // Arrange using (var testInfo = new TestInfo()) { var args = new[] { "update", "client-cert", "--configfile", testInfo.ConfigFile, "--package-source", testInfo.PackageSourceName }; var log = new TestCommandOutputLogger(); // Act var exitCode = Program.MainInternal(args.ToArray(), log); // Assert var expectedError = "Invalid combination of arguments"; Assert.Contains(expectedError, log.ShowErrors()); Assert.Equal(1, exitCode); } }
public void ClientCertRemoveCommand_Success_ItemCertificate() { // Arrange using (var testInfo = new TestInfo()) { testInfo.SetupInitialItems(new FileClientCertItem(testInfo.PackageSourceName, testInfo.CertificateAbsoluteFilePath, testInfo.CertificatePassword, false, testInfo.ConfigFile)); var args = new[] { "remove", "client-cert", "--configfile", testInfo.ConfigFile, "--package-source", testInfo.PackageSourceName }; var log = new TestCommandOutputLogger(); // Act var exitCode = Program.MainInternal(args.ToArray(), log); // Assert Assert.Equal(string.Empty, log.ShowErrors()); Assert.Equal(0, exitCode); Assert.Contains("was successfully removed", log.ShowMessages()); testInfo.ValidateSettings(); } }
public void ClientCertAddCommand_Fail_CertificateSourceCombinationSpecified() { // Arrange using (var testInfo = new TestInfo()) { var args = new[] { "add", "client-cert", "--configfile", testInfo.ConfigFile, "--package-source", testInfo.PackageSourceName, "--path", testInfo.CertificateRelativeFilePath, "--store-location", testInfo.CertificateStoreLocation.ToString() }; var log = new TestCommandOutputLogger(); // Act var exitCode = Program.MainInternal(args.ToArray(), log); // Assert Assert.Contains("Invalid combination of arguments", log.ShowErrors()); Assert.Equal(1, exitCode); } }
public void ClientCertUpdatedCommand_Fail_NotConfigured() { var updatedPath = "MyCertificateSecond.pfx"; var updatedPassword = "******"; // Arrange using (var testInfo = new TestInfo()) { var args = new[] { "update", "client-cert", "--configfile", testInfo.ConfigFile, "--package-source", testInfo.PackageSourceName, "--path", updatedPath, "--password", updatedPassword }; var log = new TestCommandOutputLogger(); // Act var exitCode = Program.MainInternal(args.ToArray(), log); // Assert var expectedError = "does not exist"; Assert.Contains(expectedError, log.ShowErrors()); Assert.Equal(1, exitCode); } }
public void ClientCertAddCommand_Fail_StoreCertificateNotExist() { // Arrange using (var testInfo = new TestInfo()) { var args = new[] { "add", "client-cert", "--configfile", testInfo.ConfigFile, "--package-source", testInfo.PackageSourceName, "--find-value", "SOME" }; var log = new TestCommandOutputLogger(); // Act var exitCode = Program.MainInternal(args.ToArray(), log); // Assert var expectedError = "was not found"; Assert.Contains(expectedError, log.ShowErrors()); Assert.Equal(1, exitCode); } }
public void ClientCertRemoveCommand_Failed_NotExist() { // Arrange using (var testInfo = new TestInfo()) { var args = new[] { "remove", "client-cert", "--configfile", testInfo.ConfigFile, "--package-source", testInfo.PackageSourceName }; var log = new TestCommandOutputLogger(); // Act var exitCode = Program.MainInternal(args.ToArray(), log); // Assert Assert.Equal(string.Empty, log.ShowErrors()); Assert.Equal(0, exitCode); Assert.Contains("There are no client certificates configured for", log.ShowMessages()); testInfo.ValidateSettings(); } }
public void ClientCertUpdateCommand_Success_StoreCertificateForce() { var updatedStoreLocation = StoreLocation.CurrentUser; var updatedStoreName = StoreName.AuthRoot; var updatedFindBy = X509FindType.FindByCertificatePolicy; var updatedFindValue = "SOMEUpdated"; // Arrange using (var testInfo = new TestInfo()) { testInfo.SetupInitialItems(new StoreClientCertItem(testInfo.PackageSourceName, testInfo.CertificateFindValue.ToString(), testInfo.CertificateStoreLocation, testInfo.CertificateStoreName, testInfo.CertificateFindBy)); var args = new[] { "update", "client-cert", "--configfile", testInfo.ConfigFile, "--package-source", testInfo.PackageSourceName, "--store-location", updatedStoreLocation.ToString(), "--store-name", updatedStoreName.ToString(), "--find-by", updatedFindBy.ToString().Replace("FindBy", string.Empty), "--find-value", updatedFindValue, "--force" }; var log = new TestCommandOutputLogger(); // Act var exitCode = Program.MainInternal(args.ToArray(), log); // Assert Assert.Equal(string.Empty, log.ShowErrors()); Assert.Equal(0, exitCode); Assert.Contains("was successfully updated", log.ShowMessages()); testInfo.ValidateSettings(new StoreClientCertItem(testInfo.PackageSourceName, updatedFindValue, updatedStoreLocation, updatedStoreName, updatedFindBy)); } }
public void ClientCertAddCommand_Fail_NoSourceSpecified() { // Arrange var args = new[] { "add", "client-cert" }; var log = new TestCommandOutputLogger(); // Act var exitCode = Program.MainInternal(args.ToArray(), log); // Assert var expectedError = "Property 'PackageSource' should not be null or empty"; Assert.Contains(expectedError, log.ShowErrors()); Assert.Equal(1, exitCode); }
public async Task PushToServerWhichRejectsDuplicates_SkipDuplicate_Succeeds(PackageSource packageSource) { // Arrange using (var packageDir = TestDirectory.Create()) using (TestFileSystemUtility.SetCurrentDirectory(packageDir)) { var packageId = "XPlatPushTests.PushToServerSucceeds"; var packageVersion = "1.0.0"; var packageFile = await TestPackagesCore.GetRuntimePackageAsync(packageDir, packageId, packageVersion); var configFile = XPlatTestUtils.CopyFuncTestConfig(packageDir); var logFirstPush = new TestCommandOutputLogger(); var logSecondPush = new TestCommandOutputLogger(); var apiKey = XPlatTestUtils.ReadApiKey(packageSource.Name); Assert.False(string.IsNullOrEmpty(apiKey)); var pushArgs = new List <string> { "push", packageFile.FullName, "--source", packageSource.Source, "--api-key", apiKey, "--skip-duplicate" }; // Act var exitCodeFirstPush = NuGet.CommandLine.XPlat.Program.MainInternal(pushArgs.ToArray(), logFirstPush); var exitCodeSecondPush = NuGet.CommandLine.XPlat.Program.MainInternal(pushArgs.ToArray(), logSecondPush); // Assert First Push - it should happen without error. var outputMessagesFirstPush = logFirstPush.ShowMessages(); Assert.Equal(string.Empty, logFirstPush.ShowErrors()); Assert.Equal(0, exitCodeFirstPush); // Assert Second Push - it should happen without error, even though a duplicate is present. var outputMessagesSecondPush = logSecondPush.ShowMessages(); Assert.Equal(string.Empty, logSecondPush.ShowErrors()); Assert.Equal(0, exitCodeSecondPush); Assert.Contains($"PUT {packageSource.Source}", outputMessagesSecondPush); Assert.DoesNotContain("already exists at feed", outputMessagesSecondPush); Assert.Contains("Your package was pushed.", outputMessagesSecondPush); } }
public void ClientCertUpdatedCommand_Fail_StoreCertificateNotExist() { var updatedStoreLocation = StoreLocation.CurrentUser; var updatedStoreName = StoreName.My; var updatedFindBy = X509FindType.FindByIssuerName; var updatedFindValue = "SOMEUpdated"; // Arrange using (var testInfo = new TestInfo()) { testInfo.SetupInitialItems(new StoreClientCertItem(testInfo.PackageSourceName, testInfo.CertificateFindValue.ToString(), testInfo.CertificateStoreLocation, testInfo.CertificateStoreName, testInfo.CertificateFindBy)); var args = new[] { "update", "client-cert", "--configfile", testInfo.ConfigFile, "--package-source", testInfo.PackageSourceName, "--store-location", updatedStoreLocation.ToString(), "--store-name", updatedStoreName.ToString(), "--find-by", updatedFindBy.ToString().Replace("FindBy", string.Empty), "--find-value", updatedFindValue }; var log = new TestCommandOutputLogger(); // Act var exitCode = Program.MainInternal(args.ToArray(), log); // Assert var expectedError = "was not found"; Assert.Contains(expectedError, log.ShowErrors()); Assert.Equal(1, exitCode); } }
public async Task PushToServerSkipDuplicateSucceeds(PackageSource packageSource) { // Arrange using (var packageDir = TestDirectory.Create()) using (TestFileSystemUtility.SetCurrentDirectory(packageDir)) { var packageId = "XPlatPushTests.PushToServerSucceeds"; var packageVersion = "1.0.0"; var packageFile = await TestPackagesCore.GetRuntimePackageAsync(packageDir, packageId, packageVersion); var configFile = XPlatTestUtils.CopyFuncTestConfig(packageDir); var log = new TestCommandOutputLogger(); var apiKey = XPlatTestUtils.ReadApiKey(packageSource.Name); Assert.False(string.IsNullOrEmpty(apiKey)); var pushArgs = new List <string> { "push", packageFile.FullName, "--source", packageSource.Source, "--api-key", apiKey, "--skip-duplicate" }; // Act var exitCode = NuGet.CommandLine.XPlat.Program.MainInternal(pushArgs.ToArray(), log); // Assert var outputMessages = log.ShowMessages(); Assert.Equal(string.Empty, log.ShowErrors()); Assert.Equal(0, exitCode); Assert.Contains($"PUT {packageSource.Source}", outputMessages); //info: PUT http://localhost:5000/api/v2/package/ //info: Conflict http://localhost:5000/api/v2/package/ 127ms Assert.Contains("already exists at feed", outputMessages); Assert.Contains("Your package was pushed.", outputMessages); } }
public void ClientCertAddCommand_Success_StoreCertificate() { // Arrange using (var testInfo = new TestInfo()) { testInfo.SetupCertificateInStorage(); var args = new[] { "add", "client-cert", "--configfile", testInfo.ConfigFile, "--package-source", testInfo.PackageSourceName, "--store-location", testInfo.CertificateStoreLocation.ToString(), "--store-name", testInfo.CertificateStoreName.ToString(), "--find-by", testInfo.CertificateFindBy.ToString().Replace("FindBy", string.Empty), "--find-value", testInfo.CertificateFindValue.ToString() }; var log = new TestCommandOutputLogger(); // Act var exitCode = Program.MainInternal(args.ToArray(), log); // Assert Assert.Equal(string.Empty, log.ShowErrors()); Assert.Equal(0, exitCode); Assert.Contains("was successfully added", log.ShowMessages()); testInfo.ValidateSettings(new StoreClientCertItem(testInfo.PackageSourceName, testInfo.CertificateFindValue.ToString(), testInfo.CertificateStoreLocation, testInfo.CertificateStoreName, testInfo.CertificateFindBy)); } }
// [InlineData(TestServers.Klondike, nameof(TestServers.Klondike), false)] // 500 Internal Server Error pushing // [InlineData(TestServers.NuGetServer, nameof(TestServers.NuGetServer), false)] // 500 - missing manifest? public async Task PushToServerSucceeds(string sourceUri, string feedName, bool mustDeleteFirst) { // Arrange using (var packageDir = TestDirectory.Create()) using (TestFileSystemUtility.SetCurrentDirectory(packageDir)) { var packageId = "XPlatPushTests.PushToServerSucceeds"; var packageVersion = "1.0.0"; var packageFile = await TestPackagesCore.GetRuntimePackageAsync(packageDir, packageId, packageVersion); var configFile = XPlatTestUtils.CopyFuncTestConfig(packageDir); var log = new TestCommandOutputLogger(); var apiKey = XPlatTestUtils.ReadApiKey(feedName); Assert.False(string.IsNullOrEmpty(apiKey)); if (mustDeleteFirst) { DeletePackageBeforePush(packageId, packageVersion, sourceUri, apiKey); } var pushArgs = new List <string>() { "push", packageFile.FullName, "--source", sourceUri, "--api-key", apiKey }; // Act int exitCode = NuGet.CommandLine.XPlat.Program.MainInternal(pushArgs.ToArray(), log); // Assert Assert.Equal(string.Empty, log.ShowErrors()); Assert.Equal(0, exitCode); Assert.Contains($"PUT {sourceUri}", log.ShowMessages()); Assert.Contains("Your package was pushed.", log.ShowMessages()); } }
public void Restore_WithConfigFileInDifferentDirectory_Succeeds(string sourceUri) { using (var packagesDir = TestDirectory.Create()) using (var projectDir = TestDirectory.Create()) using (var configDir = TestDirectory.Create()) { var configFile = XPlatTestUtils.CopyFuncTestConfig(configDir); var specPath = Path.Combine(projectDir, "XPlatRestoreTests", "project.json"); var spec = XPlatTestUtils.BasicConfigNetCoreApp; XPlatTestUtils.AddDependency(spec, "costura.fody", "1.3.3"); XPlatTestUtils.AddDependency(spec, "fody", "1.29.4"); XPlatTestUtils.WriteJson(spec, specPath); var log = new TestCommandOutputLogger(); var args = new List <string>() { "restore", projectDir, "--packages", packagesDir, "--source", sourceUri, "--no-cache", "--configfile", configFile }; // Act int exitCode = NuGet.CommandLine.XPlat.Program.MainInternal(args.ToArray(), log); Assert.Contains($@"OK {sourceUri}/FindPackagesById()?id='fody'", log.ShowMessages()); Assert.Equal(string.Empty, log.ShowErrors()); Assert.Equal(0, exitCode); var lockFilePath = Path.Combine(projectDir, "XPlatRestoreTests", "project.lock.json"); Assert.True(File.Exists(lockFilePath)); } }
public void ClientCertUpdatedCommand_Fail_FileCertificateNotExist() { var updatedPath = "MyCertificateSecond.pfx"; var updatedPassword = "******"; // Arrange using (var testInfo = new TestInfo()) { testInfo.SetupInitialItems(new FileClientCertItem(testInfo.PackageSourceName, testInfo.CertificateAbsoluteFilePath, testInfo.CertificatePassword, false, testInfo.ConfigFile)); var args = new[] { "update", "client-cert", "--configfile", testInfo.ConfigFile, "--package-source", testInfo.PackageSourceName, "--path", updatedPath, "--password", updatedPassword }; var log = new TestCommandOutputLogger(); // Act var exitCode = Program.MainInternal(args.ToArray(), log); // Assert var expectedError = "A fileCert path specified a file that does not exist"; Assert.Contains(expectedError, log.ShowErrors()); Assert.Equal(1, exitCode); } }
public void BasicLogging_VerifyExceptionLoggedWhenVerbose() { // Arrange var log = new TestCommandOutputLogger(observeLogLevel: true); var args = new string[] { "--verbosity", "verbose", "--unknown", }; // Act var exitCode = Program.MainInternal(args, log); // Assert Assert.Equal(1, exitCode); Assert.Equal(3, log.Messages.Count); Assert.Equal(1, log.Errors); Assert.Equal(0, log.Warnings); Assert.Contains("--unknown", log.ShowErrors()); // error Assert.Contains("NuGet.CommandLine.XPlat.Program.", log.ShowMessages()); // verbose stack trace }
public void BasicLogging_RestoreUnknownOption_ExitCode() { // Arrange var log = new TestCommandOutputLogger(); var args = new string[] { "restore", "--unknown", }; // Act var exitCode = Program.MainInternal(args, log); // Assert Assert.Equal(1, exitCode); Assert.Equal(3, log.Messages.Count); Assert.Equal(1, log.Errors); Assert.Equal(0, log.Warnings); Assert.Contains("--unknown", log.ShowErrors()); // error Assert.Contains("NuGet.CommandLine.XPlat.Program.", log.ShowMessages()); // verbose stack trace }
public void ClientCertAddCommand_Success_FileCertificateRelative() { // Arrange using (var testInfo = new TestInfo()) { testInfo.SetupCertificateFile(); var packageSource = testInfo.PackageSourceName; var path = testInfo.CertificateRelativeFilePath; var password = testInfo.CertificatePassword; var args = new[] { "add", "client-cert", "--configfile", testInfo.ConfigFile, "--package-source", packageSource, "--path", path, "--password", password }; var log = new TestCommandOutputLogger(); // Act var exitCode = Program.MainInternal(args.ToArray(), log); // Assert Assert.Equal(string.Empty, log.ShowErrors()); Assert.Equal(0, exitCode); Assert.Contains("was successfully added", log.ShowMessages()); testInfo.ValidateSettings(new FileClientCertItem(packageSource, path, password, false, testInfo.ConfigFile)); } }
public void ClientCertListCommand_Success_NotEmptyList() { // Arrange using (var testInfo = new TestInfo()) { testInfo.SetupInitialItems(new FileClientCertItem(testInfo.PackageSourceName, testInfo.CertificateRelativeFilePath, testInfo.CertificatePassword, false, testInfo.ConfigFile), new StoreClientCertItem(testInfo.InvalidPackageSourceName, testInfo.CertificateFindValue.ToString(), testInfo.CertificateStoreLocation, testInfo.CertificateStoreName, testInfo.CertificateFindBy)); var args = new[] { "list", "client-cert", "--configfile", testInfo.ConfigFile }; var log = new TestCommandOutputLogger(); // Act var exitCode = Program.MainInternal(args.ToArray(), log); // Assert Assert.Equal(string.Empty, log.ShowErrors()); Assert.Equal(0, exitCode); var showMessages = log.ShowMessages(); Assert.Contains($"{testInfo.PackageSourceName} [{ConfigurationConstants.FileCertificate}]", showMessages); Assert.Contains($"{testInfo.InvalidPackageSourceName} [{ConfigurationConstants.StoreCertificate}]", showMessages); } }
public async Task PushMultiplePathsToFileSystemSource() { using (var packageDirectory = TestDirectory.Create()) using (var source = TestDirectory.Create()) { // Arrange var log = new TestCommandOutputLogger(); var packageInfoCollection = new[] { await TestPackagesCore.GetRuntimePackageAsync(packageDirectory, "testPackageA", "1.1.0"), await TestPackagesCore.GetRuntimePackageAsync(packageDirectory, "testPackageB", "1.1.0"), }; var pushArgs = new List <string> { "push", packageInfoCollection[0].FullName, packageInfoCollection[1].FullName, "--source", source, }; // Act var exitCode = CommandLine.XPlat.Program.MainInternal(pushArgs.ToArray(), log); // Assert Assert.Equal(string.Empty, log.ShowErrors()); Assert.Equal(0, exitCode); foreach (var packageInfo in packageInfoCollection) { Assert.Contains($"Pushing {packageInfo.Name}", log.ShowMessages()); Assert.True(File.Exists(Path.Combine(source, packageInfo.Name))); } } }
public void ClientCertListCommand_Success_EmptyList() { // Arrange using (var testInfo = new TestInfo()) { var args = new[] { "list", "client-cert", "--configfile", testInfo.ConfigFile }; var log = new TestCommandOutputLogger(); // Act var exitCode = Program.MainInternal(args.ToArray(), log); // Assert Assert.Equal(string.Empty, log.ShowErrors()); Assert.Equal(0, exitCode); Assert.Contains("There are no client certificates", log.ShowMessages()); } }
public async Task Restore_FallbackFolderDoesNotExist() { using (var sourceDir = TestFileSystemUtility.CreateRandomTestFolder()) using (var fallbackDir1 = TestFileSystemUtility.CreateRandomTestFolder()) using (var fallbackDir2 = TestFileSystemUtility.CreateRandomTestFolder()) using (var packagesDir = TestFileSystemUtility.CreateRandomTestFolder()) using (var projectDir = TestFileSystemUtility.CreateRandomTestFolder()) { var specPath = Path.Combine(projectDir, "XPlatRestoreTests", "project.json"); var spec = XPlatTestUtils.BasicConfigNetCoreApp; XPlatTestUtils.AddDependency(spec, "a", "1.0.0"); XPlatTestUtils.AddDependency(spec, "b", "1.0.0"); XPlatTestUtils.WriteJson(spec, specPath); var packageA = new SimpleTestPackageContext("a", "1.0.0"); var packageB = new SimpleTestPackageContext("b", "1.0.0"); var saveMode = PackageSaveMode.Nuspec | PackageSaveMode.Files; await SimpleTestPackageUtility.CreateFolderFeedV3( fallbackDir2, saveMode, packageA, packageB); Directory.Delete(fallbackDir1); var log = new TestCommandOutputLogger(); var config = $@"<?xml version=""1.0"" encoding=""utf-8""?> <configuration> <config> <add key=""globalPackagesFolder"" value=""{packagesDir}"" /> </config> <fallbackPackageFolders> <add key=""a"" value=""{fallbackDir1}"" /> <add key=""b"" value=""{fallbackDir2}"" /> </fallbackPackageFolders> <packageSources> <add key=""a"" value=""{sourceDir}"" /> </packageSources> </configuration>"; File.WriteAllText(Path.Combine(projectDir, "NuGet.Config"), config); var args = new string[] { "restore", projectDir, }; // Act var exitCode = Program.MainInternal(args, log); // Assert Assert.Equal(1, exitCode); Assert.Equal(1, log.Errors); Assert.Contains(fallbackDir1, log.ShowErrors()); } }