]> git.saurik.com Git - apple/security.git/blob - OSX/sec/securityd/Regressions/secd-156-timers.m
Security-58286.200.222.tar.gz
[apple/security.git] / OSX / sec / securityd / Regressions / secd-156-timers.m
1 //
2 // secd-156-timers.m
3 // secdRegressions
4 //
5
6 #import <Foundation/Foundation.h>
7
8 #include <Security/SecBase.h>
9 #include <Security/SecItem.h>
10
11 #include <CoreFoundation/CFDictionary.h>
12 #include <stdlib.h>
13 #include <unistd.h>
14
15 #include "secd_regressions.h"
16 #include <utilities/SecCFWrappers.h>
17
18 #include <securityd/SOSCloudCircleServer.h>
19
20 #include "SOSAccountTesting.h"
21
22 #include "SecdTestKeychainUtilities.h"
23
24 static int kTestTestCount = 3;
25
26
27 static void testPeerRateLimiterSendNextMessageWithRetain(CFStringRef peerid, CFStringRef accessGroup)
28 {
29 ok(CFStringCompare(peerid, CFSTR("imretainedpeerid"), 0) == kCFCompareEqualTo);
30 }
31
32 static void testOTRTimer()
33 {
34 dispatch_semaphore_t sema2 = dispatch_semaphore_create(0);
35
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);
39
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);
44 });
45 dispatch_resume(timer2);
46 dispatch_source_set_cancel_handler(timer2, ^{
47 CFReleaseSafe(peeridRetained);
48 });
49
50 CFReleaseNull(peeridRetained);
51 dispatch_semaphore_wait(sema2, DISPATCH_TIME_FOREVER);
52
53 }
54
55 static void testOTRTimerWithRetain(CFStringRef peerid)
56 {
57 ok(CFStringCompare(peerid, CFSTR("imretainedpeerid"), 0) == kCFCompareEqualTo);
58 }
59
60 static void testRateLimitingTimer()
61
62 {
63 dispatch_semaphore_t sema2 = dispatch_semaphore_create(0);
64
65 CFStringRef peeridRetained = CFRetainSafe(CFStringCreateWithFormat(kCFAllocatorDefault, NULL, CFSTR("%@"), CFSTR("imretainedpeerid")));
66
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);
69
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);
74 });
75 dispatch_resume(timer2);
76
77 dispatch_source_set_cancel_handler(timer2, ^{
78 CFReleaseSafe(peeridRetained);
79 });
80
81 CFReleaseNull(peeridRetained);
82 dispatch_semaphore_wait(sema2, DISPATCH_TIME_FOREVER);
83
84 }
85 static void tests(){
86
87 testOTRTimer();
88 testRateLimitingTimer();
89 }
90
91 int secd_156_timers(int argc, char *const *argv)
92 {
93 plan_tests(kTestTestCount);
94
95 secd_test_setup_temp_keychain(__FUNCTION__, NULL);
96
97 tests();
98
99 return 0;
100 }