2 // secd-64-circlereset.c
5 // Created by Richard Murphy on 7/22/15.
11 #include <Security/SecBase.h>
12 #include <Security/SecItem.h>
14 #include <CoreFoundation/CFDictionary.h>
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>
25 #include "secd_regressions.h"
26 #include "SOSTestDataSource.h"
28 #include "SOSRegressionUtilities.h"
29 #include <utilities/SecCFWrappers.h>
30 #include <Security/SecKeyPriv.h>
32 #include <securityd/SOSCloudCircleServer.h>
34 #include "SOSAccountTesting.h"
36 #include "SecdTestKeychainUtilities.h"
38 static int kTestTestCount
= 46;
40 static void tests(void)
42 CFErrorRef error
= NULL
;
43 CFDataRef cfpassword
= CFDataCreate(NULL
, (uint8_t *) "FooFooFoo", 10);
44 CFStringRef cfaccount
= CFSTR("test@test.org");
46 CFMutableDictionaryRef changes
= CFDictionaryCreateMutableForCFTypes(kCFAllocatorDefault
);
47 SOSAccountRef alice_account
= CreateAccountForLocalChanges(CFSTR("Alice"), CFSTR("TestSource"));
48 SOSAccountRef bob_account
= CreateAccountForLocalChanges(CFSTR("Bob"), CFSTR("TestSource"));
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
);
55 ok(SOSAccountResetToOffering(alice_account
, &error
), "Reset to offering (%@)", error
);
57 is(ProcessChangesUntilNoChange(changes
, alice_account
, bob_account
, NULL
), 2, "updates");
58 ok(SOSAccountJoinCircles(bob_account
, &error
), "Bob Applies (%@)", error
);
60 is(ProcessChangesUntilNoChange(changes
, alice_account
, bob_account
, NULL
), 2, "updates");
62 CFArrayRef applicants
= SOSAccountCopyApplicants(alice_account
, &error
);
64 ok(applicants
&& CFArrayGetCount(applicants
) == 1, "See one applicant %@ (%@)", applicants
, error
);
65 ok(SOSAccountAcceptApplicants(alice_account
, applicants
, &error
), "Alice accepts (%@)", error
);
67 CFReleaseNull(applicants
);
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
);
75 ok(SOSAccountResetToEmpty(alice_account
, &error
), "Alice resets the circle to empty");
77 is(ProcessChangesUntilNoChange(changes
, alice_account
, bob_account
, NULL
), 2, "updates");
78 CFReleaseNull(bob_account
);
79 CFReleaseNull(alice_account
);
80 CFReleaseNull(cfpassword
);
82 SOSUnregisterAllTransportMessages();
83 SOSUnregisterAllTransportCircles();
84 SOSUnregisterAllTransportKeyParameters();
85 CFArrayRemoveAllValues(key_transports
);
86 CFArrayRemoveAllValues(circle_transports
);
87 CFArrayRemoveAllValues(message_transports
);
91 int secd_64_circlereset(int argc
, char *const *argv
)
93 plan_tests(kTestTestCount
);
95 secd_test_setup_temp_keychain(__FUNCTION__
, NULL
);