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/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 protected: | 91 protected: |
92 void SetUp() override { | 92 void SetUp() override { |
93 key_pair_ = RsaKeyPair::FromString(kTestRsaKeyPair); | 93 key_pair_ = RsaKeyPair::FromString(kTestRsaKeyPair); |
94 request_context_getter_ = new net::TestURLRequestContextGetter( | 94 request_context_getter_ = new net::TestURLRequestContextGetter( |
95 message_loop_.task_runner(), | 95 message_loop_.task_runner(), |
96 make_scoped_ptr(new SetResponseURLRequestContext())); | 96 make_scoped_ptr(new SetResponseURLRequestContext())); |
97 ThirdPartyAuthConfig config; | 97 ThirdPartyAuthConfig config; |
98 config.token_url = GURL(kTokenUrl); | 98 config.token_url = GURL(kTokenUrl); |
99 config.token_validation_url = GURL(kTokenValidationUrl); | 99 config.token_validation_url = GURL(kTokenValidationUrl); |
100 config.token_validation_cert_issuer = kTokenValidationCertIssuer; | 100 config.token_validation_cert_issuer = kTokenValidationCertIssuer; |
101 token_validator_factory_.reset(new TokenValidatorFactoryImpl( | 101 token_validator_factory_ = new TokenValidatorFactoryImpl( |
102 config, key_pair_, request_context_getter_)); | 102 config, key_pair_, request_context_getter_); |
103 } | 103 } |
104 | 104 |
105 static std::string CreateResponse(const std::string& scope) { | 105 static std::string CreateResponse(const std::string& scope) { |
106 base::DictionaryValue response_dict; | 106 base::DictionaryValue response_dict; |
107 response_dict.SetString("access_token", kSharedSecret); | 107 response_dict.SetString("access_token", kSharedSecret); |
108 response_dict.SetString("token_type", "shared_secret"); | 108 response_dict.SetString("token_type", "shared_secret"); |
109 response_dict.SetString("scope", scope); | 109 response_dict.SetString("scope", scope); |
110 std::string response; | 110 std::string response; |
111 base::JSONWriter::Write(response_dict, &response); | 111 base::JSONWriter::Write(response_dict, &response); |
112 return response; | 112 return response; |
(...skipping 11 matching lines...) Expand all Loading... |
124 void SetResponse(const std::string& headers, const std::string& response) { | 124 void SetResponse(const std::string& headers, const std::string& response) { |
125 SetResponseURLRequestContext* context = | 125 SetResponseURLRequestContext* context = |
126 static_cast<SetResponseURLRequestContext*>( | 126 static_cast<SetResponseURLRequestContext*>( |
127 request_context_getter_->GetURLRequestContext()); | 127 request_context_getter_->GetURLRequestContext()); |
128 context->SetResponse(headers, response); | 128 context->SetResponse(headers, response); |
129 } | 129 } |
130 | 130 |
131 base::MessageLoop message_loop_; | 131 base::MessageLoop message_loop_; |
132 scoped_refptr<RsaKeyPair> key_pair_; | 132 scoped_refptr<RsaKeyPair> key_pair_; |
133 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; | 133 scoped_refptr<net::URLRequestContextGetter> request_context_getter_; |
134 scoped_ptr<TokenValidatorFactoryImpl> token_validator_factory_; | 134 scoped_refptr<TokenValidatorFactoryImpl> token_validator_factory_; |
135 scoped_ptr<protocol::TokenValidator> token_validator_; | 135 scoped_ptr<protocol::TokenValidator> token_validator_; |
136 }; | 136 }; |
137 | 137 |
138 TEST_F(TokenValidatorFactoryImplTest, Success) { | 138 TEST_F(TokenValidatorFactoryImplTest, Success) { |
139 token_validator_ = token_validator_factory_->CreateTokenValidator( | 139 token_validator_ = token_validator_factory_->CreateTokenValidator( |
140 kLocalJid, kRemoteJid); | 140 kLocalJid, kRemoteJid); |
141 | 141 |
142 SetResponse(net::URLRequestTestJob::test_headers(), | 142 SetResponse(net::URLRequestTestJob::test_headers(), |
143 CreateResponse(token_validator_->token_scope())); | 143 CreateResponse(token_validator_->token_scope())); |
144 | 144 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 SetResponse(net::URLRequestTestJob::test_error_headers(), std::string()); | 180 SetResponse(net::URLRequestTestJob::test_error_headers(), std::string()); |
181 | 181 |
182 token_validator_->ValidateThirdPartyToken( | 182 token_validator_->ValidateThirdPartyToken( |
183 kToken, base::Bind( | 183 kToken, base::Bind( |
184 &TokenValidatorFactoryImplTest::DeleteOnFailureCallback, | 184 &TokenValidatorFactoryImplTest::DeleteOnFailureCallback, |
185 base::Unretained(this))); | 185 base::Unretained(this))); |
186 message_loop_.Run(); | 186 message_loop_.Run(); |
187 } | 187 } |
188 | 188 |
189 } // namespace remoting | 189 } // namespace remoting |
OLD | NEW |