Esempio n. 1
0
        public void GetIncomingAndOutgoingCertPolicieByOwnerAndUsage_Test()
        {
            CertPolicyGroupManager groupMgr     = CreatePolicyGroupManager();
            CertPolicyGroup        policyGroup1 = groupMgr.Get("PolicyGroup1");

            policyGroup1.CertPolicies.Count.Should().Be(0);
            CertPolicyGroup policyGroup2 = groupMgr.Get("PolicyGroup2");

            policyGroup1.CertPolicies.Count.Should().Be(0);
            policyGroup2.CertPolicies.Count.Should().Be(0);



            //
            // Map cert policy group to domains
            //
            groupMgr.AssociateToOwner(policyGroup1.Name, "domain1.test.com");
            groupMgr.AssociateToOwner(policyGroup2.Name, "domain2.test.com");
            //
            // Map cert policy group to policy
            //
            groupMgr.AddPolicyUse("Policy1", "PolicyGroup1", CertPolicyUse.TRUST, true, true);
            groupMgr.AddPolicyUse("Policy2", "PolicyGroup1", CertPolicyUse.PRIVATE_RESOLVER, true, false);


            CertPolicyManager policyMgr = CreateManager();

            CertPolicy[] policies = policyMgr.GetIncomingByOwner("domain1.test.com", CertPolicyUse.TRUST);
            policies.Length.Should().Be(1);
            policies = policyMgr.GetIncomingByOwner("domain1.test.com", CertPolicyUse.PUBLIC_RESOLVER);
            policies.Length.Should().Be(0);
            policies = policyMgr.GetOutgoingByOwner("domain1.test.com", CertPolicyUse.TRUST);
            policies.Length.Should().Be(1);
            policies = policyMgr.GetOutgoingByOwner("domain1.test.com", CertPolicyUse.PRIVATE_RESOLVER);
            policies.Length.Should().Be(0);

            policies = policyMgr.GetIncomingByOwner("domain2.test.com", CertPolicyUse.PRIVATE_RESOLVER);
            policies.Length.Should().Be(0);

            policies = policyMgr.GetIncomingByOwner("domain3.test.com", CertPolicyUse.PRIVATE_RESOLVER);
            policies.Length.Should().Be(0);
        }
Esempio n. 2
0
        public void GetPolicyGroupByNameWithPolicyUsage()
        {
            InitCertPolicyRecords();
            InitCertPolicyGroupRecords();

            CertPolicyGroupManager mgr = CreateManager();

            mgr.AddPolicyUse("Policy1", "PolicyGroup1", CertPolicyUse.TRUST, true, true);
            CertPolicyGroupMap[] maps = mgr.GetWithPolicies("PolicyGroup1");
            maps[0].CertPolicyGroup.Name.Should().Be("PolicyGroup1");
            maps[0].CertPolicy.Name.Should().Be("Policy1");
        }
Esempio n. 3
0
        public void AddPolicyUseTest()
        {
            //arrange
            InitCertPolicyRecords();
            InitCertPolicyGroupRecords();

            CertPolicyGroupManager mgr = CreateManager();

            //act
            mgr.AddPolicyUse("Policy1", "PolicyGroup1", CertPolicyUse.TRUST, true, true);

            //assert 1
            CertPolicyGroup policyGroup = mgr.Get("PolicyGroup1");

            policyGroup.CertPolicies.Count.Should().Be(1);

            //act
            mgr.AddPolicyUse("Policy2", "PolicyGroup1", CertPolicyUse.TRUST, false, true);

            //assert 2
            policyGroup = mgr.Get("PolicyGroup1");
            policyGroup.CertPolicies.Count.Should().Be(2);
        }
Esempio n. 4
0
        public void DisassociatePolicyFromGroupTest()
        {
            InitCertPolicyRecords();
            InitCertPolicyGroupRecords();

            CertPolicyGroupManager mgr = CreateManager();

            //act
            mgr.AddPolicyUse("Policy1", "PolicyGroup1", CertPolicyUse.TRUST, true, true);

            CertPolicyGroup policyGroup = mgr.Get("PolicyGroup1");

            policyGroup.CertPolicies.Count.Should().Be(1);

            CertPolicyGroupMap[] map = new CertPolicyGroupMap[] { policyGroup.CertPolicyGroupMaps.First() };
            mgr.RemovePolicy(map);

            policyGroup = mgr.Get("PolicyGroup1");
            policyGroup.CertPolicies.Count.Should().Be(0);
        }
Esempio n. 5
0
        public void DeletePolicyWithAssociations()
        {
            CertPolicyGroupManager groupMgr    = CreatePolicyGroupManager();
            CertPolicyGroup        policyGroup = groupMgr.Get("PolicyGroup1");

            policyGroup.CertPolicies.Count.Should().Be(0);

            CertPolicyManager policyMgr = CreateManager();

            policyMgr.Get("Policy1").Should().NotBeNull();

            groupMgr.AddPolicyUse("Policy1", "PolicyGroup1", CertPolicyUse.PRIVATE_RESOLVER, true, true);

            policyGroup = groupMgr.Get("PolicyGroup1");
            policyGroup.CertPolicies.Count.Should().Be(1);

            CertPolicyManager mgr    = CreateManager();
            CertPolicy        policy = mgr.Get("Policy1");

            mgr.Remove(policy.ID);
            policyMgr.Get("Policy1").Should().BeNull();
        }
        public void GetPolicyGroupsByDomainsWithPoliciesTest()
        {
            InitDomainRecords();
            InitCertPolicyRecords();
            InitCertPolicyGroupRecords();

            CertPolicyGroupManager groupMgr     = CreateManager();
            CertPolicyGroup        policyGroup1 = groupMgr.Get("PolicyGroup1");

            policyGroup1.CertPolicies.Count.Should().Be(0);
            CertPolicyGroup policyGroup2 = groupMgr.Get("PolicyGroup2");

            policyGroup1.CertPolicies.Count.Should().Be(0);
            policyGroup2.CertPolicies.Count.Should().Be(0);



            //
            // Map cert policy group to domains
            //
            groupMgr.AssociateToOwner(policyGroup1.Name, "domain1.test.com");
            groupMgr.AssociateToOwner(policyGroup1.Name, "domain2.test.com");
            groupMgr.AssociateToOwner(policyGroup1.Name, "domain3.test.com");
            groupMgr.AssociateToOwner(policyGroup2.Name, "domain2.test.com");
            //
            // Map cert policy group to policy
            //
            groupMgr.AddPolicyUse("Policy1", "PolicyGroup1", CertPolicyUse.PUBLIC_RESOLVER, true, true);
            groupMgr.AddPolicyUse("Policy2", "PolicyGroup1", CertPolicyUse.PUBLIC_RESOLVER, true, true);
            groupMgr.AddPolicyUse("Policy2", "PolicyGroup2", CertPolicyUse.PUBLIC_RESOLVER, true, true);

            CertPolicyGroup[] policyGroups = groupMgr.GetByDomains(new string[] { "domain1.test.com" });
            policyGroups.Length.Should().Be(1);
            policyGroups.Single(cpg => cpg.Name == "PolicyGroup1").CertPolicyGroupDomainMaps.Count.Should().Be(1);
            policyGroups.Single(cpg => cpg.Name == "PolicyGroup1").CertPolicyGroupMaps.Count.Should().Be(2);
            policyGroups.Single(cpg => cpg.Name == "PolicyGroup1").CertPolicies.Count.Should().Be(2);
            foreach (var policy in policyGroups.Single(cpg => cpg.Name == "PolicyGroup1").CertPolicies)
            {
                Console.WriteLine(policy.Name);
                Console.WriteLine(policy.Data.ToUtf8String());
            }

            policyGroups = groupMgr.GetByDomains(new string[] { "domain2.test.com" });
            policyGroups.Length.Should().Be(2);
            policyGroups.Single(cpg => cpg.Name == "PolicyGroup1").CertPolicyGroupDomainMaps.Count.Should().Be(1);
            policyGroups.Single(cpg => cpg.Name == "PolicyGroup1").CertPolicyGroupMaps.Count.Should().Be(2);
            policyGroups.Single(cpg => cpg.Name == "PolicyGroup2").CertPolicyGroupDomainMaps.Count.Should().Be(1);
            policyGroups.Single(cpg => cpg.Name == "PolicyGroup2").CertPolicyGroupMaps.Count.Should().Be(1);

            policyGroups = groupMgr.GetByDomains(new string[] { "domain1.test.com", "domain2.test.com" });
            policyGroups.Length.Should().Be(2);
            policyGroups.Single(cpg => cpg.Name == "PolicyGroup1").CertPolicyGroupDomainMaps.Count.Should().Be(2);
            policyGroups.Single(cpg => cpg.Name == "PolicyGroup1").CertPolicyGroupMaps.Count.Should().Be(2);
            policyGroups.Single(cpg => cpg.Name == "PolicyGroup2").CertPolicyGroupDomainMaps.Count.Should().Be(1);
            policyGroups.Single(cpg => cpg.Name == "PolicyGroup2").CertPolicyGroupMaps.Count.Should().Be(1);

            policyGroups = groupMgr.GetByDomains(new string[] { "domain1.test.com", "domain2.test.com", "domain3.test.com" });
            policyGroups.Length.Should().Be(2);
            policyGroups.Single(cpg => cpg.Name == "PolicyGroup1").CertPolicyGroupDomainMaps.Count.Should().Be(3);
            policyGroups.Single(cpg => cpg.Name == "PolicyGroup1").CertPolicyGroupMaps.Count.Should().Be(2);
            policyGroups.Single(cpg => cpg.Name == "PolicyGroup2").CertPolicyGroupDomainMaps.Count.Should().Be(1);
            policyGroups.Single(cpg => cpg.Name == "PolicyGroup2").CertPolicyGroupMaps.Count.Should().Be(1);
        }