public static void Run(AddClientCertArgs args, Func <ILogger> getLogger)
        {
            args.Validate();
            var settings = RunnerHelper.GetSettings(args.Configfile);
            var clientCertificateProvider = new ClientCertificateProvider(settings);

            var item = clientCertificateProvider.GetClientCertificate(args.PackageSource);

            if (item != null)
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture,
                                                          Strings.Error_ClientCertificateAlreadyExist,
                                                          args.PackageSource));
            }

            if (args.IsFileCertSettingsProvided())
            {
                item = new FileClientCertItem(args.PackageSource,
                                              args.Path,
                                              args.Password,
                                              args.StorePasswordInClearText,
                                              args.Configfile);
            }
            else if (args.IsStoreCertSettingsProvided())
            {
                item = new StoreClientCertItem(args.PackageSource,
                                               args.FindValue,
                                               args.GetStoreLocation(),
                                               args.GetStoreName(),
                                               args.GetFindBy());
            }
            else
            {
                throw new CommandLineArgumentCombinationException(string.Format(CultureInfo.CurrentCulture,
                                                                                Strings.Error_UnknownClientCertificateStoreType));
            }

            try
            {
                var certificates = item.Search();
                if (!certificates.Any())
                {
                    throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Strings.Error_ClientCertificatesNotFound));
                }
            }
            catch
            {
                if (!args.Force)
                {
                    throw;
                }
            }


            clientCertificateProvider.AddOrUpdate(item);

            getLogger().LogInformation(string.Format(CultureInfo.CurrentCulture, Strings.ClientCertificateSuccessfullyAdded, args.PackageSource));
        }
Пример #2
0
        public void FileClientCertItem_WithClearTextPassword_ParsedCorrectly()
        {
            // Arrange
            var config = @"
<configuration>
   <SectionName>
      <fileCert packageSource=""Foo"" path="".\certificate.pfx"" clearTextPassword=""..."" />
   </SectionName>
</configuration>";

            var nugetConfigPath = "NuGet.Config";

            using (var mockBaseDirectory = TestDirectory.Create())
            {
                SettingsTestUtils.CreateConfigurationFile(nugetConfigPath, mockBaseDirectory, config);

                // Act and Assert
                var settingsFile = new SettingsFile(mockBaseDirectory);
                var section      = settingsFile.GetSection("SectionName");
                section.Should().NotBeNull();
                var items = section.Items.ToList();

                items.Count.Should().Be(1);

                var fileClientCertItem = (FileClientCertItem)items[0];
                fileClientCertItem.ElementName.Should().Be("fileCert");
                fileClientCertItem.PackageSource.Should().Be("Foo");
                fileClientCertItem.FilePath.Should().Be(@".\certificate.pfx");
                fileClientCertItem.Password.Should().Be(@"...");
                fileClientCertItem.IsPasswordIsClearText.Should().Be(true);

                var expectedFileClientCertItem = new FileClientCertItem("Foo",
                                                                        @".\certificate.pfx",
                                                                        "...",
                                                                        true,
                                                                        string.Empty);

                SettingsTestUtils.DeepEquals(fileClientCertItem, expectedFileClientCertItem).Should().BeTrue();
            }
        }
Пример #3
0
 private static bool FileClientCertItem_DeepEquals(FileClientCertItem item1, FileClientCertItem item2)
 {
     return(ItemBase_DeepEquals(item1, item2));
 }