kc-16-item-update-password.c [plain text]
#import <Security/Security.h>
#import <Security/SecCertificatePriv.h>
#include "keychain_regressions.h"
#include "kc-helpers.h"
#include "kc-item-helpers.h"
static void tests()
{
SecKeychainRef kc = getPopulatedTestKeychain();
CFMutableDictionaryRef query = NULL;
SecKeychainItemRef item = NULL;
query = createQueryCustomItemDictionaryWithService(kc, kSecClassInternetPassword, CFSTR("test_service"), CFSTR("test_service"));
item = checkNCopyFirst(testName, query, 1);
readPasswordContents(item, CFSTR("test_password")); checkPrompts(0, "after reading a password");
changePasswordContents(item, CFSTR("new_password")); checkPrompts(0, "changing a internet password");
readPasswordContents(item, CFSTR("new_password")); checkPrompts(0, "reading a changed internet password");
CFReleaseNull(item);
query = createQueryCustomItemDictionaryWithService(kc, kSecClassInternetPassword, CFSTR("test_service_restrictive_acl"), CFSTR("test_service_restrictive_acl"));
item = checkNCopyFirst(testName, query, 1);
readPasswordContentsWithResult(item, errSecAuthFailed, NULL); checkPrompts(1, "trying to read internet password without access");
changePasswordContents(item, CFSTR("new_password"));
checkPrompts(0, "after changing a internet password without access"); readPasswordContentsWithResult(item, errSecAuthFailed, NULL); checkPrompts(1, "after changing a internet password without access");
CFReleaseNull(item);
query = createQueryCustomItemDictionaryWithService(kc, kSecClassGenericPassword, CFSTR("test_service"), CFSTR("test_service"));
item = checkNCopyFirst(testName, query, 1);
readPasswordContents(item, CFSTR("test_password")); checkPrompts(0, "after reading a generic password");
changePasswordContents(item, CFSTR("new_password")); checkPrompts(0, "changing a generic password");
readPasswordContents(item, CFSTR("new_password")); checkPrompts(0, "after changing a generic password");
CFReleaseNull(item);
query = createQueryCustomItemDictionaryWithService(kc, kSecClassGenericPassword, CFSTR("test_service_restrictive_acl"), CFSTR("test_service_restrictive_acl"));
item = checkNCopyFirst(testName, query, 1);
readPasswordContentsWithResult(item, errSecAuthFailed, NULL); checkPrompts(1, "trying to read generic password without access");
changePasswordContents(item, CFSTR("new_password"));
checkPrompts(0, "changing a generic password without access"); readPasswordContentsWithResult(item, errSecAuthFailed, NULL); checkPrompts(1, "after changing a generic password without access");
CFReleaseNull(item);
ok_status(SecKeychainDelete(kc), "%s: SecKeychainDelete", testName);
CFReleaseNull(kc);
}
#define numTests (getPopulatedTestKeychainTests + \
checkNTests + readPasswordContentsTests + checkPromptsTests + changePasswordContentsTests + checkPromptsTests + readPasswordContentsTests + checkPromptsTests + \
checkNTests + readPasswordContentsTests + checkPromptsTests + changePasswordContentsTests + checkPromptsTests + readPasswordContentsTests + checkPromptsTests + \
checkNTests + readPasswordContentsTests + checkPromptsTests + changePasswordContentsTests + checkPromptsTests + readPasswordContentsTests + checkPromptsTests + \
checkNTests + readPasswordContentsTests + checkPromptsTests + changePasswordContentsTests + checkPromptsTests + readPasswordContentsTests + checkPromptsTests + \
+ 1)
int kc_16_item_update_password(int argc, char *const *argv)
{
plan_tests(numTests);
initializeKeychainTests(__FUNCTION__);
tests();
deleteTestFiles();
return 0;
}