Exemplo n.º 1
0
        public void testIdentityManagement()
        {
            /* foreach */
            foreach (PibDataFixture2 fixture  in  pibImpls)
            {
                PibImpl pib = fixture.pib;

                // No default identity is set. This should throw an Error.
                try {
                    pib.getDefaultIdentity();
                    Assert.Fail("Did not throw the expected exception");
                } catch (Pib.Error ex) {
                } catch (Exception ex_0) {
                    Assert.Fail("Did not throw the expected exception");
                }

                // Check for id1, which should not exist.
                Assert.AssertEquals(false, pib.hasIdentity(fixture.id1));

                // Add id1, which should be the default.
                pib.addIdentity(fixture.id1);
                Assert.AssertEquals(true, pib.hasIdentity(fixture.id1));
                try {
                    pib.getDefaultIdentity();
                } catch (Exception ex_1) {
                    Assert.Fail("Unexpected exception: " + ex_1.Message);
                }
                Assert.AssertEquals(fixture.id1, pib.getDefaultIdentity());

                // Add id2, which should not be the default.
                pib.addIdentity(fixture.id2);
                Assert.AssertEquals(true, pib.hasIdentity(fixture.id2));
                Assert.AssertEquals(fixture.id1, pib.getDefaultIdentity());

                // Explicitly set id2 as the default.
                pib.setDefaultIdentity(fixture.id2);
                Assert.AssertEquals(fixture.id2, pib.getDefaultIdentity());

                // Remove id2. The PIB should not have a default identity.
                pib.removeIdentity(fixture.id2);
                Assert.AssertEquals(false, pib.hasIdentity(fixture.id2));
                try {
                    pib.getDefaultIdentity();
                    Assert.Fail("Did not throw the expected exception");
                } catch (Pib.Error ex_2) {
                } catch (Exception ex_3) {
                    Assert.Fail("Did not throw the expected exception");
                }

                // Set id2 as the default. This should add id2 again.
                pib.setDefaultIdentity(fixture.id2);
                Assert.AssertEquals(fixture.id2, pib.getDefaultIdentity());

                // Get all the identities, which should have id1 and id2.
                HashedSet <Name> idNames = pib.getIdentities();
                Assert.AssertEquals(2, idNames.Count);
                Assert.AssertTrue(ILOG.J2CsMapping.Collections.Collections.Contains(fixture.id1, idNames));
                Assert.AssertTrue(ILOG.J2CsMapping.Collections.Collections.Contains(fixture.id2, idNames));
            }
        }
Exemplo n.º 2
0
        public void testDefaultsManagement()
        {
            /* foreach */
            foreach (PibDataFixture2 fixture  in  pibImpls)
            {
                PibImpl pib = fixture.pib;

                pib.addIdentity(fixture.id1);
                Assert.AssertEquals(fixture.id1, pib.getDefaultIdentity());

                pib.addIdentity(fixture.id2);
                Assert.AssertEquals(fixture.id1, pib.getDefaultIdentity());

                pib.removeIdentity(fixture.id1);
                try {
                    pib.getDefaultIdentity();
                    Assert.Fail("Did not throw the expected exception");
                } catch (Pib.Error ex) {
                } catch (Exception ex_0) {
                    Assert.Fail("Did not throw the expected exception");
                }

                pib.addKey(fixture.id2, fixture.id2Key1Name, fixture.id2Key1.buf());
                Assert.AssertEquals(fixture.id2, pib.getDefaultIdentity());
                Assert.AssertEquals(fixture.id2Key1Name,
                                    pib.getDefaultKeyOfIdentity(fixture.id2));

                pib.addKey(fixture.id2, fixture.id2Key2Name, fixture.id2Key2.buf());
                Assert.AssertEquals(fixture.id2Key1Name,
                                    pib.getDefaultKeyOfIdentity(fixture.id2));

                pib.removeKey(fixture.id2Key1Name);
                try {
                    pib.getDefaultKeyOfIdentity(fixture.id2);
                    Assert.Fail("Did not throw the expected exception");
                } catch (Pib.Error ex_1) {
                } catch (Exception ex_2) {
                    Assert.Fail("Did not throw the expected exception");
                }

                pib.addCertificate(fixture.id2Key2Cert1);
                Assert.AssertEquals(fixture.id2Key2Name,
                                    pib.getDefaultKeyOfIdentity(fixture.id2));
                Assert.AssertEquals(fixture.id2Key2Cert1.getName(), pib
                                    .getDefaultCertificateOfKey(fixture.id2Key2Name).getName());

                pib.addCertificate(fixture.id2Key2Cert2);
                Assert.AssertEquals(fixture.id2Key2Cert1.getName(), pib
                                    .getDefaultCertificateOfKey(fixture.id2Key2Name).getName());

                pib.removeCertificate(fixture.id2Key2Cert2.getName());
                Assert.AssertEquals(fixture.id2Key2Cert1.getName(), pib
                                    .getDefaultCertificateOfKey(fixture.id2Key2Name).getName());
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Create a PibIdentityImpl with identityName.
        /// </summary>
        ///
        /// <param name="identityName">The name of the identity, which is copied.</param>
        /// <param name="pibImpl">The Pib backend implementation.</param>
        /// <param name="needInit">becomes the default). If false, then throw Pib.Error if the identity does not exist in the pibImpl back end.</param>
        /// <exception cref="Pib.Error">if the identity does not exist in the pibImpl back endand needInit is false.</exception>
        public PibIdentityImpl(Name identityName, PibImpl pibImpl, bool needInit)
        {
            this.defaultKey_ = null;
            // Copy the Name.
            identityName_ = new Name(identityName);
            keys_         = new PibKeyContainer(identityName, pibImpl);
            pibImpl_      = pibImpl;

            if (pibImpl == null)
            {
                throw new AssertionError("The pibImpl is null");
            }

            if (needInit)
            {
                pibImpl_.addIdentity(identityName_);
            }
            else
            {
                if (!pibImpl_.hasIdentity(identityName_))
                {
                    throw new Pib.Error("Identity " + identityName_.toUri()
                                        + " does not exist");
                }
            }
        }