OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include "base/bind.h" | 5 #include "base/bind.h" |
6 #include "net/base/net_errors.h" | 6 #include "net/base/net_errors.h" |
7 #include "remoting/base/rsa_key_pair.h" | 7 #include "remoting/base/rsa_key_pair.h" |
8 #include "remoting/protocol/authenticator_test_base.h" | 8 #include "remoting/protocol/authenticator_test_base.h" |
9 #include "remoting/protocol/channel_authenticator.h" | 9 #include "remoting/protocol/channel_authenticator.h" |
10 #include "remoting/protocol/connection_tester.h" | 10 #include "remoting/protocol/connection_tester.h" |
11 #include "remoting/protocol/fake_authenticator.h" | 11 #include "remoting/protocol/fake_authenticator.h" |
12 #include "remoting/protocol/third_party_authenticator_base.h" | 12 #include "remoting/protocol/third_party_authenticator_base.h" |
13 #include "remoting/protocol/third_party_client_authenticator.h" | 13 #include "remoting/protocol/third_party_client_authenticator.h" |
14 #include "remoting/protocol/third_party_host_authenticator.h" | 14 #include "remoting/protocol/third_party_host_authenticator.h" |
| 15 #include "remoting/protocol/token_validator.h" |
15 #include "testing/gmock/include/gmock/gmock.h" | 16 #include "testing/gmock/include/gmock/gmock.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
17 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" | 18 #include "third_party/libjingle/source/talk/xmllite/xmlelement.h" |
18 | 19 |
19 using testing::_; | 20 using testing::_; |
20 using testing::DeleteArg; | 21 using testing::DeleteArg; |
21 using testing::SaveArg; | 22 using testing::SaveArg; |
22 | 23 |
23 namespace { | 24 namespace { |
24 | 25 |
(...skipping 29 matching lines...) Expand all Loading... |
54 ASSERT_FALSE(on_token_fetched_.is_null()); | 55 ASSERT_FALSE(on_token_fetched_.is_null()); |
55 TokenFetchedCallback on_token_fetched = on_token_fetched_; | 56 TokenFetchedCallback on_token_fetched = on_token_fetched_; |
56 on_token_fetched_.Reset(); | 57 on_token_fetched_.Reset(); |
57 on_token_fetched.Run(token, shared_secret); | 58 on_token_fetched.Run(token, shared_secret); |
58 } | 59 } |
59 | 60 |
60 private: | 61 private: |
61 TokenFetchedCallback on_token_fetched_; | 62 TokenFetchedCallback on_token_fetched_; |
62 }; | 63 }; |
63 | 64 |
64 class FakeTokenValidator | 65 class FakeTokenValidator : public TokenValidator { |
65 : public ThirdPartyHostAuthenticator::TokenValidator { | |
66 public: | 66 public: |
67 FakeTokenValidator() | 67 FakeTokenValidator() |
68 : token_url_(kTokenUrl), | 68 : token_url_(kTokenUrl), |
69 token_scope_(kTokenScope) {} | 69 token_scope_(kTokenScope) {} |
70 | 70 |
71 virtual ~FakeTokenValidator() {} | 71 virtual ~FakeTokenValidator() {} |
72 | 72 |
73 virtual void ValidateThirdPartyToken( | 73 virtual void ValidateThirdPartyToken( |
74 const std::string& token, | 74 const std::string& token, |
75 const TokenValidatedCallback& token_validated_callback) OVERRIDE { | 75 const TokenValidatedCallback& token_validated_callback) OVERRIDE { |
(...skipping 21 matching lines...) Expand all Loading... |
97 std::string token_scope_; | 97 std::string token_scope_; |
98 base::Callback<void(const std::string& shared_secret)> on_token_validated_; | 98 base::Callback<void(const std::string& shared_secret)> on_token_validated_; |
99 }; | 99 }; |
100 | 100 |
101 public: | 101 public: |
102 ThirdPartyAuthenticatorTest() {} | 102 ThirdPartyAuthenticatorTest() {} |
103 virtual ~ThirdPartyAuthenticatorTest() {} | 103 virtual ~ThirdPartyAuthenticatorTest() {} |
104 | 104 |
105 protected: | 105 protected: |
106 void InitAuthenticators() { | 106 void InitAuthenticators() { |
107 scoped_ptr<ThirdPartyHostAuthenticator::TokenValidator> | 107 scoped_ptr<TokenValidator> token_validator(new FakeTokenValidator()); |
108 token_validator(new FakeTokenValidator()); | |
109 token_validator_ = static_cast<FakeTokenValidator*>(token_validator.get()); | 108 token_validator_ = static_cast<FakeTokenValidator*>(token_validator.get()); |
110 host_.reset(new ThirdPartyHostAuthenticator( | 109 host_.reset(new ThirdPartyHostAuthenticator( |
111 host_cert_, key_pair_, token_validator.Pass())); | 110 host_cert_, key_pair_, token_validator.Pass())); |
112 scoped_ptr<ThirdPartyClientAuthenticator::TokenFetcher> | 111 scoped_ptr<ThirdPartyClientAuthenticator::TokenFetcher> |
113 token_fetcher(new FakeTokenFetcher()); | 112 token_fetcher(new FakeTokenFetcher()); |
114 token_fetcher_ = static_cast<FakeTokenFetcher*>(token_fetcher.get()); | 113 token_fetcher_ = static_cast<FakeTokenFetcher*>(token_fetcher.get()); |
115 client_.reset(new ThirdPartyClientAuthenticator(token_fetcher.Pass())); | 114 client_.reset(new ThirdPartyClientAuthenticator(token_fetcher.Pass())); |
116 } | 115 } |
117 | 116 |
118 FakeTokenFetcher* token_fetcher_; | 117 FakeTokenFetcher* token_fetcher_; |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 ASSERT_EQ(Authenticator::PROCESSING_MESSAGE, host_->state()); | 216 ASSERT_EQ(Authenticator::PROCESSING_MESSAGE, host_->state()); |
218 ASSERT_NO_FATAL_FAILURE( | 217 ASSERT_NO_FATAL_FAILURE( |
219 token_validator_->OnTokenValidated(kSharedSecret)); | 218 token_validator_->OnTokenValidated(kSharedSecret)); |
220 | 219 |
221 // The end result is that the host rejected the fake authentication. | 220 // The end result is that the host rejected the fake authentication. |
222 ASSERT_EQ(Authenticator::REJECTED, client_->state()); | 221 ASSERT_EQ(Authenticator::REJECTED, client_->state()); |
223 } | 222 } |
224 | 223 |
225 } // namespace protocol | 224 } // namespace protocol |
226 } // namespace remoting | 225 } // namespace remoting |
OLD | NEW |