public void AddQueryRemove_Identity()
        {
            using (SecRecord rec = new SecRecord(SecKind.Identity))
                using (var id = IdentityTest.GetIdentity()) {
                    rec.SetValueRef(id);
                    SecStatusCode code = SecKeyChain.Add(rec);
                    Assert.True(code == SecStatusCode.DuplicateItem || code == SecStatusCode.Success);
                }

            if (!TestRuntime.CheckXcodeVersion(5, 0))
            {
                Assert.Inconclusive("QueryAsConcreteType does not work before iOS7");
            }

            using (SecRecord rec = new SecRecord(SecKind.Identity)) {
                SecStatusCode code;
                var           match = SecKeyChain.QueryAsConcreteType(rec, out code);
                if ((match == null) && (code == SecStatusCode.ItemNotFound))
                {
                    Assert.Inconclusive("Test randomly fails (race condition between addtion/commit/query?");
                }

                Assert.That(code, Is.EqualTo(SecStatusCode.Success), "QueryAsRecord-2");
                Assert.NotNull(match, "match-2");

                code = SecKeyChain.Remove(rec);
                Assert.That(code, Is.EqualTo(SecStatusCode.Success), "Remove");

                match = SecKeyChain.QueryAsConcreteType(rec, out code);
                Assert.That(code, Is.EqualTo(SecStatusCode.ItemNotFound), "QueryAsRecord-3");
                Assert.Null(match, "match-3");
            }
        }
 // same as Add_Identity but directly p/invoking - shows that the type MUST NOT be included for Identity
 public void SecItemAdd_Identity()
 {
     using (NSString valueref = new NSString("v_Ref"))
         using (NSMutableDictionary data = new NSMutableDictionary())
             using (var id = IdentityTest.GetIdentity()) {
                 data.LowlevelSetObject(id.Handle, valueref.Handle);
                 SecStatusCode code = SecItemAdd(data.Handle, IntPtr.Zero);
                 Assert.True(code == SecStatusCode.DuplicateItem || code == SecStatusCode.Success);
             }
 }
        public void IdentityRecordTest()
        {
            using (var identity = IdentityTest.GetIdentity())
                using (var rec = new SecRecord(identity)) {
                    SecStatusCode code = SecKeyChain.Add(rec);
                    Assert.True(code == SecStatusCode.DuplicateItem || code == SecStatusCode.Success, "Identity added");

                    var ret = rec.GetIdentity();
                    Assert.NotNull(ret, "ret is null");
                    Assert.That(identity.Handle, Is.EqualTo(ret.Handle), "Same Handle");

                    Assert.Throws <InvalidOperationException> (() => rec.GetKey(), "GetKey should throw");
                    Assert.Throws <InvalidOperationException> (() => rec.GetCertificate(), "GetCertificate should throw");
                }
        }
Beispiel #4
0
        public void SecItemAdd_Identity()
        {
            using (NSString valueref = new NSString("v_Ref"))
                using (NSMutableDictionary data = new NSMutableDictionary())
                    using (var id = IdentityTest.GetIdentity()) {
                        data.LowlevelSetObject(id.Handle, valueref.Handle);
                        SecStatusCode code     = SecItemAdd(data.Handle, IntPtr.Zero);
                        var           expected = Is.EqualTo(SecStatusCode.DuplicateItem).Or.EqualTo(SecStatusCode.Success);
#if __MACOS__
                        if (!TestRuntime.CheckSystemVersion(PlatformName.MacOSX, 10, 9))
                        {
                            expected = Is.EqualTo(SecStatusCode.Param);
                        }
#endif
                        Assert.That(code, expected);
                    }
        }