2 * Copyright (c) 2012-2014 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
26 #include <Security/SecBase.h>
27 #include <Security/SecItem.h>
29 #include <SecureObjectSync/SOSAccount.h>
30 #include <SecureObjectSync/SOSCloudCircle.h>
31 #include <SecureObjectSync/SOSInternal.h>
32 #include <SecureObjectSync/SOSUserKeygen.h>
36 #include "secd_regressions.h"
37 #include "SOSTestDataSource.h"
39 #include "SOSRegressionUtilities.h"
40 #include <utilities/SecCFWrappers.h>
42 #include <securityd/SOSCloudCircleServer.h>
43 #include "SecdTestKeychainUtilities.h"
44 #include "SOSAccountTesting.h"
46 static int kTestTestCount
= 10 + kSecdTestSetupTestCount
;
47 static void tests(void)
49 secd_test_setup_temp_keychain("secd_50_account", ^{
52 CFErrorRef error
= NULL
;
53 CFDataRef cfpassword
= CFDataCreate(NULL
, (uint8_t *) "FooFooFoo", 10);
54 CFStringRef cfaccount
= CFSTR("test@test.org");
56 SOSDataSourceFactoryRef test_factory
= SOSTestDataSourceFactoryCreate();
57 SOSDataSourceRef test_source
= SOSTestDataSourceCreate();
58 SOSTestDataSourceFactoryAddDataSource(test_factory
, CFSTR("TestType"), test_source
);
60 SOSAccountRef account
= CreateAccountForLocalChanges(CFSTR("Test Device"),CFSTR("TestType") );
62 ok(SOSAccountAssertUserCredentials(account
, cfaccount
, cfpassword
, &error
), "Credential setting (%@)", error
);
64 CFReleaseNull(cfpassword
);
66 ok(NULL
!= account
, "Created");
68 ok(1 == SOSAccountCountCircles(account
), "Has one circle");
70 size_t size
= SOSAccountGetDEREncodedSize(account
, &error
);
73 uint8_t* start
= SOSAccountEncodeToDER(account
, &error
, buffer
, buffer
+ sizeof(buffer
));
76 ok(start
, "successful encoding");
77 ok(start
== buffer
, "Used whole buffer");
79 const uint8_t *der
= buffer
;
80 SOSAccountRef inflated
= SOSAccountCreateFromDER(kCFAllocatorDefault
, test_factory
,
81 &error
, &der
, buffer
+ sizeof(buffer
));
83 SOSAccountEnsureFactoryCirclesTest(inflated
, CFSTR("Test Device"));
84 ok(inflated
, "inflated");
85 ok(CFEqual(inflated
, account
), "Compares");
87 CFDictionaryRef new_gestalt
= SOSCreatePeerGestaltFromName(CFSTR("New Device"));
88 ok(SOSAccountResetToOffering(account
, &error
), "Reset to Offering (%@)", error
);
90 is(SOSAccountIsInCircles(account
, &error
), kSOSCCInCircle
, "Was in Circle (%@)", error
);
93 SOSAccountUpdateGestalt(account
, new_gestalt
);
95 is(SOSAccountIsInCircles(account
, &error
), kSOSCCInCircle
, "Still in Circle (%@)", error
);
98 CFReleaseNull(new_gestalt
);
99 CFReleaseNull(account
);
101 SOSUnregisterAllTransportMessages();
102 SOSUnregisterAllTransportCircles();
103 SOSUnregisterAllTransportKeyParameters();
105 CFArrayRemoveAllValues(key_transports
);
106 CFArrayRemoveAllValues(circle_transports
);
107 CFArrayRemoveAllValues(message_transports
);
111 int secd_50_account(int argc
, char *const *argv
)
113 plan_tests(kTestTestCount
);