]> git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_keychain/regressions/kc-helpers.h
Security-59306.140.5.tar.gz
[apple/security.git] / OSX / libsecurity_keychain / regressions / kc-helpers.h
1 /*
2 * Copyright (c) 2016 Apple Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 #ifndef kc_helpers_h
25 #define kc_helpers_h
26
27 #include <stdlib.h>
28 #include <unistd.h>
29
30 #include <Security/Security.h>
31 #include <Security/SecKeychainPriv.h>
32 #include "utilities/SecCFRelease.h"
33
34 #include "kc-keychain-file-helpers.h"
35
36 extern char keychainFile[1000];
37 extern char keychainDbFile[1000];
38 extern char keychainTempFile[1000];
39 extern char keychainName[1000];
40 extern char testName[1000];
41
42 /* redefine this since the headers are mixed up */
43 static inline bool CFEqualSafe(CFTypeRef left, CFTypeRef right)
44 {
45 if (left == NULL || right == NULL)
46 return left == right;
47 else
48 return CFEqual(left, right);
49 }
50
51 void startTest(const char* thisTestName);
52
53 void initializeKeychainTests(const char* thisTestName);
54
55 // Use this at the bottom of every test to make sure everything is gone
56 void deleteTestFiles(void);
57
58 void addToSearchList(SecKeychainRef keychain);
59
60 /* Checks to be sure there are N elements in this search, and returns the first
61 * if it exists. */
62 SecKeychainItemRef checkNCopyFirst(char* testName, const CFDictionaryRef CF_CONSUMED query, uint32_t n);
63
64 void checkN(char* testName, const CFDictionaryRef CF_CONSUMED query, uint32_t n);
65 #define checkNTests 3
66
67 void readPasswordContentsWithResult(SecKeychainItemRef item, OSStatus expectedResult, CFStringRef expectedContents);
68 #define readPasswordContentsWithResultTests 3
69
70 void readPasswordContents(SecKeychainItemRef item, CFStringRef expectedContents);
71 #define readPasswordContentsTests readPasswordContentsWithResultTests
72
73 void changePasswordContents(SecKeychainItemRef item, CFStringRef newPassword);
74 #define changePasswordContentsTests 1
75
76 void deleteItem(SecKeychainItemRef item);
77 #define deleteItemTests 1
78
79 void deleteItems(CFArrayRef items);
80 #define deleteItemsTests 1
81
82 /* Checks in with securityd to see how many prompts were generated since the last call to this function, and tests against the number expected.
83 Returns the number generated since the last call. */
84 uint32_t checkPrompts(uint32_t expectedSinceLastCall, char* explanation);
85 #define checkPromptsTests 2
86
87 #endif /* kc_helpers_h */