]> git.saurik.com Git - apple/security.git/blob - keychain/securityd/Regressions/secd-82-persistent-ref.m
Security-59306.41.2.tar.gz
[apple/security.git] / keychain / securityd / Regressions / secd-82-persistent-ref.m
1 //
2 // secd-82-persistent-ref.c
3 // sec
4 //
5 // Copyright (c) 2013-2014 Apple Inc. All Rights Reserved.
6 //
7 //
8
9 #include <Security/Security.h>
10 #include <Security/SecItemPriv.h>
11 #include <utilities/SecCFWrappers.h>
12
13 #include "secd_regressions.h"
14 #include "SecdTestKeychainUtilities.h"
15
16 int secd_82_persistent_ref(int argc, char *const *argv)
17 {
18 plan_tests(5);
19
20 /* custom keychain dir */
21 secd_test_setup_temp_keychain("secd_82_persistent_ref", NULL);
22
23 CFMutableDictionaryRef attrs = NULL;
24 CFMutableDictionaryRef query = NULL;
25 CFDataRef data = NULL;
26 CFTypeRef result = NULL;
27 CFArrayRef array = NULL;
28 CFIndex i, n;
29 CFDictionaryRef item = NULL;
30
31 attrs = CFDictionaryCreateMutable( NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks );
32 CFDictionarySetValue( attrs, kSecClass, kSecClassGenericPassword );
33 CFDictionarySetValue( attrs, kSecAttrAccessible, kSecAttrAccessibleAlwaysPrivate );
34 CFDictionarySetValue( attrs, kSecAttrLabel, CFSTR( "TestLabel" ) );
35 CFDictionarySetValue( attrs, kSecAttrDescription, CFSTR( "TestDescription" ) );
36 CFDictionarySetValue( attrs, kSecAttrAccount, CFSTR( "TestAccount" ) );
37 CFDictionarySetValue( attrs, kSecAttrService, CFSTR( "TestService" ) );
38 data = CFDataCreate( NULL, (const uint8_t *) "\x00\x01\x02", 3 );
39 CFDictionarySetValue( attrs, kSecValueData, data );
40 CFReleaseNull( data );
41
42 is(SecItemAdd(attrs, NULL), errSecSuccess);
43 CFReleaseNull( attrs );
44
45 query = CFDictionaryCreateMutable( NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks );
46 CFDictionarySetValue( query, kSecClass, kSecClassGenericPassword );
47 CFDictionarySetValue( query, kSecAttrSynchronizable, kSecAttrSynchronizableAny );;
48 CFDictionarySetValue( query, kSecAttrAccount, CFSTR( "TestAccount" ) );
49 CFDictionarySetValue( query, kSecReturnAttributes, kCFBooleanTrue );
50 CFDictionarySetValue( query, kSecReturnPersistentRef, kCFBooleanTrue );
51 CFDictionarySetValue( query, kSecMatchLimit, kSecMatchLimitAll );
52
53 is(SecItemCopyMatching(query, &result), errSecSuccess);
54 CFReleaseNull( query );
55 array = (CFArrayRef) result;
56
57 SKIP: {
58 skip("No results from SecItemCopyMatching", 2, array && (CFArrayGetTypeID() == CFGetTypeID(array)));
59 n = CFArrayGetCount( array );
60 is(n, 1);
61 for( i = 0; i < n; ++i )
62 {
63 item = (CFDictionaryRef) CFArrayGetValueAtIndex(array, i);
64
65 ok((CFDataRef) CFDictionaryGetValue(item, kSecValuePersistentRef));
66 }
67 }
68 CFReleaseNull( result );
69
70
71 return 0;
72 }