4 * Created by Mitch Adler on 1/25/121.
5 * Copyright 2012 Apple Inc. All rights reserved.
10 #include <Security/SecBase.h>
11 #include <Security/SecItem.h>
13 #include <SecureObjectSync/SOSAccount.h>
14 #include <SecureObjectSync/SOSCloudCircle.h>
15 #include <SecureObjectSync/SOSInternal.h>
16 #include <SecureObjectSync/SOSUserKeygen.h>
21 #include "secd_regressions.h"
22 #include "SOSTestDataSource.h"
24 #include "SOSRegressionUtilities.h"
25 #include <utilities/SecCFWrappers.h>
27 #include <securityd/SOSCloudCircleServer.h>
29 #include "SecdTestKeychainUtilities.h"
31 static int kTestTestCount
= 10 + kSecdTestSetupTestCount
;
32 static void tests(void)
34 secd_test_setup_temp_keychain("secd_50_account", ^{
37 CFErrorRef error
= NULL
;
38 CFDataRef cfpassword
= CFDataCreate(NULL
, (uint8_t *) "FooFooFoo", 10);
39 CFStringRef cfaccount
= CFSTR("test@test.org");
41 SOSAccountKeyInterestBlock interest_block
= ^(bool getNewKeysOnly
, CFArrayRef alwaysKeys
, CFArrayRef afterFirstUnlockKeys
, CFArrayRef unlockedKeys
) {};
42 SOSAccountDataUpdateBlock update_block
= ^ bool (CFDictionaryRef keys
, CFErrorRef
*error
) {return true;};
44 SOSDataSourceFactoryRef test_factory
= SOSTestDataSourceFactoryCreate();
45 SOSDataSourceRef test_source
= SOSTestDataSourceCreate();
46 SOSTestDataSourceFactoryAddDataSource(test_factory
, CFSTR("TestType"), test_source
);
48 CFDictionaryRef gestalt
= SOSCreatePeerGestaltFromName(CFSTR("Test Device"));
49 SOSAccountRef account
= SOSAccountCreate(kCFAllocatorDefault
, gestalt
, test_factory
, interest_block
, update_block
);
50 ok(SOSAccountAssertUserCredentials(account
, cfaccount
, cfpassword
, &error
), "Credential setting (%@)", error
);
52 CFReleaseNull(cfpassword
);
54 ok(NULL
!= account
, "Created");
56 ok(1 == SOSAccountCountCircles(account
), "Has one circle");
58 size_t size
= SOSAccountGetDEREncodedSize(account
, &error
);
61 uint8_t* start
= SOSAccountEncodeToDER(account
, &error
, buffer
, buffer
+ sizeof(buffer
));
64 ok(start
, "successful encoding");
65 ok(start
== buffer
, "Used whole buffer");
67 const uint8_t *der
= buffer
;
68 SOSAccountRef inflated
= SOSAccountCreateFromDER(kCFAllocatorDefault
, test_factory
, interest_block
, update_block
,
69 &error
, &der
, buffer
+ sizeof(buffer
));
71 ok(inflated
, "inflated");
72 ok(CFEqual(inflated
, account
), "Compares");
74 CFDictionaryRef new_gestalt
= SOSCreatePeerGestaltFromName(CFSTR("New Device"));
76 ok(SOSAccountResetToOffering(account
, &error
), "Reset to Offering (%@)", error
);
79 is(SOSAccountIsInCircles(account
, &error
), kSOSCCInCircle
, "Was in Circle (%@)", error
);
82 SOSAccountUpdateGestalt(account
, new_gestalt
);
84 is(SOSAccountIsInCircles(account
, &error
), kSOSCCInCircle
, "Still in Circle (%@)", error
);
87 CFReleaseNull(gestalt
);
88 CFReleaseNull(new_gestalt
);
89 CFReleaseNull(account
);
92 int secd_50_account(int argc
, char *const *argv
)
94 plan_tests(kTestTestCount
);