5 // Created by John Hurley 10/16/12.
6 // Copyright 2012 Apple Inc. All rights reserved.
10 This test is a simple test of SOSCloudKeychainUserNotification to show
11 an OK/Cancel dialog to the user and get the response. Run with:
13 /AppleInternal/Applications/SecurityTests.app/SecurityTests sc_102_cfusernotification -v
17 #include <AssertMacros.h>
18 #include <CoreFoundation/CFUserNotification.h>
19 #include <dispatch/dispatch.h>
21 #include <utilities/SecCFWrappers.h>
22 #include <utilities/debugging.h>
24 #include "SOSCircle_regressions.h"
25 #include "SOSCloudKeychainClient.h"
26 #include "SOSCloudKeychainConstants.h"
28 #if TARGET_OS_EMBEDDED && !TARGET_IPHONE_SIMULATOR
29 #include <MobileGestalt.h>
32 static void tests(void)
34 // CFStringRef messageToUser = CFSTR("OK to sync with world?");
35 // CFStringRef messageToUser = CFSTR("Allow “Emily‘s iPad to use your iCloud Keychain?");
36 #if !TARGET_IPHONE_SIMULATOR
37 #if TARGET_OS_EMBEDDED
38 CFStringRef our_peer_id
= (CFStringRef
)MGCopyAnswer(kMGQUserAssignedDeviceName
, NULL
);
40 CFStringRef our_peer_id
= CFSTR("🔥💩");
43 CFStringRef our_peer_id
= CFSTR("Emily‘s iPad");
46 CFStringRef messageToUser
= CFStringCreateWithFormat(kCFAllocatorDefault
, 0, CFSTR("Allow “%@” to use your iCloud Keychain?"), our_peer_id
);
47 dispatch_queue_t processQueue
= dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT
, 0);
48 dispatch_group_t work_group
= dispatch_group_create();
50 // Prep the group for exitting the whole shebang.
51 dispatch_group_enter(work_group
);
52 dispatch_group_notify(work_group
, processQueue
, ^
54 printf("Exiting via dispatch_group_notify; all work done\n");
55 CFRunLoopStop(CFRunLoopGetMain());
59 SOSCloudKeychainUserNotification(messageToUser
, processQueue
, ^ (CFDictionaryRef returnedValues
, CFErrorRef error
)
62 pass("Reply from SOSCloudKeychainUserNotification: %@", returnedValues
);
63 CFStringRef nfkey
= CFStringCreateWithCString(kCFAllocatorDefault
, kMessageKeyNotificationFlags
, kCFStringEncodingUTF8
);
64 CFTypeRef cfflags
= returnedValues
? CFDictionaryGetValue(returnedValues
, nfkey
) : NULL
;
65 if (cfflags
&& (CFGetTypeID(cfflags
) == CFNumberGetTypeID()))
66 CFNumberGetValue(cfflags
, kCFNumberSInt64Type
, &flags
);
69 // flags is not actually a mask
70 if (flags
== kCFUserNotificationDefaultResponse
)
71 pass("OK button pressed");
73 if (flags
== kCFUserNotificationCancelResponse
)
74 pass("Cancel button pressed");
76 if (flags
== kCFUserNotificationAlternateResponse
)
77 pass("Alternate button pressed");
79 pass("Flags: %#llx", flags
);
81 ok(error
== NULL
, "SOSCloudKeychainPutObjectsInCloud [error: %@:]", error
);
82 dispatch_group_leave(work_group
);
85 pass("Dialog is up for device \"%@\"", our_peer_id
);
86 printf("Dialog is up\n");
87 dispatch_group_wait(work_group
, DISPATCH_TIME_FOREVER
);
88 CFRunLoopRun(); // Wait for it...
89 pass("Exit from run loop");
92 static int kUNTestCount
= 5;
94 int sc_102_cfusernotification(int argc
, char *const *argv
)
96 plan_tests(kUNTestCount
);