Esempio n. 1
0
        public void Remove_Test()
        {
            ServiceIdentityTree tree = this.SetupTree();

            // Delete a node
            tree.Remove(this.e2_L1.Id).Wait();

            // Auth-chains for everything in its subtree should be invalidated
            Assert.False(tree.GetAuthChain(this.e2_L1.Id).Result.HasValue);
            Assert.False(tree.GetAuthChain(this.e3_L2.Id).Result.HasValue);
            Assert.False(tree.GetAuthChain(this.e4_L2.Id).Result.HasValue);
            Assert.False(tree.GetAuthChain(this.leaf2.Id).Result.HasValue);
            Assert.False(tree.GetAuthChain(this.mod2.Id).Result.HasValue);

            // Delete the rest of the subtree
            tree.Remove(this.e3_L2.Id).Wait();
            tree.Remove(this.e4_L2.Id).Wait();
            tree.Remove(this.leaf2.Id).Wait();
            tree.Remove(this.mod2.Id).Wait();

            // Nothing under e2_L1 should remain
            Assert.False(tree.Get(this.e2_L1.Id).Result.HasValue);
            Assert.False(tree.Get(this.e3_L2.Id).Result.HasValue);
            Assert.False(tree.Get(this.e4_L2.Id).Result.HasValue);
            Assert.False(tree.Get(this.leaf2.Id).Result.HasValue);
            Assert.False(tree.Get(this.mod2.Id).Result.HasValue);
        }
Esempio n. 2
0
        public void Update_Test()
        {
            ServiceIdentityTree tree = this.SetupTree();

            // Re-insert the same node, nothing should have changed
            tree.AddOrUpdate(this.e2_L2).Wait();
            this.CheckValidAuthChains(tree);

            // Re-parent e3_L2 from e2_L1 to e1_L1
            ServiceIdentity updatedIdentity = CreateServiceIdentity(
                this.e3_L2.DeviceId,
                null,
                this.e3_L2.DeviceScope.Expect(() => new InvalidOperationException()),
                this.e1_L1.DeviceScope.Expect(() => new InvalidOperationException()),
                true);

            tree.AddOrUpdate(updatedIdentity).Wait();

            // Equality check
            Option <ServiceIdentity> roundTripIdentity = tree.Get(updatedIdentity.Id).Result;

            Assert.True(roundTripIdentity.Contains(updatedIdentity));

            // The child of e3_L2, leaf2, should also go through a different path for authchain now
            Option <string> authChainActual          = tree.GetAuthChain(this.leaf2.Id).Result;
            string          leaf2_authchain_expected =
                this.leaf2.Id + ";" +
                this.e3_L2.Id + ";" +
                this.e1_L1.Id + ";" +
                this.root.Id;

            Assert.True(authChainActual.Contains(leaf2_authchain_expected));
        }
Esempio n. 3
0
        public void Update_NotChanged_Test()
        {
            ServiceIdentityTree tree = this.SetupTree();

            ServiceIdentity updated = CreateServiceIdentity("e2_L2", null, "e2_L2_scope", "e1_L1_scope", true);
            ServiceIdentity root    = CreateServiceIdentity("root", null, "rootScope", null, true);

            // Re-insert the same node, nothing should have changed
            tree.AddOrUpdate(updated).Wait();
            tree.AddOrUpdate(root).Wait();
            this.CheckValidAuthChains(tree);

            Option <ServiceIdentity> roundTripIdentity = tree.Get(this.e2_L2.Id).Result;
            Option <ServiceIdentity> roundTripRoot     = tree.Get(this.root.Id).Result;

            Assert.True(roundTripIdentity.HasValue);
            Assert.True(ReferenceEquals(roundTripIdentity.OrDefault(), this.e2_L2));
            Assert.False(ReferenceEquals(roundTripIdentity.OrDefault(), updated));
            Assert.True(roundTripRoot.HasValue);
            Assert.True(ReferenceEquals(roundTripRoot.OrDefault(), this.root));
            Assert.False(ReferenceEquals(roundTripRoot.OrDefault(), root));
        }