]> git.saurik.com Git - apple/security.git/blob - OSX/sec/securityd/Regressions/secd-64-circlereset.c
Security-57337.40.85.tar.gz
[apple/security.git] / OSX / sec / securityd / Regressions / secd-64-circlereset.c
1 //
2 // secd-64-circlereset.c
3 // sec
4 //
5 // Created by Richard Murphy on 7/22/15.
6 //
7 //
8
9
10
11 #include <Security/SecBase.h>
12 #include <Security/SecItem.h>
13
14 #include <CoreFoundation/CFDictionary.h>
15
16 #include <Security/SecureObjectSync/SOSAccount.h>
17 #include <Security/SecureObjectSync/SOSCloudCircle.h>
18 #include <Security/SecureObjectSync/SOSInternal.h>
19 #include <Security/SecureObjectSync/SOSUserKeygen.h>
20 #include <Security/SecureObjectSync/SOSTransport.h>
21
22 #include <stdlib.h>
23 #include <unistd.h>
24
25 #include "secd_regressions.h"
26 #include "SOSTestDataSource.h"
27
28 #include "SOSRegressionUtilities.h"
29 #include <utilities/SecCFWrappers.h>
30 #include <Security/SecKeyPriv.h>
31
32 #include <securityd/SOSCloudCircleServer.h>
33
34 #include "SOSAccountTesting.h"
35
36 #include "SecdTestKeychainUtilities.h"
37
38 static int kTestTestCount = 46;
39
40 static void tests(void)
41 {
42 CFErrorRef error = NULL;
43 CFDataRef cfpassword = CFDataCreate(NULL, (uint8_t *) "FooFooFoo", 10);
44 CFStringRef cfaccount = CFSTR("test@test.org");
45
46 CFMutableDictionaryRef changes = CFDictionaryCreateMutableForCFTypes(kCFAllocatorDefault);
47 SOSAccountRef alice_account = CreateAccountForLocalChanges(CFSTR("Alice"), CFSTR("TestSource"));
48 SOSAccountRef bob_account = CreateAccountForLocalChanges(CFSTR("Bob"), CFSTR("TestSource"));
49
50 // Setup Circle with Bob and Alice in it
51 ok(SOSAccountAssertUserCredentialsAndUpdate(bob_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
52 is(ProcessChangesUntilNoChange(changes, alice_account, bob_account, NULL), 1, "updates");
53 ok(SOSAccountAssertUserCredentialsAndUpdate(alice_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
54 CFReleaseNull(error);
55 ok(SOSAccountResetToOffering(alice_account, &error), "Reset to offering (%@)", error);
56 CFReleaseNull(error);
57 is(ProcessChangesUntilNoChange(changes, alice_account, bob_account, NULL), 2, "updates");
58 ok(SOSAccountJoinCircles(bob_account, &error), "Bob Applies (%@)", error);
59 CFReleaseNull(error);
60 is(ProcessChangesUntilNoChange(changes, alice_account, bob_account, NULL), 2, "updates");
61 {
62 CFArrayRef applicants = SOSAccountCopyApplicants(alice_account, &error);
63
64 ok(applicants && CFArrayGetCount(applicants) == 1, "See one applicant %@ (%@)", applicants, error);
65 ok(SOSAccountAcceptApplicants(alice_account, applicants, &error), "Alice accepts (%@)", error);
66 CFReleaseNull(error);
67 CFReleaseNull(applicants);
68 }
69 is(ProcessChangesUntilNoChange(changes, alice_account, bob_account, NULL), 3, "updates");
70 accounts_agree("bob&alice pair", bob_account, alice_account);
71 CFArrayRef peers = SOSAccountCopyPeers(alice_account, &error);
72 ok(peers && CFArrayGetCount(peers) == 2, "See two peers %@ (%@)", peers, error);
73 CFReleaseNull(peers);
74
75 ok(SOSAccountResetToEmpty(alice_account, &error), "Alice resets the circle to empty");
76 CFReleaseNull(error);
77 is(ProcessChangesUntilNoChange(changes, alice_account, bob_account, NULL), 2, "updates");
78 CFReleaseNull(bob_account);
79 CFReleaseNull(alice_account);
80 CFReleaseNull(cfpassword);
81
82 SOSUnregisterAllTransportMessages();
83 SOSUnregisterAllTransportCircles();
84 SOSUnregisterAllTransportKeyParameters();
85 CFArrayRemoveAllValues(key_transports);
86 CFArrayRemoveAllValues(circle_transports);
87 CFArrayRemoveAllValues(message_transports);
88
89 }
90
91 int secd_64_circlereset(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 }