Esempio n. 1
0
 static void AddProperty(Dictionary <string, List <AuthProperty> > properties, string name, string value)
 {
     if (!properties.TryGetValue(name, out var values))
     {
         values = (properties[name] = new List <AuthProperty>());
     }
     values.Add(AuthProperty.Create(name, Encoding.UTF8.GetBytes(value)));
 }
        public void Create()
        {
            var valueBytes   = new byte[] { 68, 69, 70 };
            var authProperty = AuthProperty.Create("abc", valueBytes);

            Assert.AreEqual("abc", authProperty.Name);
            Assert.AreNotSame(valueBytes, authProperty.ValueBytesUnsafe);
            CollectionAssert.AreEqual(valueBytes, authProperty.ValueBytes);
            CollectionAssert.AreEqual(valueBytes, authProperty.ValueBytesUnsafe);
            Assert.AreEqual("DEF", authProperty.Value);
        }
Esempio n. 3
0
        public void AuthenticatedContext()
        {
            var property1 = AuthProperty.Create("abc", new byte[] { 68, 69, 70 });
            var context   = new AuthContext("some_identity", new Dictionary <string, List <AuthProperty> >
            {
                { "some_identity", new List <AuthProperty> {
                      property1
                  } }
            });

            Assert.IsTrue(context.IsPeerAuthenticated);
            Assert.AreEqual("some_identity", context.PeerIdentityPropertyName);
            Assert.AreEqual(1, context.PeerIdentity.Count());
        }
Esempio n. 4
0
        public void FindPropertiesByName()
        {
            var property1 = AuthProperty.Create("abc", new byte[] { 68, 69, 70 });
            var property2 = AuthProperty.Create("abc", new byte[] { 71, 72, 73 });
            var property3 = AuthProperty.Create("abc", new byte[] {});
            var context   = new AuthContext(null, new Dictionary <string, List <AuthProperty> >
            {
                { "existent", new List <AuthProperty> {
                      property1, property2
                  } },
                { "foobar", new List <AuthProperty> {
                      property3
                  } },
            });

            Assert.AreEqual(3, context.Properties.Count());
            Assert.AreEqual(0, context.FindPropertiesByName("nonexistent").Count());

            var existentProperties = new List <AuthProperty>(context.FindPropertiesByName("existent"));

            Assert.AreEqual(2, existentProperties.Count);
        }
 public void Create_ValueIsNotNull()
 {
     Assert.Throws(typeof(ArgumentNullException), () => AuthProperty.Create("abc", null));
     Assert.Throws(typeof(ArgumentNullException), () => AuthProperty.CreateUnsafe("abc", null));
 }
 public void Create_NameIsNotNull()
 {
     Assert.Throws(typeof(ArgumentNullException), () => AuthProperty.Create(null, new byte[0]));
     Assert.Throws(typeof(ArgumentNullException), () => AuthProperty.CreateUnsafe(null, new byte[0]));
 }