| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/chromeos/login/profile_auth_data.h" | 5 #include "chrome/browser/chromeos/login/profile_auth_data.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 const char kProxyAuthRealm[] = "realm"; | 40 const char kProxyAuthRealm[] = "realm"; |
| 41 const char kProxyAuthChallenge[] = "challenge"; | 41 const char kProxyAuthChallenge[] = "challenge"; |
| 42 const char kProxyAuthPassword1[] = "password 1"; | 42 const char kProxyAuthPassword1[] = "password 1"; |
| 43 const char kProxyAuthPassword2[] = "password 2"; | 43 const char kProxyAuthPassword2[] = "password 2"; |
| 44 | 44 |
| 45 const char kGAIACookieURL[] = "http://google.com/"; | 45 const char kGAIACookieURL[] = "http://google.com/"; |
| 46 const char kSAMLIdPCookieURL[] = "http://example.com/"; | 46 const char kSAMLIdPCookieURL[] = "http://example.com/"; |
| 47 const char kCookieName[] = "cookie"; | 47 const char kCookieName[] = "cookie"; |
| 48 const char kCookieValue1[] = "value 1"; | 48 const char kCookieValue1[] = "value 1"; |
| 49 const char kCookieValue2[] = "value 2"; | 49 const char kCookieValue2[] = "value 2"; |
| 50 const char kGAIACookieDomain[] = ".google.com"; | 50 const char kGAIACookieDomain[] = "google.com"; |
| 51 const char kSAMLIdPCookieDomain[] = ".example.com"; | 51 const char kSAMLIdPCookieDomain[] = "example.com"; |
| 52 | 52 |
| 53 const char kChannelIDServerIdentifier[] = "server"; | 53 const char kChannelIDServerIdentifier[] = "server"; |
| 54 const char kChannelIDPrivateKey1[] = "private key 1"; | 54 const char kChannelIDPrivateKey1[] = "private key 1"; |
| 55 const char kChannelIDPrivateKey2[] = "private key 2"; | 55 const char kChannelIDPrivateKey2[] = "private key 2"; |
| 56 const char kChannelIDCert1[] = "cert 1"; | 56 const char kChannelIDCert1[] = "cert 1"; |
| 57 const char kChannelIDCert2[] = "cert 2"; | 57 const char kChannelIDCert2[] = "cert 2"; |
| 58 | 58 |
| 59 } // namespace | 59 } // namespace |
| 60 | 60 |
| 61 class ProfileAuthDataTest : public testing::Test { | 61 class ProfileAuthDataTest : public testing::Test { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 84 const std::string& cookie_value, | 84 const std::string& cookie_value, |
| 85 const std::string& channel_id_private_key, | 85 const std::string& channel_id_private_key, |
| 86 const std::string& channel_id_cert); | 86 const std::string& channel_id_cert); |
| 87 | 87 |
| 88 net::URLRequestContext* GetRequestContext( | 88 net::URLRequestContext* GetRequestContext( |
| 89 content::BrowserContext* browser_context); | 89 content::BrowserContext* browser_context); |
| 90 net::HttpAuthCache* GetProxyAuth(content::BrowserContext* browser_context); | 90 net::HttpAuthCache* GetProxyAuth(content::BrowserContext* browser_context); |
| 91 net::CookieMonster* GetCookies(content::BrowserContext* browser_context); | 91 net::CookieMonster* GetCookies(content::BrowserContext* browser_context); |
| 92 net::ChannelIDStore* GetChannelIDs(content::BrowserContext* browser_context); | 92 net::ChannelIDStore* GetChannelIDs(content::BrowserContext* browser_context); |
| 93 | 93 |
| 94 void QuitLoop(bool ignored); | 94 void QuitLoop(const net::CookieList& ignored); |
| 95 void StoreCookieListAndQuitLoop(const net::CookieList& cookie_list); | 95 void StoreCookieListAndQuitLoop(const net::CookieList& cookie_list); |
| 96 void StoreChannelIDListAndQuitLoop( | 96 void StoreChannelIDListAndQuitLoop( |
| 97 const net::ChannelIDStore::ChannelIDList& channel_id_list); | 97 const net::ChannelIDStore::ChannelIDList& channel_id_list); |
| 98 | 98 |
| 99 content::TestBrowserThreadBundle thread_bundle_; | 99 content::TestBrowserThreadBundle thread_bundle_; |
| 100 | 100 |
| 101 TestingProfile login_browser_context_; | 101 TestingProfile login_browser_context_; |
| 102 TestingProfile user_browser_context_; | 102 TestingProfile user_browser_context_; |
| 103 | 103 |
| 104 net::CookieList user_cookie_list_; | 104 net::CookieList user_cookie_list_; |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 EXPECT_EQ(base::ASCIIToUTF16(kProxyAuthPassword1), | 171 EXPECT_EQ(base::ASCIIToUTF16(kProxyAuthPassword1), |
| 172 entry->credentials().password()); | 172 entry->credentials().password()); |
| 173 } | 173 } |
| 174 | 174 |
| 175 void ProfileAuthDataTest::VerifyUserCookies( | 175 void ProfileAuthDataTest::VerifyUserCookies( |
| 176 const std::string& expected_gaia_cookie_value, | 176 const std::string& expected_gaia_cookie_value, |
| 177 const std::string& expected_saml_idp_cookie_value) { | 177 const std::string& expected_saml_idp_cookie_value) { |
| 178 net::CookieList user_cookies = GetUserCookies(); | 178 net::CookieList user_cookies = GetUserCookies(); |
| 179 ASSERT_EQ(2u, user_cookies.size()); | 179 ASSERT_EQ(2u, user_cookies.size()); |
| 180 net::CanonicalCookie* cookie = &user_cookies[0]; | 180 net::CanonicalCookie* cookie = &user_cookies[0]; |
| 181 EXPECT_EQ(kSAMLIdPCookieURL, cookie->Source()); |
| 182 EXPECT_EQ(kCookieName, cookie->Name()); |
| 183 EXPECT_EQ(expected_saml_idp_cookie_value, cookie->Value()); |
| 184 EXPECT_EQ(kSAMLIdPCookieDomain, cookie->Domain()); |
| 185 cookie = &user_cookies[1]; |
| 181 EXPECT_EQ(kGAIACookieURL, cookie->Source()); | 186 EXPECT_EQ(kGAIACookieURL, cookie->Source()); |
| 182 EXPECT_EQ(kCookieName, cookie->Name()); | 187 EXPECT_EQ(kCookieName, cookie->Name()); |
| 183 EXPECT_EQ(expected_gaia_cookie_value, cookie->Value()); | 188 EXPECT_EQ(expected_gaia_cookie_value, cookie->Value()); |
| 184 cookie = &user_cookies[1]; | 189 EXPECT_EQ(kGAIACookieDomain, cookie->Domain()); |
| 185 EXPECT_EQ(kSAMLIdPCookieURL, cookie->Source()); | |
| 186 EXPECT_EQ(kCookieName, cookie->Name()); | |
| 187 EXPECT_EQ(expected_saml_idp_cookie_value, cookie->Value()); | |
| 188 } | 190 } |
| 189 | 191 |
| 190 void ProfileAuthDataTest::VerifyUserChannelID( | 192 void ProfileAuthDataTest::VerifyUserChannelID( |
| 191 const std::string& expected_private_key, | 193 const std::string& expected_private_key, |
| 192 const std::string& expected_cert) { | 194 const std::string& expected_cert) { |
| 193 net::ChannelIDStore::ChannelIDList user_channel_ids = GetUserChannelIDs(); | 195 net::ChannelIDStore::ChannelIDList user_channel_ids = GetUserChannelIDs(); |
| 194 ASSERT_EQ(1u, user_channel_ids.size()); | 196 ASSERT_EQ(1u, user_channel_ids.size()); |
| 195 net::ChannelIDStore::ChannelID* channel_id = &user_channel_ids.front(); | 197 net::ChannelIDStore::ChannelID* channel_id = &user_channel_ids.front(); |
| 196 EXPECT_EQ(kChannelIDServerIdentifier, channel_id->server_identifier()); | 198 EXPECT_EQ(kChannelIDServerIdentifier, channel_id->server_identifier()); |
| 197 EXPECT_EQ(expected_private_key, channel_id->private_key()); | 199 EXPECT_EQ(expected_private_key, channel_id->private_key()); |
| 198 EXPECT_EQ(expected_cert, channel_id->cert()); | 200 EXPECT_EQ(expected_cert, channel_id->cert()); |
| 199 } | 201 } |
| 200 | 202 |
| 201 void ProfileAuthDataTest::PopulateBrowserContext( | 203 void ProfileAuthDataTest::PopulateBrowserContext( |
| 202 content::BrowserContext* browser_context, | 204 content::BrowserContext* browser_context, |
| 203 const std::string& proxy_auth_password, | 205 const std::string& proxy_auth_password, |
| 204 const std::string& cookie_value, | 206 const std::string& cookie_value, |
| 205 const std::string& channel_id_private_key, | 207 const std::string& channel_id_private_key, |
| 206 const std::string& channel_id_cert) { | 208 const std::string& channel_id_cert) { |
| 207 GetProxyAuth(browser_context)->Add( | 209 GetProxyAuth(browser_context)->Add( |
| 208 GURL(kProxyAuthURL), | 210 GURL(kProxyAuthURL), |
| 209 kProxyAuthRealm, | 211 kProxyAuthRealm, |
| 210 net::HttpAuth::AUTH_SCHEME_BASIC, | 212 net::HttpAuth::AUTH_SCHEME_BASIC, |
| 211 kProxyAuthChallenge, | 213 kProxyAuthChallenge, |
| 212 net::AuthCredentials(base::string16(), | 214 net::AuthCredentials(base::string16(), |
| 213 base::ASCIIToUTF16(proxy_auth_password)), | 215 base::ASCIIToUTF16(proxy_auth_password)), |
| 214 std::string()); | 216 std::string()); |
| 215 | 217 |
| 216 net::CookieMonster* cookies = GetCookies(browser_context); | 218 net::CookieMonster* cookies = GetCookies(browser_context); |
| 219 // Ensure |cookies| is fully initialized. |
| 217 run_loop_.reset(new base::RunLoop); | 220 run_loop_.reset(new base::RunLoop); |
| 218 cookies->SetCookieWithDetailsAsync( | 221 cookies->GetAllCookiesAsync(base::Bind(&ProfileAuthDataTest::QuitLoop, |
| 219 GURL(kGAIACookieURL), | 222 base::Unretained(this))); |
| 220 kCookieName, | |
| 221 cookie_value, | |
| 222 kGAIACookieDomain, | |
| 223 std::string(), | |
| 224 base::Time(), | |
| 225 true, | |
| 226 false, | |
| 227 net::COOKIE_PRIORITY_DEFAULT, | |
| 228 base::Bind(&ProfileAuthDataTest::QuitLoop, base::Unretained(this))); | |
| 229 run_loop_->Run(); | 223 run_loop_->Run(); |
| 230 run_loop_.reset(new base::RunLoop); | 224 |
| 231 cookies->SetCookieWithDetailsAsync( | 225 net::CookieList cookie_list; |
| 232 GURL(kSAMLIdPCookieURL), | 226 cookie_list.push_back(net::CanonicalCookie(GURL(kGAIACookieURL), |
| 233 kCookieName, | 227 kCookieName, |
| 234 cookie_value, | 228 cookie_value, |
| 235 kSAMLIdPCookieDomain, | 229 kGAIACookieDomain, |
| 236 std::string(), | 230 std::string(), |
| 237 base::Time(), | 231 base::Time(), |
| 238 true, | 232 base::Time(), |
| 239 false, | 233 base::Time(), |
| 240 net::COOKIE_PRIORITY_DEFAULT, | 234 true, |
| 241 base::Bind(&ProfileAuthDataTest::QuitLoop, base::Unretained(this))); | 235 false, |
| 242 run_loop_->Run(); | 236 net::COOKIE_PRIORITY_DEFAULT)); |
| 237 cookie_list.push_back(net::CanonicalCookie(GURL(kSAMLIdPCookieURL), |
| 238 kCookieName, |
| 239 cookie_value, |
| 240 kSAMLIdPCookieDomain, |
| 241 std::string(), |
| 242 base::Time(), |
| 243 base::Time(), |
| 244 base::Time(), |
| 245 true, |
| 246 false, |
| 247 net::COOKIE_PRIORITY_DEFAULT)); |
| 248 cookies->ImportCookies(cookie_list); |
| 243 | 249 |
| 244 GetChannelIDs(browser_context)->SetChannelID(kChannelIDServerIdentifier, | 250 GetChannelIDs(browser_context)->SetChannelID(kChannelIDServerIdentifier, |
| 245 base::Time(), | 251 base::Time(), |
| 246 base::Time(), | 252 base::Time(), |
| 247 channel_id_private_key, | 253 channel_id_private_key, |
| 248 channel_id_cert); | 254 channel_id_cert); |
| 249 } | 255 } |
| 250 | 256 |
| 251 net::URLRequestContext* ProfileAuthDataTest::GetRequestContext( | 257 net::URLRequestContext* ProfileAuthDataTest::GetRequestContext( |
| 252 content::BrowserContext* browser_context) { | 258 content::BrowserContext* browser_context) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 263 content::BrowserContext* browser_context) { | 269 content::BrowserContext* browser_context) { |
| 264 return GetRequestContext(browser_context)->cookie_store()->GetCookieMonster(); | 270 return GetRequestContext(browser_context)->cookie_store()->GetCookieMonster(); |
| 265 } | 271 } |
| 266 | 272 |
| 267 net::ChannelIDStore* ProfileAuthDataTest::GetChannelIDs( | 273 net::ChannelIDStore* ProfileAuthDataTest::GetChannelIDs( |
| 268 content::BrowserContext* browser_context) { | 274 content::BrowserContext* browser_context) { |
| 269 return GetRequestContext(browser_context)->channel_id_service()-> | 275 return GetRequestContext(browser_context)->channel_id_service()-> |
| 270 GetChannelIDStore(); | 276 GetChannelIDStore(); |
| 271 } | 277 } |
| 272 | 278 |
| 273 void ProfileAuthDataTest::QuitLoop(bool ignored) { | 279 void ProfileAuthDataTest::QuitLoop(const net::CookieList& ignored) { |
| 274 run_loop_->Quit(); | 280 run_loop_->Quit(); |
| 275 } | 281 } |
| 276 | 282 |
| 277 void ProfileAuthDataTest::StoreCookieListAndQuitLoop( | 283 void ProfileAuthDataTest::StoreCookieListAndQuitLoop( |
| 278 const net::CookieList& cookie_list) { | 284 const net::CookieList& cookie_list) { |
| 279 user_cookie_list_ = cookie_list; | 285 user_cookie_list_ = cookie_list; |
| 280 run_loop_->Quit(); | 286 run_loop_->Quit(); |
| 281 } | 287 } |
| 282 | 288 |
| 283 void ProfileAuthDataTest::StoreChannelIDListAndQuitLoop( | 289 void ProfileAuthDataTest::StoreChannelIDListAndQuitLoop( |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 PopulateUserBrowserContext(); | 333 PopulateUserBrowserContext(); |
| 328 | 334 |
| 329 Transfer(false, true); | 335 Transfer(false, true); |
| 330 | 336 |
| 331 VerifyTransferredUserProxyAuthEntry(); | 337 VerifyTransferredUserProxyAuthEntry(); |
| 332 VerifyUserCookies(kCookieValue2, kCookieValue1); | 338 VerifyUserCookies(kCookieValue2, kCookieValue1); |
| 333 VerifyUserChannelID(kChannelIDPrivateKey2, kChannelIDCert2); | 339 VerifyUserChannelID(kChannelIDPrivateKey2, kChannelIDCert2); |
| 334 } | 340 } |
| 335 | 341 |
| 336 } // namespace chromeos | 342 } // namespace chromeos |
| OLD | NEW |