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)));
 }
Esempio n. 2
0
        private AuthProperty PtrToAuthProperty(IntPtr authPropertyPtr)
        {
            var nativeAuthProperty = (NativeAuthProperty)Marshal.PtrToStructure(authPropertyPtr, typeof(NativeAuthProperty));
            var name       = Marshal.PtrToStringAnsi(nativeAuthProperty.Name);
            var valueBytes = new byte[(int)nativeAuthProperty.ValueLength];

            Marshal.Copy(nativeAuthProperty.Value, valueBytes, 0, (int)nativeAuthProperty.ValueLength);
            return(AuthProperty.CreateUnsafe(name, valueBytes));
        }
        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);
        }
 private AuthProperty PtrToAuthProperty(IntPtr authPropertyPtr)
 {
     #pragma warning disable 0618
     // We need to use the obsolete non-generic version of Marshal.PtrToStructure, because the generic version is not available in net45
     var nativeAuthProperty = (NativeAuthProperty)Marshal.PtrToStructure(authPropertyPtr, typeof(NativeAuthProperty));
     #pragma warning restore 0618
     var name       = Marshal.PtrToStringAnsi(nativeAuthProperty.Name);
     var valueBytes = new byte[(int)nativeAuthProperty.ValueLength];
     Marshal.Copy(nativeAuthProperty.Value, valueBytes, 0, (int)nativeAuthProperty.ValueLength);
     return(AuthProperty.CreateUnsafe(name, valueBytes));
 }
Esempio n. 5
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. 6
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]));
 }