6 #import <Foundation/Foundation.h>
8 #include <Security/SecBase.h>
9 #include <Security/SecItem.h>
11 #include <CoreFoundation/CFDictionary.h>
15 #include "secd_regressions.h"
16 #include <utilities/SecCFWrappers.h>
18 #include <securityd/SOSCloudCircleServer.h>
20 #include "SOSAccountTesting.h"
22 #include "SecdTestKeychainUtilities.h"
24 static int kTestTestCount = 3;
27 static void testPeerRateLimiterSendNextMessageWithRetain(CFStringRef peerid, CFStringRef accessGroup)
29 ok(CFStringCompare(peerid, CFSTR("imretainedpeerid"), 0) == kCFCompareEqualTo);
32 static void testOTRTimer()
34 dispatch_semaphore_t sema2 = dispatch_semaphore_create(0);
36 CFStringRef peeridRetained = CFRetainSafe(CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%@"), CFSTR("imretainedpeerid")));
37 dispatch_queue_t test_queue2 = dispatch_queue_create("com.apple.security.keychain-otrtimer2", DISPATCH_QUEUE_SERIAL);
38 __block dispatch_source_t timer2 = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, test_queue2);
40 dispatch_source_set_timer(timer2, dispatch_time(DISPATCH_TIME_NOW, 5 * NSEC_PER_SEC), DISPATCH_TIME_FOREVER, 0);
41 dispatch_source_set_event_handler(timer2, ^{
42 testPeerRateLimiterSendNextMessageWithRetain(peeridRetained, CFSTR("NoAttribute"));
43 dispatch_semaphore_signal(sema2);
45 dispatch_resume(timer2);
46 dispatch_source_set_cancel_handler(timer2, ^{
47 CFReleaseSafe(peeridRetained);
50 CFReleaseNull(peeridRetained);
51 dispatch_semaphore_wait(sema2, DISPATCH_TIME_FOREVER);
55 static void testOTRTimerWithRetain(CFStringRef peerid)
57 ok(CFStringCompare(peerid, CFSTR("imretainedpeerid"), 0) == kCFCompareEqualTo);
60 static void testRateLimitingTimer()
63 dispatch_semaphore_t sema2 = dispatch_semaphore_create(0);
65 CFStringRef peeridRetained = CFRetainSafe(CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%@"), CFSTR("imretainedpeerid")));
67 dispatch_queue_t test_queue2 = dispatch_queue_create("com.apple.security.keychain-ratelimit12", DISPATCH_QUEUE_SERIAL);
68 __block dispatch_source_t timer2 = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, test_queue2);
70 dispatch_source_set_timer(timer2, dispatch_time(DISPATCH_TIME_NOW, 5 * NSEC_PER_SEC), DISPATCH_TIME_FOREVER, 0);
71 dispatch_source_set_event_handler(timer2, ^{
72 testOTRTimerWithRetain(peeridRetained);
73 dispatch_semaphore_signal(sema2);
75 dispatch_resume(timer2);
77 dispatch_source_set_cancel_handler(timer2, ^{
78 CFReleaseSafe(peeridRetained);
81 CFReleaseNull(peeridRetained);
82 dispatch_semaphore_wait(sema2, DISPATCH_TIME_FOREVER);
88 testRateLimitingTimer();
91 int secd_156_timers(int argc, char *const *argv)
93 plan_tests(kTestTestCount);
95 secd_test_setup_temp_keychain(__FUNCTION__, NULL);