| 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" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 const char kSharedSecretBad[] = "0000-0000-0001"; | 33 const char kSharedSecretBad[] = "0000-0000-0001"; |
| 34 | 34 |
| 35 } // namespace | 35 } // namespace |
| 36 | 36 |
| 37 namespace remoting { | 37 namespace remoting { |
| 38 namespace protocol { | 38 namespace protocol { |
| 39 | 39 |
| 40 class ThirdPartyAuthenticatorTest : public AuthenticatorTestBase { | 40 class ThirdPartyAuthenticatorTest : public AuthenticatorTestBase { |
| 41 class FakeTokenFetcher : public ThirdPartyClientAuthenticator::TokenFetcher { | 41 class FakeTokenFetcher : public ThirdPartyClientAuthenticator::TokenFetcher { |
| 42 public: | 42 public: |
| 43 virtual void FetchThirdPartyToken( | 43 void FetchThirdPartyToken( |
| 44 const GURL& token_url, | 44 const GURL& token_url, |
| 45 const std::string& scope, | 45 const std::string& scope, |
| 46 const TokenFetchedCallback& token_fetched_callback) override { | 46 const TokenFetchedCallback& token_fetched_callback) override { |
| 47 ASSERT_EQ(token_url.spec(), kTokenUrl); | 47 ASSERT_EQ(token_url.spec(), kTokenUrl); |
| 48 ASSERT_EQ(scope, kTokenScope); | 48 ASSERT_EQ(scope, kTokenScope); |
| 49 ASSERT_FALSE(token_fetched_callback.is_null()); | 49 ASSERT_FALSE(token_fetched_callback.is_null()); |
| 50 on_token_fetched_ = token_fetched_callback; | 50 on_token_fetched_ = token_fetched_callback; |
| 51 } | 51 } |
| 52 | 52 |
| 53 void OnTokenFetched(const std::string& token, | 53 void OnTokenFetched(const std::string& token, |
| 54 const std::string& shared_secret) { | 54 const std::string& shared_secret) { |
| 55 ASSERT_FALSE(on_token_fetched_.is_null()); | 55 ASSERT_FALSE(on_token_fetched_.is_null()); |
| 56 TokenFetchedCallback on_token_fetched = on_token_fetched_; | 56 TokenFetchedCallback on_token_fetched = on_token_fetched_; |
| 57 on_token_fetched_.Reset(); | 57 on_token_fetched_.Reset(); |
| 58 on_token_fetched.Run(token, shared_secret); | 58 on_token_fetched.Run(token, shared_secret); |
| 59 } | 59 } |
| 60 | 60 |
| 61 private: | 61 private: |
| 62 TokenFetchedCallback on_token_fetched_; | 62 TokenFetchedCallback on_token_fetched_; |
| 63 }; | 63 }; |
| 64 | 64 |
| 65 class FakeTokenValidator : public TokenValidator { | 65 class FakeTokenValidator : public 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 ~FakeTokenValidator() override {} |
| 72 | 72 |
| 73 virtual void ValidateThirdPartyToken( | 73 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 { |
| 76 ASSERT_FALSE(token_validated_callback.is_null()); | 76 ASSERT_FALSE(token_validated_callback.is_null()); |
| 77 on_token_validated_ = token_validated_callback; | 77 on_token_validated_ = token_validated_callback; |
| 78 } | 78 } |
| 79 | 79 |
| 80 void OnTokenValidated(const std::string& shared_secret) { | 80 void OnTokenValidated(const std::string& shared_secret) { |
| 81 ASSERT_FALSE(on_token_validated_.is_null()); | 81 ASSERT_FALSE(on_token_validated_.is_null()); |
| 82 TokenValidatedCallback on_token_validated = on_token_validated_; | 82 TokenValidatedCallback on_token_validated = on_token_validated_; |
| 83 on_token_validated_.Reset(); | 83 on_token_validated_.Reset(); |
| 84 on_token_validated.Run(shared_secret); | 84 on_token_validated.Run(shared_secret); |
| 85 } | 85 } |
| 86 | 86 |
| 87 virtual const GURL& token_url() const override { | 87 const GURL& token_url() const override { return token_url_; } |
| 88 return token_url_; | |
| 89 } | |
| 90 | 88 |
| 91 virtual const std::string& token_scope() const override { | 89 const std::string& token_scope() const override { return token_scope_; } |
| 92 return token_scope_; | |
| 93 } | |
| 94 | 90 |
| 95 private: | 91 private: |
| 96 GURL token_url_; | 92 GURL token_url_; |
| 97 std::string token_scope_; | 93 std::string token_scope_; |
| 98 base::Callback<void(const std::string& shared_secret)> on_token_validated_; | 94 base::Callback<void(const std::string& shared_secret)> on_token_validated_; |
| 99 }; | 95 }; |
| 100 | 96 |
| 101 public: | 97 public: |
| 102 ThirdPartyAuthenticatorTest() {} | 98 ThirdPartyAuthenticatorTest() {} |
| 103 virtual ~ThirdPartyAuthenticatorTest() {} | 99 virtual ~ThirdPartyAuthenticatorTest() {} |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 209 ASSERT_EQ(Authenticator::PROCESSING_MESSAGE, host_->state()); | 205 ASSERT_EQ(Authenticator::PROCESSING_MESSAGE, host_->state()); |
| 210 ASSERT_NO_FATAL_FAILURE( | 206 ASSERT_NO_FATAL_FAILURE( |
| 211 token_validator_->OnTokenValidated(kSharedSecret)); | 207 token_validator_->OnTokenValidated(kSharedSecret)); |
| 212 | 208 |
| 213 // The end result is that the host rejected the fake authentication. | 209 // The end result is that the host rejected the fake authentication. |
| 214 ASSERT_EQ(Authenticator::REJECTED, client_->state()); | 210 ASSERT_EQ(Authenticator::REJECTED, client_->state()); |
| 215 } | 211 } |
| 216 | 212 |
| 217 } // namespace protocol | 213 } // namespace protocol |
| 218 } // namespace remoting | 214 } // namespace remoting |
| OLD | NEW |