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 // A set of unit tests for TokenValidatorFactoryImpl | 5 // A set of unit tests for TokenValidatorFactoryImpl |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/json/json_writer.h" | 9 #include "base/json/json_writer.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
11 #include "net/http/http_status_code.h" | 11 #include "net/http/http_status_code.h" |
12 #include "net/url_request/test_url_fetcher_factory.h" | 12 #include "net/url_request/test_url_fetcher_factory.h" |
| 13 #include "net/url_request/url_request_status.h" |
13 #include "net/url_request/url_request_test_util.h" | 14 #include "net/url_request/url_request_test_util.h" |
14 #include "remoting/base/rsa_key_pair.h" | 15 #include "remoting/base/rsa_key_pair.h" |
15 #include "remoting/base/test_rsa_key_pair.h" | 16 #include "remoting/base/test_rsa_key_pair.h" |
16 #include "remoting/host/token_validator_factory_impl.h" | 17 #include "remoting/host/token_validator_factory_impl.h" |
17 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
18 #include "url/gurl.h" | 19 #include "url/gurl.h" |
19 | 20 |
20 namespace { | 21 namespace { |
21 | 22 |
22 const char kTokenUrl[] = "https://example.com/token"; | 23 const char kTokenUrl[] = "https://example.com/token"; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; | 88 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; |
88 scoped_ptr<TokenValidatorFactoryImpl> token_validator_factory_; | 89 scoped_ptr<TokenValidatorFactoryImpl> token_validator_factory_; |
89 scoped_ptr<protocol::ThirdPartyHostAuthenticator::TokenValidator> | 90 scoped_ptr<protocol::ThirdPartyHostAuthenticator::TokenValidator> |
90 token_validator_; | 91 token_validator_; |
91 }; | 92 }; |
92 | 93 |
93 TEST_F(TokenValidatorFactoryImplTest, Success) { | 94 TEST_F(TokenValidatorFactoryImplTest, Success) { |
94 net::FakeURLFetcherFactory factory(NULL); | 95 net::FakeURLFetcherFactory factory(NULL); |
95 token_validator_ = token_validator_factory_->CreateTokenValidator( | 96 token_validator_ = token_validator_factory_->CreateTokenValidator( |
96 kLocalJid, kRemoteJid); | 97 kLocalJid, kRemoteJid); |
97 factory.SetFakeResponse(GURL(kTokenValidationUrl), CreateResponse( | 98 factory.SetFakeResponse( |
98 token_validator_->token_scope()), net::HTTP_OK); | 99 GURL(kTokenValidationUrl), |
| 100 CreateResponse(token_validator_->token_scope()), |
| 101 net::HTTP_OK, net::URLRequestStatus::SUCCESS); |
99 token_validator_->ValidateThirdPartyToken( | 102 token_validator_->ValidateThirdPartyToken( |
100 kToken, base::Bind(&TokenValidatorFactoryImplTest::SuccessCallback, | 103 kToken, base::Bind(&TokenValidatorFactoryImplTest::SuccessCallback, |
101 base::Unretained(this))); | 104 base::Unretained(this))); |
102 message_loop_.Run(); | 105 message_loop_.Run(); |
103 } | 106 } |
104 | 107 |
105 TEST_F(TokenValidatorFactoryImplTest, BadToken) { | 108 TEST_F(TokenValidatorFactoryImplTest, BadToken) { |
106 net::FakeURLFetcherFactory factory(NULL); | 109 net::FakeURLFetcherFactory factory(NULL); |
107 token_validator_ = token_validator_factory_->CreateTokenValidator( | 110 token_validator_ = token_validator_factory_->CreateTokenValidator( |
108 kLocalJid, kRemoteJid); | 111 kLocalJid, kRemoteJid); |
109 factory.SetFakeResponse(GURL(kTokenValidationUrl), | 112 factory.SetFakeResponse(GURL(kTokenValidationUrl), std::string(), |
110 std::string(), | 113 net::HTTP_INTERNAL_SERVER_ERROR, |
111 net::HTTP_INTERNAL_SERVER_ERROR); | 114 net::URLRequestStatus::FAILED); |
112 token_validator_->ValidateThirdPartyToken( | 115 token_validator_->ValidateThirdPartyToken( |
113 kToken, base::Bind(&TokenValidatorFactoryImplTest::FailureCallback, | 116 kToken, base::Bind(&TokenValidatorFactoryImplTest::FailureCallback, |
114 base::Unretained(this))); | 117 base::Unretained(this))); |
115 message_loop_.Run(); | 118 message_loop_.Run(); |
116 } | 119 } |
117 | 120 |
118 TEST_F(TokenValidatorFactoryImplTest, BadScope) { | 121 TEST_F(TokenValidatorFactoryImplTest, BadScope) { |
119 net::FakeURLFetcherFactory factory(NULL); | 122 net::FakeURLFetcherFactory factory(NULL); |
120 token_validator_ = token_validator_factory_->CreateTokenValidator( | 123 token_validator_ = token_validator_factory_->CreateTokenValidator( |
121 kLocalJid, kRemoteJid); | 124 kLocalJid, kRemoteJid); |
122 factory.SetFakeResponse( | 125 factory.SetFakeResponse( |
123 GURL(kTokenValidationUrl), CreateResponse(kBadScope), net::HTTP_OK); | 126 GURL(kTokenValidationUrl), CreateResponse(kBadScope), net::HTTP_OK, |
| 127 net::URLRequestStatus::SUCCESS); |
124 token_validator_->ValidateThirdPartyToken( | 128 token_validator_->ValidateThirdPartyToken( |
125 kToken, base::Bind(&TokenValidatorFactoryImplTest::FailureCallback, | 129 kToken, base::Bind(&TokenValidatorFactoryImplTest::FailureCallback, |
126 base::Unretained(this))); | 130 base::Unretained(this))); |
127 message_loop_.Run(); | 131 message_loop_.Run(); |
128 } | 132 } |
129 | 133 |
130 TEST_F(TokenValidatorFactoryImplTest, DeleteOnFailure) { | 134 TEST_F(TokenValidatorFactoryImplTest, DeleteOnFailure) { |
131 net::FakeURLFetcherFactory factory(NULL); | 135 net::FakeURLFetcherFactory factory(NULL); |
132 token_validator_ = token_validator_factory_->CreateTokenValidator( | 136 token_validator_ = token_validator_factory_->CreateTokenValidator( |
133 kLocalJid, kRemoteJid); | 137 kLocalJid, kRemoteJid); |
134 factory.SetFakeResponse(GURL(kTokenValidationUrl), | 138 factory.SetFakeResponse(GURL(kTokenValidationUrl), |
135 std::string(), | 139 std::string(), |
136 net::HTTP_INTERNAL_SERVER_ERROR); | 140 net::HTTP_INTERNAL_SERVER_ERROR, |
| 141 net::URLRequestStatus::FAILED); |
137 token_validator_->ValidateThirdPartyToken( | 142 token_validator_->ValidateThirdPartyToken( |
138 kToken, base::Bind( | 143 kToken, base::Bind( |
139 &TokenValidatorFactoryImplTest::DeleteOnFailureCallback, | 144 &TokenValidatorFactoryImplTest::DeleteOnFailureCallback, |
140 base::Unretained(this))); | 145 base::Unretained(this))); |
141 message_loop_.Run(); | 146 message_loop_.Run(); |
142 } | 147 } |
143 | 148 |
144 } // namespace remoting | 149 } // namespace remoting |
OLD | NEW |