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/url_request/test_url_fetcher_factory.h" | 12 #include "net/url_request/test_url_fetcher_factory.h" |
12 #include "net/url_request/url_request_test_util.h" | 13 #include "net/url_request/url_request_test_util.h" |
13 #include "remoting/base/rsa_key_pair.h" | 14 #include "remoting/base/rsa_key_pair.h" |
14 #include "remoting/base/test_rsa_key_pair.h" | 15 #include "remoting/base/test_rsa_key_pair.h" |
15 #include "remoting/host/token_validator_factory_impl.h" | 16 #include "remoting/host/token_validator_factory_impl.h" |
16 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
17 #include "url/gurl.h" | 18 #include "url/gurl.h" |
18 | 19 |
19 namespace { | 20 namespace { |
20 | 21 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 scoped_ptr<TokenValidatorFactoryImpl> token_validator_factory_; | 88 scoped_ptr<TokenValidatorFactoryImpl> token_validator_factory_; |
88 scoped_ptr<protocol::ThirdPartyHostAuthenticator::TokenValidator> | 89 scoped_ptr<protocol::ThirdPartyHostAuthenticator::TokenValidator> |
89 token_validator_; | 90 token_validator_; |
90 }; | 91 }; |
91 | 92 |
92 TEST_F(TokenValidatorFactoryImplTest, Success) { | 93 TEST_F(TokenValidatorFactoryImplTest, Success) { |
93 net::FakeURLFetcherFactory factory(NULL); | 94 net::FakeURLFetcherFactory factory(NULL); |
94 token_validator_ = token_validator_factory_->CreateTokenValidator( | 95 token_validator_ = token_validator_factory_->CreateTokenValidator( |
95 kLocalJid, kRemoteJid); | 96 kLocalJid, kRemoteJid); |
96 factory.SetFakeResponse(GURL(kTokenValidationUrl), CreateResponse( | 97 factory.SetFakeResponse(GURL(kTokenValidationUrl), CreateResponse( |
97 token_validator_->token_scope()), true); | 98 token_validator_->token_scope()), net::HTTP_OK); |
98 token_validator_->ValidateThirdPartyToken( | 99 token_validator_->ValidateThirdPartyToken( |
99 kToken, base::Bind(&TokenValidatorFactoryImplTest::SuccessCallback, | 100 kToken, base::Bind(&TokenValidatorFactoryImplTest::SuccessCallback, |
100 base::Unretained(this))); | 101 base::Unretained(this))); |
101 message_loop_.Run(); | 102 message_loop_.Run(); |
102 } | 103 } |
103 | 104 |
104 TEST_F(TokenValidatorFactoryImplTest, BadToken) { | 105 TEST_F(TokenValidatorFactoryImplTest, BadToken) { |
105 net::FakeURLFetcherFactory factory(NULL); | 106 net::FakeURLFetcherFactory factory(NULL); |
106 token_validator_ = token_validator_factory_->CreateTokenValidator( | 107 token_validator_ = token_validator_factory_->CreateTokenValidator( |
107 kLocalJid, kRemoteJid); | 108 kLocalJid, kRemoteJid); |
108 factory.SetFakeResponse(GURL(kTokenValidationUrl), std::string(), false); | 109 factory.SetFakeResponse(GURL(kTokenValidationUrl), |
| 110 std::string(), |
| 111 net::HTTP_INTERNAL_SERVER_ERROR); |
109 token_validator_->ValidateThirdPartyToken( | 112 token_validator_->ValidateThirdPartyToken( |
110 kToken, base::Bind(&TokenValidatorFactoryImplTest::FailureCallback, | 113 kToken, base::Bind(&TokenValidatorFactoryImplTest::FailureCallback, |
111 base::Unretained(this))); | 114 base::Unretained(this))); |
112 message_loop_.Run(); | 115 message_loop_.Run(); |
113 } | 116 } |
114 | 117 |
115 TEST_F(TokenValidatorFactoryImplTest, BadScope) { | 118 TEST_F(TokenValidatorFactoryImplTest, BadScope) { |
116 net::FakeURLFetcherFactory factory(NULL); | 119 net::FakeURLFetcherFactory factory(NULL); |
117 token_validator_ = token_validator_factory_->CreateTokenValidator( | 120 token_validator_ = token_validator_factory_->CreateTokenValidator( |
118 kLocalJid, kRemoteJid); | 121 kLocalJid, kRemoteJid); |
119 factory.SetFakeResponse( | 122 factory.SetFakeResponse( |
120 GURL(kTokenValidationUrl), CreateResponse(kBadScope), true); | 123 GURL(kTokenValidationUrl), CreateResponse(kBadScope), net::HTTP_OK); |
121 token_validator_->ValidateThirdPartyToken( | 124 token_validator_->ValidateThirdPartyToken( |
122 kToken, base::Bind(&TokenValidatorFactoryImplTest::FailureCallback, | 125 kToken, base::Bind(&TokenValidatorFactoryImplTest::FailureCallback, |
123 base::Unretained(this))); | 126 base::Unretained(this))); |
124 message_loop_.Run(); | 127 message_loop_.Run(); |
125 } | 128 } |
126 | 129 |
127 TEST_F(TokenValidatorFactoryImplTest, DeleteOnFailure) { | 130 TEST_F(TokenValidatorFactoryImplTest, DeleteOnFailure) { |
128 net::FakeURLFetcherFactory factory(NULL); | 131 net::FakeURLFetcherFactory factory(NULL); |
129 token_validator_ = token_validator_factory_->CreateTokenValidator( | 132 token_validator_ = token_validator_factory_->CreateTokenValidator( |
130 kLocalJid, kRemoteJid); | 133 kLocalJid, kRemoteJid); |
131 factory.SetFakeResponse(GURL(kTokenValidationUrl), std::string(), false); | 134 factory.SetFakeResponse(GURL(kTokenValidationUrl), |
| 135 std::string(), |
| 136 net::HTTP_INTERNAL_SERVER_ERROR); |
132 token_validator_->ValidateThirdPartyToken( | 137 token_validator_->ValidateThirdPartyToken( |
133 kToken, base::Bind( | 138 kToken, base::Bind( |
134 &TokenValidatorFactoryImplTest::DeleteOnFailureCallback, | 139 &TokenValidatorFactoryImplTest::DeleteOnFailureCallback, |
135 base::Unretained(this))); | 140 base::Unretained(this))); |
136 message_loop_.Run(); | 141 message_loop_.Run(); |
137 } | 142 } |
138 | 143 |
139 } // namespace remoting | 144 } // namespace remoting |
OLD | NEW |