public CertificateStorageTests(CertificateStorageTestFixture fixture, ITestOutputHelper log)
 {
     _logger   = SerilogTestLogger.Create <CertificateStorageTests>(log);
     _fixture  = fixture;
     _services = _fixture.Services;
     _registry = _fixture.Registry;
     _fixture.SkipOnInvalidConfiguration();
 }
Esempio n. 2
0
        public CertificateStorageTestFixture()
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(Directory.GetCurrentDirectory())
                          .AddJsonFile("testsettings.json", false, true)
                          .AddJsonFile("testsettings.Development.json", true, true)
                          .AddFromDotEnvFile()
                          .AddEnvironmentVariables();
            var configuration = builder.Build();

            _serviceConfig = new VaultConfig(configuration);
            _clientConfig  = new ClientConfig(configuration);
            _vaultConfig   = new KeyVaultConfig(configuration);
            _logger        = SerilogTestLogger.Create <CertificateStorageTestFixture>();
            if (!InvalidConfiguration())
            {
                RandomGenerator = new ApplicationTestDataGenerator();
                var timeid = DateTime.UtcNow.ToFileTimeUtc() / 1000 % 10000;

                // Create registry
                GroupId = "test";

                Registry = new TrustGroupDatabase(new ItemContainerFactory(
                                                      new CosmosDbServiceClient(_serviceConfig, _logger)), _logger);

                // Registry.CreateGroupAsync(new CertificateGroupCreateRequestModel {
                //     Name = "GroupTestIssuerCA" + timeid.ToString(),
                //     SubjectName = "CN=OPC Vault Cert Request Test CA, O=Microsoft, OU=Azure IoT",
                //     CertificateType = CertificateType.ApplicationInstanceCertificate
                // }, CancellationToken.None).Result.Id

                // Create client
                var serializer = new KeyVaultKeyHandleSerializer();
                var repo       = new CertificateDatabase(new ItemContainerFactory(
                                                             new CosmosDbServiceClient(_serviceConfig, _logger)), serializer);
                _keyVaultServiceClient = new KeyVaultServiceClient(_vaultConfig,
                                                                   new AppAuthenticationProvider(_clientConfig), repo, _logger);

                // Create services
                Services = new RequestDatabase(
                    repo,
                    _keyVaultServiceClient,  // keystore
                    Registry,
                    _keyVaultServiceClient,  // issuer
                    new CertificateRevoker(repo, _keyVaultServiceClient, _keyVaultServiceClient),
                    new EntityExtensionFactory(_keyVaultServiceClient),
                    _serviceConfig);

                // Clear
                _keyVaultServiceClient.PurgeAsync("groups", GroupId, CancellationToken.None).Wait();
            }
            KeyVaultInitOk = false;
        }
Esempio n. 3
0
 public CertificateAuthorityTests(CertificateAuthorityTestFixture fixture, ITestOutputHelper log)
 {
     _fixture = fixture;
     // fixture
     fixture.SkipOnInvalidConfiguration();
     _logger = SerilogTestLogger.Create <CertificateAuthorityTests>(log);
     _applicationsDatabase = fixture.ApplicationsDatabase;
     _groupServices        = fixture.Services;
     _groupRegistry        = fixture.Registry;
     _requests             = fixture.RequestManagement;
     _ca = fixture.CertificateAuthority;
     _applicationTestSet = fixture.ApplicationTestSet;
     _randomSource       = new RandomSource(10815);
 }
Esempio n. 4
0
        public CertificateAuthorityTestFixture()
        {
            RandomGenerator = new ApplicationTestDataGenerator(kRandomStart);
            var builder = new ConfigurationBuilder()
                          .SetBasePath(Directory.GetCurrentDirectory())
                          .AddJsonFile("testsettings.json", false, true)
                          .AddJsonFile("testsettings.Development.json", true, true)
                          .AddFromDotEnvFile()
                          .AddEnvironmentVariables();
            var configuration = builder.Build();

            _serviceConfig = new VaultConfig(configuration);
            _clientConfig  = new ClientConfig(configuration);
            _vaultConfig   = new KeyVaultConfig(configuration);
            _logger        = SerilogTestLogger.Create <CertificateAuthorityTestFixture>();
            if (!InvalidConfiguration())
            {
                ApplicationsDatabase = new ApplicationRegistry(new ApplicationDatabase(
                                                                   new ItemContainerFactory(new CosmosDbServiceClient(_serviceConfig, _logger)), _logger),
                                                               new EndpointRegistryStub(), new EndpointRegistryStub(),
                                                               new ApplicationEventBrokerStub(), _logger);

                var timeid = DateTime.UtcNow.ToFileTimeUtc() / 1000 % 10000;

                // Create group registry
                Registry = new TrustGroupDatabase(new ItemContainerFactory(
                                                      new CosmosDbServiceClient(_serviceConfig, _logger)), _logger);
                _groupId = Registry.CreateGroupAsync(new Models.TrustGroupRegistrationRequestModel {
                    Name        = "CertReqConfig" + timeid.ToString(),
                    SubjectName = "CN=OPC Vault Cert Request Test CA, O=Microsoft, OU=Azure IoT",
                }).Result.Id;

                // Create client
                var serializer = new KeyVaultKeyHandleSerializer();
                var repo       = new CertificateDatabase(new ItemContainerFactory(
                                                             new CosmosDbServiceClient(_serviceConfig, _logger)), serializer);
                _keyVaultServiceClient = new KeyVaultServiceClient(_vaultConfig,
                                                                   new AppAuthenticationProvider(_clientConfig), repo, _logger);

                // Create services
                _keyVaultCertificateGroup = new RequestDatabase(
                    repo,
                    _keyVaultServiceClient,  // keystore
                    Registry,
                    _keyVaultServiceClient,  // issuer
                    new CertificateRevoker(repo, _keyVaultServiceClient, _keyVaultServiceClient),
                    new EntityExtensionFactory(_keyVaultServiceClient),
                    _serviceConfig);
                _keyVaultServiceClient.PurgeAsync("groups", _groupId, CancellationToken.None).Wait();
                Services = _keyVaultCertificateGroup;

                CertificateAuthority = new CertificateRequestManager(ApplicationsDatabase, Services,
                                                                     new ItemContainerFactory(new CosmosDbServiceClient(_serviceConfig, _logger)), _logger);
                RequestManagement = (IRequestManagement)CertificateAuthority;

                // create test set
                ApplicationTestSet = new List <ApplicationTestData>();
                for (var i = 0; i < kTestSetSize; i++)
                {
                    var randomApp = RandomGenerator.RandomApplicationTestData();
                    ApplicationTestSet.Add(randomApp);
                }
            }
            RegistrationOk = false;
        }