]> git.saurik.com Git - apple/security.git/blob - keychain/securityd/Regressions/secd-51-account-inflate.m
Security-59754.41.1.tar.gz
[apple/security.git] / keychain / securityd / Regressions / secd-51-account-inflate.m
1 /*
2 * Copyright (c) 2013-2014 Apple Inc. All Rights Reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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
11 * file.
12 *
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.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24
25 #include <Security/SecBase.h>
26 #include <Security/SecItem.h>
27
28 #include "keychain/SecureObjectSync/SOSAccount.h"
29 #include <Security/SecureObjectSync/SOSCloudCircle.h>
30 #include "keychain/SecureObjectSync/SOSInternal.h"
31 #include "keychain/SecureObjectSync/SOSUserKeygen.h"
32 #include "keychain/SecureObjectSync/SOSAccountTrustClassic+Circle.h"
33
34 #include <stdlib.h>
35 #include <unistd.h>
36
37 #include "secd_regressions.h"
38 #include "SOSTestDataSource.h"
39
40 #include "SOSRegressionUtilities.h"
41 #include <utilities/SecCFWrappers.h>
42
43 #include "keychain/securityd/SOSCloudCircleServer.h"
44
45 #include "SecdTestKeychainUtilities.h"
46 #include "SOSAccountTesting.h"
47 #include "SOSTransportTestTransports.h"
48
49 #if SOS_ENABLED
50
51 #define kCompatibilityTestCount 0
52 #if 0
53 static void test_v6(void) {
54 SOSDataSourceFactoryRef ak_factory = SOSTestDataSourceFactoryCreate();
55 SOSDataSourceRef test_source = SOSTestDataSourceCreate();
56 SOSTestDataSourceFactorySetDataSource(ak_factory, CFSTR("ak"), test_source);
57 CFErrorRef error = NULL;
58
59 const uint8_t *der_p = v6_der;
60
61 SOSAccount* convertedAccount = SOSAccountCreateFromDER(kCFAllocatorDefault, ak_factory, &error, &der_p, v6_der + sizeof(v6_der));
62
63 ok(convertedAccount, "inflate v6 account (%@)", error);
64 CFReleaseSafe(error);
65
66 is(kSOSCCInCircle, [convertedAccount.trust getCircleStatus:&error], "in the circle");
67
68 CFReleaseSafe(convertedAccount);
69 ak_factory->release(ak_factory);
70 SOSDataSourceRelease(test_source, NULL);
71 }
72 #endif
73
74 static int kTestTestCount = 11 + kSecdTestSetupTestCount;
75 static void tests(void)
76 {
77
78 CFErrorRef error = NULL;
79 CFDataRef cfpassword = CFDataCreate(NULL, (uint8_t *) "FooFooFoo", 10);
80 CFStringRef cfaccount = CFSTR("test@test.org");
81
82 SOSDataSourceFactoryRef test_factory = SOSTestDataSourceFactoryCreate();
83 SOSDataSourceRef test_source = SOSTestDataSourceCreate();
84 SOSTestDataSourceFactorySetDataSource(test_factory, CFSTR("TestType"), test_source);
85
86 SOSAccount* account = CreateAccountForLocalChanges(CFSTR("Test Device"), CFSTR("TestType"));
87 ok(SOSAccountAssertUserCredentialsAndUpdate(account, cfaccount, cfpassword, &error), "Credential setting (%@)", error);
88 CFReleaseNull(error);
89 CFReleaseNull(cfpassword);
90
91 ok(NULL != account, "Created");
92
93 ok(SOSAccountResetToOffering_wTxn(account, &error), "Reset to offering (%@)", error);
94 CFReleaseNull(error);
95
96 ok(testAccountPersistence(account), "Test Account->DER->Account Equivalence");
97
98 SOSTestCleanup();
99
100 test_factory->release(test_factory);
101 SOSDataSourceRelease(test_source, NULL);
102 }
103
104 #endif
105
106 int secd_51_account_inflate(int argc, char *const *argv)
107 {
108 #if SOS_ENABLED
109 plan_tests(kTestTestCount + kCompatibilityTestCount);
110 secd_test_setup_temp_keychain(__FUNCTION__, NULL);
111 secd_test_clear_testviews();
112 tests();
113 #else
114 plan_tests(0);
115 #endif
116
117 return 0;
118 }