Ejemplo n.º 1
0
        public void GetAddedCnsAndIssuersTest()
        {
            Dictionary <string, string> currentList = new Dictionary <string, string>()
            {
                { "cn1", "tp1,tp2" },
                { "cn2", null },
                { "cn3", "tp3" },
                { "cn4", null }
            };
            Dictionary <string, string> newList = new Dictionary <string, string>()
            {
                { "cn1", "tp2,tp4" },
                { "cn2", null },
                { "cn4", "tp5" },
                { "cn5", null },
            };

            ServerCertificateCommonNames currentCns     = ConstructCertCommonNames(currentList);
            ServerCertificateCommonNames newCns         = ConstructCertCommonNames(newList);
            Dictionary <string, string>  actualResult   = CertificateClusterUpgradeFlow.GetAddedCnsAndIssuers(currentCns, newCns);
            Dictionary <string, string>  expectedResult = new Dictionary <string, string>()
            {
                { "cn1", "tp4" },
                { "cn4", "tp5" },
                { "cn5", null },
            };

            Assert.AreEqual(expectedResult.Count, actualResult.Count);
            Assert.IsTrue(actualResult.All(p => p.Value == expectedResult[p.Key]));
        }
Ejemplo n.º 2
0
        public void SwapCertTest()
        {
            X509 currentCert;
            X509 targetCert;
            List <CertificateClusterUpgradeStep> flow;

            GetCerts_Swap(out currentCert, out targetCert);
            flow = CertificateClusterUpgradeFlow.GetUpgradeFlow(currentCert, targetCert);
            VerifyFlow_Swap(currentCert.ClusterCertificate, targetCert.ClusterCertificate, flow);
        }
Ejemplo n.º 3
0
        public void ReplaceCertTest()
        {
            X509 currentCert;
            X509 targetCert;
            List <CertificateClusterUpgradeStep> flow;

            GetCerts_ReplaceThumbprint(out currentCert, out targetCert);
            flow = CertificateClusterUpgradeFlow.GetUpgradeFlow(currentCert, targetCert);
            VerifyFlow_ReplaceThumbprint(currentCert.ClusterCertificate, targetCert.ClusterCertificate, flow);

            GetCerts_ReplaceCn(out currentCert, out targetCert);
            flow = CertificateClusterUpgradeFlow.GetUpgradeFlow(currentCert, targetCert);
            VerifyFlow_ReplaceCn(currentCert.ClusterCertificateCommonNames, targetCert.ClusterCertificateCommonNames, flow);
        }
Ejemplo n.º 4
0
        public void MergeCnsAndIssuersTest()
        {
            Dictionary <string, string> current = new Dictionary <string, string>()
            {
                { "cn1", "tp1,tp2" },
                { "cn2", null },
            };
            Dictionary <string, string> added = new Dictionary <string, string>();

            // no added
            Dictionary <string, string> actualResult   = CertificateClusterUpgradeFlow.MergeCnsAndIssuers(current, added);
            Dictionary <string, string> expectedResult = current;

            Assert.AreEqual(expectedResult.Count, actualResult.Count);
            Assert.IsTrue(actualResult.All(p => p.Value == expectedResult[p.Key]));

            // have added cn and issuers
            added = new Dictionary <string, string>()
            {
                { "cn1", "tp2,tp3" },
                { "cn3", "tp4" },
            };
            actualResult   = CertificateClusterUpgradeFlow.MergeCnsAndIssuers(current, added);
            expectedResult = new Dictionary <string, string>()
            {
                { "cn1", "tp1,tp2,tp3" },
                { "cn2", null },
                { "cn3", "tp4" },
            };
            Assert.AreEqual(expectedResult.Count, actualResult.Count);

            foreach (string key in actualResult.Keys)
            {
                string actualValue   = actualResult[key];
                string expectedValue = expectedResult[key];

                Assert.AreEqual(actualValue == null, expectedValue == null);
                if (actualValue != null)
                {
                    string[] actualThumbprints   = actualValue.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    string[] expectedThumbprints = expectedValue.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    Assert.IsTrue(actualThumbprints.Any());
                    Assert.IsTrue(expectedThumbprints.Any());
                    Assert.IsTrue(actualThumbprints.All(p => expectedThumbprints.Contains(p)) && expectedThumbprints.All(p => actualThumbprints.Contains(p)));
                }
            }
        }
Ejemplo n.º 5
0
        public void CertTypeChangeTest()
        {
            X509 currentCert;
            X509 targetCert;
            List <CertificateClusterUpgradeStep> flow;

            // 1 thumbprint -> 1 cn
            GetCerts_TypeChange(out currentCert, out targetCert, 1, 0, 0, 1);
            flow = CertificateClusterUpgradeFlow.GetUpgradeFlow(currentCert, targetCert);
            VerifyFlow_TypeChange(currentCert, targetCert, flow);

            // 1 thumbprint -> 2 cns
            GetCerts_TypeChange(out currentCert, out targetCert, 1, 0, 0, 2);
            flow = CertificateClusterUpgradeFlow.GetUpgradeFlow(currentCert, targetCert);
            VerifyFlow_TypeChange(currentCert, targetCert, flow);

            // 2 thumbprint -> 1 cn
            GetCerts_TypeChange(out currentCert, out targetCert, 2, 0, 0, 1);
            flow = CertificateClusterUpgradeFlow.GetUpgradeFlow(currentCert, targetCert);
            VerifyFlow_TypeChange(currentCert, targetCert, flow);

            // 2 thumbprint -> 2 cns
            GetCerts_TypeChange(out currentCert, out targetCert, 2, 0, 0, 2);
            flow = CertificateClusterUpgradeFlow.GetUpgradeFlow(currentCert, targetCert);
            VerifyFlow_TypeChange(currentCert, targetCert, flow);

            // 1 cn -> 1 thumbprint
            GetCerts_TypeChange(out currentCert, out targetCert, 0, 1, 1, 0);
            flow = CertificateClusterUpgradeFlow.GetUpgradeFlow(currentCert, targetCert);
            VerifyFlow_TypeChange(currentCert, targetCert, flow);

            // 1 cn -> 2 thumbprints
            GetCerts_TypeChange(out currentCert, out targetCert, 0, 1, 2, 0);
            flow = CertificateClusterUpgradeFlow.GetUpgradeFlow(currentCert, targetCert);
            VerifyFlow_TypeChange(currentCert, targetCert, flow);

            // 2 cns -> 1 thumbprint
            GetCerts_TypeChange(out currentCert, out targetCert, 0, 2, 1, 0);
            flow = CertificateClusterUpgradeFlow.GetUpgradeFlow(currentCert, targetCert);
            VerifyFlow_TypeChange(currentCert, targetCert, flow);

            // 2 cns -> 2 thumbprints
            GetCerts_TypeChange(out currentCert, out targetCert, 0, 2, 2, 0);
            flow = CertificateClusterUpgradeFlow.GetUpgradeFlow(currentCert, targetCert);
            VerifyFlow_TypeChange(currentCert, targetCert, flow);
        }
Ejemplo n.º 6
0
        public void AddCertTest()
        {
            X509 currentCert;
            X509 targetCert;
            List <CertificateClusterUpgradeStep> flow;

            GetCerts_AddThumbprint(out currentCert, out targetCert, addPrimary: true);
            flow = CertificateClusterUpgradeFlow.GetUpgradeFlow(currentCert, targetCert);
            VerifyFlow_AddThumbprint(currentCert.ClusterCertificate, targetCert.ClusterCertificate, flow);

            GetCerts_AddThumbprint(out currentCert, out targetCert, addPrimary: false);
            flow = CertificateClusterUpgradeFlow.GetUpgradeFlow(currentCert, targetCert);
            VerifyFlow_AddThumbprint(currentCert.ClusterCertificate, targetCert.ClusterCertificate, flow);

            GetCerts_AddCn(out currentCert, out targetCert, addCn1: true);
            flow = CertificateClusterUpgradeFlow.GetUpgradeFlow(currentCert, targetCert);
            VerifyFlow_AddCn(currentCert.ClusterCertificateCommonNames, targetCert.ClusterCertificateCommonNames, flow);

            GetCerts_AddCn(out currentCert, out targetCert, addCn1: false);
            flow = CertificateClusterUpgradeFlow.GetUpgradeFlow(currentCert, targetCert);
            VerifyFlow_AddCn(currentCert.ClusterCertificateCommonNames, targetCert.ClusterCertificateCommonNames, flow);
        }