Home | History | Annotate | Download | only in cryptohome
      1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef CHROMEOS_CRYPTOHOME_MOCK_ASYNC_METHOD_CALLER_H_
      6 #define CHROMEOS_CRYPTOHOME_MOCK_ASYNC_METHOD_CALLER_H_
      7 
      8 #include <string>
      9 
     10 #include "base/basictypes.h"
     11 #include "base/callback.h"
     12 #include "chromeos/cryptohome/async_method_caller.h"
     13 #include "testing/gmock/include/gmock/gmock.h"
     14 
     15 namespace cryptohome {
     16 
     17 class MockAsyncMethodCaller : public AsyncMethodCaller {
     18  public:
     19   static const char kFakeAttestationEnrollRequest[];
     20   static const char kFakeAttestationCertRequest[];
     21   static const char kFakeAttestationCert[];
     22   static const char kFakeSanitizedUsername[];
     23   static const char kFakeChallengeResponse[];
     24 
     25   MockAsyncMethodCaller();
     26   virtual ~MockAsyncMethodCaller();
     27 
     28   void SetUp(bool success, MountError return_code);
     29 
     30   MOCK_METHOD3(AsyncCheckKey, void(const std::string& user_email,
     31                                    const std::string& passhash,
     32                                    Callback callback));
     33   MOCK_METHOD4(AsyncMigrateKey, void(const std::string& user_email,
     34                                      const std::string& old_hash,
     35                                      const std::string& new_hash,
     36                                      Callback callback));
     37   MOCK_METHOD4(AsyncMount, void(const std::string& user_email,
     38                                 const std::string& passhash,
     39                                 int flags,
     40                                 Callback callback));
     41   MOCK_METHOD4(AsyncAddKey, void(const std::string& user_email,
     42                                  const std::string& passhash,
     43                                  const std::string& new_key,
     44                                  Callback callback));
     45   MOCK_METHOD1(AsyncMountGuest, void(Callback callback));
     46   MOCK_METHOD3(AsyncMountPublic, void(const std::string& public_mount_id,
     47                                       int flags,
     48                                       Callback callback));
     49   MOCK_METHOD2(AsyncRemove, void(const std::string& user_email,
     50                                  Callback callback));
     51   MOCK_METHOD2(AsyncTpmAttestationCreateEnrollRequest,
     52                void(chromeos::attestation::PrivacyCAType pca_type,
     53                     const DataCallback& callback));
     54   MOCK_METHOD3(AsyncTpmAttestationEnroll,
     55                void(chromeos::attestation::PrivacyCAType pca_type,
     56                     const std::string& pca_response,
     57                     const Callback& callback));
     58   MOCK_METHOD5(
     59       AsyncTpmAttestationCreateCertRequest,
     60       void(chromeos::attestation::PrivacyCAType pca_type,
     61            chromeos::attestation::AttestationCertificateProfile profile,
     62            const std::string& user_id,
     63            const std::string& request_origin,
     64            const DataCallback& callback));
     65   MOCK_METHOD5(AsyncTpmAttestationFinishCertRequest,
     66                void(const std::string& pca_response,
     67                     chromeos::attestation::AttestationKeyType key_type,
     68                     const std::string& user_id,
     69                     const std::string& key_name,
     70                     const DataCallback& callback));
     71   MOCK_METHOD4(TpmAttestationRegisterKey,
     72                void(chromeos::attestation::AttestationKeyType key_type,
     73                     const std::string& user_id,
     74                     const std::string& key_name,
     75                     const Callback& callback));
     76   MOCK_METHOD8(
     77       TpmAttestationSignEnterpriseChallenge,
     78       void(chromeos::attestation::AttestationKeyType key_type,
     79            const std::string& user_id,
     80            const std::string& key_name,
     81            const std::string& domain,
     82            const std::string& device_id,
     83            chromeos::attestation::AttestationChallengeOptions options,
     84            const std::string& challenge,
     85            const DataCallback& callback));
     86   MOCK_METHOD5(TpmAttestationSignSimpleChallenge,
     87                void(chromeos::attestation::AttestationKeyType key_type,
     88                     const std::string& user_id,
     89                     const std::string& key_name,
     90                     const std::string& challenge,
     91                     const DataCallback& callback));
     92   MOCK_METHOD2(AsyncGetSanitizedUsername,
     93                void(const std::string& user,
     94                     const DataCallback& callback));
     95 
     96  private:
     97   bool success_;
     98   MountError return_code_;
     99 
    100   void DoCallback(Callback callback);
    101   // Default fakes for attestation calls.
    102   void FakeCreateEnrollRequest(const DataCallback& callback);
    103   void FakeCreateCertRequest(const DataCallback& callback);
    104   void FakeFinishCertRequest(const DataCallback& callback);
    105   void FakeGetSanitizedUsername(const DataCallback& callback);
    106   void FakeEnterpriseChallenge(const DataCallback& callback);
    107 
    108   DISALLOW_COPY_AND_ASSIGN(MockAsyncMethodCaller);
    109 };
    110 
    111 }  // namespace cryptohome
    112 
    113 #endif  // CHROMEOS_CRYPTOHOME_MOCK_ASYNC_METHOD_CALLER_H_
    114