Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(259)

Side by Side Diff: remoting/protocol/negotiating_authenticator_unittest.cc

Issue 12326090: Third Party authentication protocol. (Closed) Base URL: http://git.chromium.org/chromium/src.git@host_key_pair
Patch Set: Add the missing new files Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 "remoting/protocol/negotiating_authenticator.h" 5 #include "remoting/protocol/negotiating_authenticator.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "net/base/net_errors.h" 8 #include "net/base/net_errors.h"
9 #include "remoting/protocol/authenticator_test_base.h" 9 #include "remoting/protocol/authenticator_test_base.h"
10 #include "remoting/protocol/channel_authenticator.h" 10 #include "remoting/protocol/channel_authenticator.h"
(...skipping 23 matching lines...) Expand all
34 } // namespace 34 } // namespace
35 35
36 class NegotiatingAuthenticatorTest : public AuthenticatorTestBase { 36 class NegotiatingAuthenticatorTest : public AuthenticatorTestBase {
37 public: 37 public:
38 NegotiatingAuthenticatorTest() { 38 NegotiatingAuthenticatorTest() {
39 } 39 }
40 virtual ~NegotiatingAuthenticatorTest() { 40 virtual ~NegotiatingAuthenticatorTest() {
41 } 41 }
42 42
43 protected: 43 protected:
44 class MockTokenFetcher
45 : public protocol::ThirdPartyAuthenticator::TokenFetcher {
46 public:
47 MOCK_METHOD4(FetchThirdPartyToken, void(
48 const std::string& token_url,
49 const std::string& host_public_key,
50 const std::string& scope,
51 const base::Callback<void(
52 const std::string& token,
53 const std::string& shared_secret)>& on_token_fetched));
54 };
55
44 void InitAuthenticators( 56 void InitAuthenticators(
45 const std::string& client_secret, 57 const std::string& client_secret,
46 const std::string& host_secret, 58 const std::string& host_secret,
47 AuthenticationMethod::HashFunction hash_function, 59 AuthenticationMethod::HashFunction hash_function,
48 bool client_hmac_only) { 60 bool client_hmac_only) {
49 std::string host_secret_hash = AuthenticationMethod::ApplyHashFunction( 61 std::string host_secret_hash = AuthenticationMethod::ApplyHashFunction(
50 hash_function, kTestHostId, host_secret); 62 hash_function, kTestHostId, host_secret);
51 host_ = NegotiatingAuthenticator::CreateForHost( 63 host_ = NegotiatingAuthenticator::CreateForHostSharedSecret(
52 host_cert_, key_pair_->Copy(), host_secret_hash, hash_function); 64 host_cert_, key_pair_->Copy(), host_secret_hash, hash_function);
53 65
54 std::vector<AuthenticationMethod> methods; 66 std::vector<AuthenticationMethod> methods;
55 methods.push_back(AuthenticationMethod::Spake2( 67 methods.push_back(AuthenticationMethod::Spake2(
56 AuthenticationMethod::HMAC_SHA256)); 68 AuthenticationMethod::HMAC_SHA256));
57 if (!client_hmac_only) { 69 if (!client_hmac_only) {
58 methods.push_back(AuthenticationMethod::Spake2( 70 methods.push_back(AuthenticationMethod::Spake2(
59 AuthenticationMethod::NONE)); 71 AuthenticationMethod::NONE));
60 } 72 }
61 client_ = NegotiatingAuthenticator::CreateForClient( 73 client_ = NegotiatingAuthenticator::CreateForClient(
62 kTestHostId, client_secret, methods); 74 kTestHostId, client_secret, host_public_key_, methods,
75 &mock_token_fetcher_);
63 } 76 }
64 77
65 void VerifyRejected(Authenticator::RejectionReason reason) { 78 void VerifyRejected(Authenticator::RejectionReason reason) {
66 ASSERT_TRUE((client_->state() == Authenticator::REJECTED && 79 ASSERT_TRUE((client_->state() == Authenticator::REJECTED &&
67 (client_->rejection_reason() == reason)) || 80 (client_->rejection_reason() == reason)) ||
68 (host_->state() == Authenticator::REJECTED && 81 (host_->state() == Authenticator::REJECTED &&
69 (host_->rejection_reason() == reason))); 82 (host_->rejection_reason() == reason)));
70 } 83 }
71 84
85 MockTokenFetcher mock_token_fetcher_;
72 DISALLOW_COPY_AND_ASSIGN(NegotiatingAuthenticatorTest); 86 DISALLOW_COPY_AND_ASSIGN(NegotiatingAuthenticatorTest);
73 }; 87 };
74 88
75 TEST_F(NegotiatingAuthenticatorTest, SuccessfulAuthHmac) { 89 TEST_F(NegotiatingAuthenticatorTest, SuccessfulAuthHmac) {
76 ASSERT_NO_FATAL_FAILURE(InitAuthenticators( 90 ASSERT_NO_FATAL_FAILURE(InitAuthenticators(
77 kTestSharedSecret, kTestSharedSecret, 91 kTestSharedSecret, kTestSharedSecret,
78 AuthenticationMethod::HMAC_SHA256, false)); 92 AuthenticationMethod::HMAC_SHA256, false));
79 ASSERT_NO_FATAL_FAILURE(RunAuthExchange()); 93 ASSERT_NO_FATAL_FAILURE(RunAuthExchange());
80 94
81 ASSERT_EQ(Authenticator::ACCEPTED, host_->state()); 95 ASSERT_EQ(Authenticator::ACCEPTED, host_->state());
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
142 ASSERT_NO_FATAL_FAILURE(InitAuthenticators( 156 ASSERT_NO_FATAL_FAILURE(InitAuthenticators(
143 kTestSharedSecret, kTestSharedSecretBad, 157 kTestSharedSecret, kTestSharedSecretBad,
144 AuthenticationMethod::NONE, true)); 158 AuthenticationMethod::NONE, true));
145 ASSERT_NO_FATAL_FAILURE(RunAuthExchange()); 159 ASSERT_NO_FATAL_FAILURE(RunAuthExchange());
146 160
147 VerifyRejected(Authenticator::PROTOCOL_ERROR); 161 VerifyRejected(Authenticator::PROTOCOL_ERROR);
148 } 162 }
149 163
150 } // namespace protocol 164 } // namespace protocol
151 } // namespace remoting 165 } // namespace remoting
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698