]> git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_keychain/regressions/kc-45-change-password.c
Security-59306.11.20.tar.gz
[apple/security.git] / OSX / libsecurity_keychain / regressions / kc-45-change-password.c
1 #include <Security/SecKeychain.h>
2 #include <Security/SecKeychainPriv.h>
3
4 #include "keychain_regressions.h"
5 #include "kc-helpers.h"
6
7 int kc_45_change_password(int argc, char *const *argv)
8 {
9 plan_tests(16);
10
11 initializeKeychainTests(__FUNCTION__);
12
13 ok_status(SecKeychainSetUserInteractionAllowed(FALSE), "SecKeychainSetUserInteractionAllowed(FALSE)");
14
15 SecKeychainRef keychain = createNewKeychain("test", "before");
16 ok_status(SecKeychainLock(keychain), "SecKeychainLock");
17 is_status(SecKeychainChangePassword(keychain, 0, NULL, 5, "after"), errSecInteractionNotAllowed, "Change PW w/ null pw while locked"); // We're not responding to prompt so we can't do stuff while locked
18 checkPrompts(1, "Prompt to unlock keychain before password change");
19 is_status(SecKeychainChangePassword(keychain, 5, "badpw", 5, "after"), errSecAuthFailed, "Change PW w/ bad pw while locked");
20 ok_status(SecKeychainUnlock(keychain, 6, "before", true), "SecKeychainUnlock");
21 is_status(SecKeychainChangePassword(keychain, 0, NULL, 5, "after"), errSecAuthFailed, "Change PW w/ null pw while unlocked");
22 is_status(SecKeychainChangePassword(keychain, 5, "badpw", 5, "after"), errSecAuthFailed, "Change PW w/ bad pw while unlocked");
23 ok_status(SecKeychainChangePassword(keychain, 6, "before", 7, "between"), "Change PW w/ good pw while unlocked");
24 ok_status(SecKeychainLock(keychain), "SecKeychainLock");
25 ok_status(SecKeychainChangePassword(keychain, 7, "between", 7, "after"), "Change PW w/ good pw while locked");
26 checkPrompts(0, "Unexpected keychain access prompt");
27
28 ok_status(SecKeychainDelete(keychain), "%s: SecKeychainDelete", testName);
29 CFRelease(keychain);
30
31 deleteTestFiles();
32 return 0;
33 }