secd-100-initialsync.c [plain text]
#include <Security/SecBase.h>
#include <Security/SecItem.h>
#include <CoreFoundation/CFDictionary.h>
#include <Security/SecureObjectSync/SOSAccount.h>
#include <Security/SecureObjectSync/SOSCloudCircle.h>
#include <Security/SecureObjectSync/SOSInternal.h>
#include <Security/SecureObjectSync/SOSUserKeygen.h>
#include <Security/SecureObjectSync/SOSTransport.h>
#include <stdlib.h>
#include <unistd.h>
#include "secd_regressions.h"
#include <utilities/SecCFWrappers.h>
#include <Security/SecKeyPriv.h>
#include <securityd/SOSCloudCircleServer.h>
#include "SOSAccountTesting.h"
#include "SecdTestKeychainUtilities.h"
static int kTestTestCount = 43;
static void tests(void)
{
CFErrorRef error = NULL;
CFDataRef cfpassword = CFDataCreate(NULL, (uint8_t *) "FooFooFoo", 10);
CFStringRef cfaccount = CFSTR("test@test.org");
CFMutableDictionaryRef changes = CFDictionaryCreateMutableForCFTypes(kCFAllocatorDefault);
SOSDataSourceFactoryRef test_factory = SOSTestDataSourceFactoryCreate();
SOSDataSourceRef test_source = SOSTestDataSourceCreate();
SOSTestDataSourceFactorySetDataSource(test_factory, CFSTR("TestType"), test_source);
SOSAccountRef alice_account = CreateAccountForLocalChanges(CFSTR("AliceAccount"),CFSTR("TestType") );
SOSAccountRef bob_account = CreateAccountForLocalChanges(CFSTR("BobAccount"),CFSTR("TestType") );
ok(SOSAccountAssertUserCredentialsAndUpdate(alice_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
ok(SOSAccountJoinCircles_wTxn(alice_account, &error), "Join circle: %@", error);
ok(SOSAccountCheckHasBeenInSync_wTxn(alice_account), "Alice account initial sync done");
ok(SOSAccountAssertUserCredentialsAndUpdate(bob_account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
CFReleaseNull(error);
CFReleaseNull(cfpassword);
is(ProcessChangesUntilNoChange(changes, alice_account, bob_account, NULL), 1, "updates");
ok(SOSAccountJoinCircles_wTxn(bob_account, &error), "Bob Applies (%@)", error);
CFReleaseNull(error);
is(ProcessChangesUntilNoChange(changes, alice_account, bob_account, NULL), 4, "updates");
{
CFArrayRef applicants = SOSAccountCopyApplicants(alice_account, &error);
ok(applicants && CFArrayGetCount(applicants) == 1, "See one applicant %@ (%@)", applicants, error);
ok(SOSAccountAcceptApplicants(alice_account, applicants, &error), "Alice accepts (%@)", error);
CFReleaseNull(error);
CFReleaseNull(applicants);
}
is(ProcessChangesUntilNoChange(changes, alice_account, bob_account, NULL), 3, "updates");
accounts_agree("bob&alice pair", bob_account, alice_account);
ok(!SOSAccountCheckHasBeenInSync_wTxn(bob_account), "Bob should not be initially synced");
CFSetRef bob_viewSet = SOSPeerInfoCopyEnabledViews(SOSAccountGetMyPeerInfo(bob_account));
is(CFSetGetCount(bob_viewSet), 5, "bob's initial view set should be just the 14 views");
CFReleaseNull(bob_viewSet);
ok(!SOSAccountCheckHasBeenInSync_wTxn(bob_account), "Bob should not be initially synced");
SOSAccountPeerGotInSync_wTxn(bob_account, SOSAccountGetMyPeerInfo(alice_account));
bob_viewSet = SOSPeerInfoCopyEnabledViews(SOSAccountGetMyPeerInfo(bob_account));
is(CFSetGetCount(bob_viewSet), 18, "bob's initial view set should be just the back up");
CFReleaseNull(bob_viewSet);
}
int secd_100_initialsync(int argc, char *const *argv)
{
plan_tests(kTestTestCount);
secd_test_setup_temp_keychain(__FUNCTION__, NULL);
tests();
return 0;
}