| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_MOCK_KEYCHAIN_MAC_H_ | 5 #ifndef CHROME_BROWSER_MOCK_KEYCHAIN_MAC_H_ |
| 6 #define CHROME_BROWSER_MOCK_KEYCHAIN_MAC_H_ | 6 #define CHROME_BROWSER_MOCK_KEYCHAIN_MAC_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 #include <string> | 10 #include <string> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/compiler_specific.h" |
| 13 #include "chrome/browser/keychain_mac.h" | 14 #include "chrome/browser/keychain_mac.h" |
| 14 | 15 |
| 15 // Mock Keychain wrapper for testing code that interacts with the OS Keychain. | 16 // Mock Keychain wrapper for testing code that interacts with the OS Keychain. |
| 16 // The basic idea of this mock is that it has a static array of data, and | 17 // The basic idea of this mock is that it has a static array of data, and |
| 17 // SecKeychainItemRef values are just indexes into that array (offset by 1 to | 18 // SecKeychainItemRef values are just indexes into that array (offset by 1 to |
| 18 // prevent problems with clients that null-check refs), cast to pointers. | 19 // prevent problems with clients that null-check refs), cast to pointers. |
| 19 // | 20 // |
| 20 // Note that "const" is pretty much meaningless for this class; the const-ness | 21 // Note that "const" is pretty much meaningless for this class; the const-ness |
| 21 // of MacKeychain doesn't apply to the actual keychain data, so all of the Mock | 22 // of MacKeychain doesn't apply to the actual keychain data, so all of the Mock |
| 22 // data is mutable; don't assume that it won't change over the life of tests. | 23 // data is mutable; don't assume that it won't change over the life of tests. |
| 23 class MockKeychain : public MacKeychain { | 24 class MockKeychain : public MacKeychain { |
| 24 public: | 25 public: |
| 25 // Create a Mock Keychain capable of holding item_capacity keychain items. | 26 // Create a Mock Keychain capable of holding item_capacity keychain items. |
| 26 explicit MockKeychain(unsigned int item_capacity); | 27 explicit MockKeychain(unsigned int item_capacity); |
| 27 virtual ~MockKeychain(); | 28 virtual ~MockKeychain(); |
| 28 virtual OSStatus ItemCopyAttributesAndData( | 29 virtual OSStatus ItemCopyAttributesAndData( |
| 29 SecKeychainItemRef itemRef, SecKeychainAttributeInfo *info, | 30 SecKeychainItemRef itemRef, SecKeychainAttributeInfo *info, |
| 30 SecItemClass *itemClass, SecKeychainAttributeList **attrList, | 31 SecItemClass *itemClass, SecKeychainAttributeList **attrList, |
| 31 UInt32 *length, void **outData) const; | 32 UInt32 *length, void **outData) const OVERRIDE; |
| 32 // Pass "fail_me" as the data to get errSecAuthFailed. | 33 // Pass "fail_me" as the data to get errSecAuthFailed. |
| 33 virtual OSStatus ItemModifyAttributesAndData( | 34 virtual OSStatus ItemModifyAttributesAndData( |
| 34 SecKeychainItemRef itemRef, const SecKeychainAttributeList *attrList, | 35 SecKeychainItemRef itemRef, const SecKeychainAttributeList *attrList, |
| 35 UInt32 length, const void *data) const; | 36 UInt32 length, const void *data) const OVERRIDE; |
| 36 virtual OSStatus ItemFreeAttributesAndData(SecKeychainAttributeList *attrList, | 37 virtual OSStatus ItemFreeAttributesAndData(SecKeychainAttributeList *attrList, |
| 37 void *data) const; | 38 void *data) const OVERRIDE; |
| 38 virtual OSStatus ItemDelete(SecKeychainItemRef itemRef) const; | 39 virtual OSStatus ItemDelete(SecKeychainItemRef itemRef) const OVERRIDE; |
| 39 virtual OSStatus SearchCreateFromAttributes( | 40 virtual OSStatus SearchCreateFromAttributes( |
| 40 CFTypeRef keychainOrArray, SecItemClass itemClass, | 41 CFTypeRef keychainOrArray, SecItemClass itemClass, |
| 41 const SecKeychainAttributeList *attrList, | 42 const SecKeychainAttributeList *attrList, |
| 42 SecKeychainSearchRef *searchRef) const; | 43 SecKeychainSearchRef *searchRef) const OVERRIDE; |
| 43 virtual OSStatus SearchCopyNext(SecKeychainSearchRef searchRef, | 44 virtual OSStatus SearchCopyNext(SecKeychainSearchRef searchRef, |
| 44 SecKeychainItemRef *itemRef) const; | 45 SecKeychainItemRef *itemRef) const OVERRIDE; |
| 45 // If there are unused slots in the Mock Keychain's capacity, the new item | 46 // If there are unused slots in the Mock Keychain's capacity, the new item |
| 46 // will use the first free one, otherwise it will stomp the last item. | 47 // will use the first free one, otherwise it will stomp the last item. |
| 47 // Pass "some.domain.com" as the serverName to get errSecDuplicateItem. | 48 // Pass "some.domain.com" as the serverName to get errSecDuplicateItem. |
| 48 virtual OSStatus AddInternetPassword(SecKeychainRef keychain, | 49 virtual OSStatus AddInternetPassword( |
| 49 UInt32 serverNameLength, | 50 SecKeychainRef keychain, |
| 50 const char *serverName, | 51 UInt32 serverNameLength, |
| 51 UInt32 securityDomainLength, | 52 const char *serverName, |
| 52 const char *securityDomain, | 53 UInt32 securityDomainLength, |
| 53 UInt32 accountNameLength, | 54 const char *securityDomain, |
| 54 const char *accountName, | 55 UInt32 accountNameLength, |
| 55 UInt32 pathLength, const char *path, | 56 const char *accountName, |
| 56 UInt16 port, SecProtocolType protocol, | 57 UInt32 pathLength, const char *path, |
| 57 SecAuthenticationType authenticationType, | 58 UInt16 port, SecProtocolType protocol, |
| 58 UInt32 passwordLength, | 59 SecAuthenticationType authenticationType, |
| 59 const void *passwordData, | 60 UInt32 passwordLength, |
| 60 SecKeychainItemRef *itemRef) const; | 61 const void *passwordData, |
| 61 virtual OSStatus FindGenericPassword(CFTypeRef keychainOrArray, | 62 SecKeychainItemRef *itemRef) const OVERRIDE; |
| 62 UInt32 serviceNameLength, | 63 virtual OSStatus FindGenericPassword( |
| 63 const char *serviceName, | 64 CFTypeRef keychainOrArray, |
| 64 UInt32 accountNameLength, | 65 UInt32 serviceNameLength, |
| 65 const char *accountName, | 66 const char *serviceName, |
| 66 UInt32 *passwordLength, | 67 UInt32 accountNameLength, |
| 67 void **passwordData, | 68 const char *accountName, |
| 68 SecKeychainItemRef *itemRef) const; | 69 UInt32 *passwordLength, |
| 70 void **passwordData, |
| 71 SecKeychainItemRef *itemRef) const OVERRIDE; |
| 69 virtual OSStatus ItemFreeContent(SecKeychainAttributeList *attrList, | 72 virtual OSStatus ItemFreeContent(SecKeychainAttributeList *attrList, |
| 70 void *data) const; | 73 void *data) const OVERRIDE; |
| 71 virtual OSStatus AddGenericPassword(SecKeychainRef keychain, | 74 virtual OSStatus AddGenericPassword( |
| 72 UInt32 serviceNameLength, | 75 SecKeychainRef keychain, |
| 73 const char *serviceName, | 76 UInt32 serviceNameLength, |
| 74 UInt32 accountNameLength, | 77 const char *serviceName, |
| 75 const char *accountName, | 78 UInt32 accountNameLength, |
| 76 UInt32 passwordLength, | 79 const char *accountName, |
| 77 const void *passwordData, | 80 UInt32 passwordLength, |
| 78 SecKeychainItemRef *itemRef) const; | 81 const void *passwordData, |
| 79 virtual void Free(CFTypeRef ref) const; | 82 SecKeychainItemRef *itemRef) const OVERRIDE; |
| 83 virtual void Free(CFTypeRef ref) const OVERRIDE; |
| 80 | 84 |
| 81 // Return the counts of objects returned by Create/Copy functions but never | 85 // Return the counts of objects returned by Create/Copy functions but never |
| 82 // Free'd as they should have been. | 86 // Free'd as they should have been. |
| 83 int UnfreedSearchCount() const; | 87 int UnfreedSearchCount() const; |
| 84 int UnfreedKeychainItemCount() const; | 88 int UnfreedKeychainItemCount() const; |
| 85 int UnfreedAttributeDataCount() const; | 89 int UnfreedAttributeDataCount() const; |
| 86 | 90 |
| 87 // Returns true if all items added with AddInternetPassword have a creator | 91 // Returns true if all items added with AddInternetPassword have a creator |
| 88 // code set. | 92 // code set. |
| 89 bool CreatorCodesSetForAddedItems() const; | 93 bool CreatorCodesSetForAddedItems() const; |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 | 188 |
| 185 // Tracks the allocations and frees of password data in |FindGenericPassword| | 189 // Tracks the allocations and frees of password data in |FindGenericPassword| |
| 186 // and |ItemFreeContent|. | 190 // and |ItemFreeContent|. |
| 187 mutable unsigned int password_data_count_; | 191 mutable unsigned int password_data_count_; |
| 188 | 192 |
| 189 // Records the password being set when |AddGenericPassword()| gets called. | 193 // Records the password being set when |AddGenericPassword()| gets called. |
| 190 mutable std::string add_generic_password_; | 194 mutable std::string add_generic_password_; |
| 191 }; | 195 }; |
| 192 | 196 |
| 193 #endif // CHROME_BROWSER_MOCK_KEYCHAIN_MAC_H_ | 197 #endif // CHROME_BROWSER_MOCK_KEYCHAIN_MAC_H_ |
| OLD | NEW |