2 * Copyright (c) 2016 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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 xLicense.
21 * @APPLE_LICENSE_HEADER_END@
24 #import <Security/Security.h>
26 #include "keychain_regressions.h"
27 #include "kc-helpers.h"
28 #include "kc-item-helpers.h"
30 #include <Security/Security.h>
35 SecKeychainRef kc
= getPopulatedTestKeychain();
37 static dispatch_once_t onceToken
= 0;
38 static dispatch_queue_t process_queue
= NULL
;
39 dispatch_once(&onceToken
, ^{
40 process_queue
= dispatch_queue_create("com.apple.security.item-add-queue", DISPATCH_QUEUE_CONCURRENT
);
42 dispatch_group_t g
= dispatch_group_create();
44 for(int i
= 0; i
< BLOCKS
; i
++) {
45 dispatch_group_async(g
, process_queue
, ^() {
46 SecKeychainItemRef blockItem
= NULL
;
47 CFStringRef itemclass
= kSecClassInternetPassword
;
49 CFStringRef label
= CFStringCreateWithFormat(NULL
, NULL
, CFSTR("testItem%05d"), i
);
50 CFStringRef account
= CFSTR("testAccount");
51 CFStringRef service
= CFStringCreateWithFormat(NULL
, NULL
, CFSTR("testService%05d"), i
);
53 asprintf(&name
, "%s (item %d)", testName
, i
);
56 blockItem
= createCustomItem(name
, kc
, createAddCustomItemDictionaryWithService(kc
, itemclass
, label
, account
, service
));
57 CFReleaseNull(blockItem
);
60 blockItem
= checkNCopyFirst(name
, createQueryCustomItemDictionaryWithService(kc
, itemclass
, label
, service
), 1);
61 readPasswordContents(blockItem
, CFSTR("data"));
64 CFMutableDictionaryRef newData
= CFDictionaryCreateMutable(NULL
, 0,
65 &kCFTypeDictionaryKeyCallBacks
,
66 &kCFTypeDictionaryValueCallBacks
);
67 CFDataRef differentdata
= CFDataCreate(NULL
, (void*)"differentdata", strlen("differentdata"));
68 CFDictionarySetValue(newData
, kSecValueData
, differentdata
);
69 CFReleaseNull(differentdata
);
71 CFDictionaryRef query
= createQueryCustomItemDictionaryWithService(kc
, itemclass
, label
, service
);
72 ok_status(SecItemUpdate(query
, newData
), "%s: SecItemUpdate", name
);
74 readPasswordContents(blockItem
, CFSTR("differentdata"));
77 ok_status(SecKeychainItemDelete(blockItem
), "%s: SecKeychainItemDelete", name
);
78 CFReleaseNull(blockItem
);
79 blockItem
= checkNCopyFirst(name
, createQueryCustomItemDictionaryWithService(kc
, itemclass
, label
, service
), 0);
83 CFReleaseNull(service
);
84 CFReleaseNull(blockItem
);
88 dispatch_group_wait(g
, DISPATCH_TIME_FOREVER
);
90 ok_status(SecKeychainDelete(kc
), "%s: SecKeychainDelete", testName
);
94 int kc_20_item_add_stress(int argc
, char *const *argv
)
96 plan_tests(( makeItemTests
+ checkNTests
+ readPasswordContentsTests
+ 1 + readPasswordContentsTests
+ 1 + checkNTests
)*BLOCKS
+ getPopulatedTestKeychainTests
+ 1);
97 initializeKeychainTests(__FUNCTION__
);