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_METHOD1(AsyncTpmAttestationCreateEnrollRequest,
     52                void(const DataCallback& callback));
     53   MOCK_METHOD2(AsyncTpmAttestationEnroll,
     54                void(const std::string& pca_response, const Callback& callback));
     55   MOCK_METHOD4(
     56       AsyncTpmAttestationCreateCertRequest,
     57       void(chromeos::attestation::AttestationCertificateProfile profile,
     58            const std::string& user_id,
     59            const std::string& request_origin,
     60            const DataCallback& callback));
     61   MOCK_METHOD5(AsyncTpmAttestationFinishCertRequest,
     62                void(const std::string& pca_response,
     63                     chromeos::attestation::AttestationKeyType key_type,
     64                     const std::string& user_id,
     65                     const std::string& key_name,
     66                     const DataCallback& callback));
     67   MOCK_METHOD4(TpmAttestationRegisterKey,
     68                void(chromeos::attestation::AttestationKeyType key_type,
     69                     const std::string& user_id,
     70                     const std::string& key_name,
     71                     const Callback& callback));
     72   MOCK_METHOD8(
     73       TpmAttestationSignEnterpriseChallenge,
     74       void(chromeos::attestation::AttestationKeyType key_type,
     75            const std::string& user_id,
     76            const std::string& key_name,
     77            const std::string& domain,
     78            const std::string& device_id,
     79            chromeos::attestation::AttestationChallengeOptions options,
     80            const std::string& challenge,
     81            const DataCallback& callback));
     82   MOCK_METHOD5(TpmAttestationSignSimpleChallenge,
     83                void(chromeos::attestation::AttestationKeyType key_type,
     84                     const std::string& user_id,
     85                     const std::string& key_name,
     86                     const std::string& challenge,
     87                     const DataCallback& callback));
     88   MOCK_METHOD2(AsyncGetSanitizedUsername,
     89                void(const std::string& user,
     90                     const DataCallback& callback));
     91 
     92  private:
     93   bool success_;
     94   MountError return_code_;
     95 
     96   void DoCallback(Callback callback);
     97   // Default fakes for attestation calls.
     98   void FakeCreateEnrollRequest(const DataCallback& callback);
     99   void FakeCreateCertRequest(const DataCallback& callback);
    100   void FakeFinishCertRequest(const DataCallback& callback);
    101   void FakeGetSanitizedUsername(const DataCallback& callback);
    102   void FakeEnterpriseChallenge(const DataCallback& callback);
    103 
    104   DISALLOW_COPY_AND_ASSIGN(MockAsyncMethodCaller);
    105 };
    106 
    107 }  // namespace cryptohome
    108 
    109 #endif  // CHROMEOS_CRYPTOHOME_MOCK_ASYNC_METHOD_CALLER_H_
    110