Ejemplo n.º 1
0
        public void TestCreateSha256Pfx()
        {
            string filePath = IntegrationTestCommon.GetTemporaryCertificateFilePath(string.Format("{0}.pfx", CertificateFilePrefix));

            CertificateBuilder.CreateSelfSignedInFile("Foo", filePath, CertificateBuilder.Sha256Algorithm, password: CommonResources.CertificatePassword);

            TestCertificateFromRawData(filePath, CertificateBuilder.Sha256Algorithm, CommonResources.CertificatePassword);
        }
Ejemplo n.º 2
0
        public void TestCreateCerFileFromRawData()
        {
            string filePath = IntegrationTestCommon.GetTemporaryCertificateFilePath(string.Format("{0}.cer", CertificateFilePrefix));

            CertificateBuilder.CreateSelfSignedInFile("Foo", filePath, CertificateBuilder.Sha1Algorithm);

            TestCertificateFromRawData(filePath, CertificateBuilder.Sha1Algorithm);
        }
        public async Task TestPoolCertificateReferencesWithUpdate()
        {
            Func <Task> test = async() =>
            {
                using (BatchClient batchCli = await TestUtilities.OpenBatchClientAsync(TestUtilities.GetCredentialsFromEnvironment()))
                {
                    //Generate the certificates
                    const string certificatePrefix = "poolwithcertificatereferences";

                    string cerFilePath = IntegrationTestCommon.GetTemporaryCertificateFilePath(string.Format("{0}.cer", certificatePrefix));
                    string pfxFilePath = IntegrationTestCommon.GetTemporaryCertificateFilePath(string.Format("{0}.pfx", certificatePrefix));

                    IEnumerable <Certificate> certificates = GenerateCertificates(batchCli, cerFilePath, pfxFilePath);

                    try
                    {
                        foreach (Certificate certificate in certificates)
                        {
                            this.testOutputHelper.WriteLine("Adding certificate with thumbprint: {0}", certificate.Thumbprint);
                            await certificate.CommitAsync().ConfigureAwait(false);
                        }

                        List <CertificateReference> certificateReferences = certificates.Select(cer => new CertificateReference(cer)
                        {
                            StoreLocation = CertStoreLocation.LocalMachine,
                            StoreName     = "My",
                            Visibility    = CertificateVisibility.RemoteUser
                        }).ToList();

                        await TestPoolCreateAndUpdateWithCertificateReferencesAsync(batchCli, certificateReferences).ConfigureAwait(false);
                        await TestAutoPoolCreateAndUpdateWithCertificateReferencesAsync(batchCli, certificateReferences).ConfigureAwait(false);
                    }
                    finally
                    {
                        File.Delete(pfxFilePath);
                        File.Delete(cerFilePath);

                        foreach (Certificate certificate in certificates)
                        {
                            TestUtilities.DeleteCertificateIfExistsAsync(batchCli, certificate.ThumbprintAlgorithm, certificate.Thumbprint).Wait();
                        }

                        foreach (Certificate certificate in certificates)
                        {
                            TestUtilities.DeleteCertMonitor(batchCli.CertificateOperations, this.testOutputHelper, certificate.ThumbprintAlgorithm, certificate.Thumbprint);
                        }
                    }
                }
            };

            await SynchronizationContextHelper.RunTestAsync(test, TestTimeout);
        }
        public async Task TestCertificateVerbs()
        {
            Func <Task> test = async() =>
            {
                using (BatchClient batchCli = await TestUtilities.OpenBatchClientAsync(TestUtilities.GetCredentialsFromEnvironment()))
                {
                    //Generate the certificates
                    const string certificatePrefix = "testcertificatecrud";

                    string cerFilePath = IntegrationTestCommon.GetTemporaryCertificateFilePath(string.Format("{0}.cer", certificatePrefix));
                    string pfxFilePath = IntegrationTestCommon.GetTemporaryCertificateFilePath(string.Format("{0}.pfx", certificatePrefix));

                    IEnumerable <Certificate> certificates = GenerateCertificates(batchCli, cerFilePath, pfxFilePath);

                    try
                    {
                        foreach (Certificate certificate in certificates)
                        {
                            this.testOutputHelper.WriteLine("Adding certificate with thumbprint: {0}", certificate.Thumbprint);
                            await certificate.CommitAsync().ConfigureAwait(false);

                            Certificate boundCert = await batchCli.CertificateOperations.GetCertificateAsync(
                                certificate.ThumbprintAlgorithm,
                                certificate.Thumbprint).ConfigureAwait(false);

                            Assert.Equal(certificate.Thumbprint, boundCert.Thumbprint);
                            Assert.Equal(certificate.ThumbprintAlgorithm, boundCert.ThumbprintAlgorithm);
                            Assert.NotNull(boundCert.Url);

                            Certificate certLowerDetail = await batchCli.CertificateOperations.GetCertificateAsync(
                                certificate.ThumbprintAlgorithm,
                                certificate.Thumbprint,
                                new ODATADetailLevel()
                            {
                                SelectClause = "thumbprint, thumbprintAlgorithm"
                            }).ConfigureAwait(false);

                            // confirm lower detail level
                            Assert.Null(certLowerDetail.Url);
                            //test refresh to higher detail level
                            await certLowerDetail.RefreshAsync();

                            // confirm higher detail level
                            Assert.NotNull(certLowerDetail.Url);
                            // test refresh can lower detail level
                            await certLowerDetail.RefreshAsync(new ODATADetailLevel()
                            {
                                SelectClause = "thumbprint, thumbprintAlgorithm"
                            });

                            // confirm lower detail level via refresh
                            Assert.Null(certLowerDetail.Url);
                        }

                        List <CertificateReference> certificateReferences = certificates.Select(cer => new CertificateReference(cer)
                        {
                            StoreLocation = CertStoreLocation.LocalMachine,
                            StoreName     = "My",
                            Visibility    = CertificateVisibility.RemoteUser
                        }).ToList();

                        await TestCancelDeleteCertificateAsync(batchCli, certificateReferences, certificates.First()).ConfigureAwait(false);
                    }
                    finally
                    {
                        File.Delete(pfxFilePath);
                        File.Delete(cerFilePath);

                        foreach (Certificate certificate in certificates)
                        {
                            TestUtilities.DeleteCertificateIfExistsAsync(batchCli, certificate.ThumbprintAlgorithm, certificate.Thumbprint).Wait();
                        }

                        foreach (Certificate certificate in certificates)
                        {
                            TestUtilities.DeleteCertMonitor(batchCli.CertificateOperations, this.testOutputHelper, certificate.ThumbprintAlgorithm, certificate.Thumbprint);
                        }
                    }
                }
            };

            await SynchronizationContextHelper.RunTestAsync(test, TestTimeout);
        }