| 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 <memory> |
| 7 #include <string> | 8 #include <string> |
| 8 #include <utility> | 9 #include <utility> |
| 9 | 10 |
| 10 #include "base/bind.h" | 11 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
| 12 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
| 13 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/ptr_util.h" |
| 14 #include "base/run_loop.h" | 15 #include "base/run_loop.h" |
| 15 #include "base/strings/string16.h" | 16 #include "base/strings/string16.h" |
| 16 #include "base/strings/utf_string_conversions.h" | 17 #include "base/strings/utf_string_conversions.h" |
| 17 #include "base/time/time.h" | 18 #include "base/time/time.h" |
| 18 #include "chrome/test/base/testing_profile.h" | 19 #include "chrome/test/base/testing_profile.h" |
| 19 #include "content/public/browser/browser_context.h" | 20 #include "content/public/browser/browser_context.h" |
| 20 #include "content/public/test/test_browser_thread_bundle.h" | 21 #include "content/public/test/test_browser_thread_bundle.h" |
| 21 #include "net/cookies/canonical_cookie.h" | 22 #include "net/cookies/canonical_cookie.h" |
| 22 #include "net/cookies/cookie_constants.h" | 23 #include "net/cookies/cookie_constants.h" |
| 23 #include "net/cookies/cookie_store.h" | 24 #include "net/cookies/cookie_store.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 | 69 |
| 69 net::CookieList GetUserCookies(); | 70 net::CookieList GetUserCookies(); |
| 70 net::ChannelIDStore::ChannelIDList GetUserChannelIDs(); | 71 net::ChannelIDStore::ChannelIDList GetUserChannelIDs(); |
| 71 | 72 |
| 72 void VerifyTransferredUserProxyAuthEntry(); | 73 void VerifyTransferredUserProxyAuthEntry(); |
| 73 void VerifyUserCookies(const std::string& expected_gaia_cookie_value, | 74 void VerifyUserCookies(const std::string& expected_gaia_cookie_value, |
| 74 const std::string& expected_saml_idp_cookie_value); | 75 const std::string& expected_saml_idp_cookie_value); |
| 75 void VerifyUserChannelID(crypto::ECPrivateKey* expected_key); | 76 void VerifyUserChannelID(crypto::ECPrivateKey* expected_key); |
| 76 | 77 |
| 77 protected: | 78 protected: |
| 78 scoped_ptr<crypto::ECPrivateKey> channel_id_key1_; | 79 std::unique_ptr<crypto::ECPrivateKey> channel_id_key1_; |
| 79 scoped_ptr<crypto::ECPrivateKey> channel_id_key2_; | 80 std::unique_ptr<crypto::ECPrivateKey> channel_id_key2_; |
| 80 | 81 |
| 81 private: | 82 private: |
| 82 void PopulateBrowserContext(content::BrowserContext* browser_context, | 83 void PopulateBrowserContext( |
| 83 const std::string& proxy_auth_password, | 84 content::BrowserContext* browser_context, |
| 84 const std::string& cookie_value, | 85 const std::string& proxy_auth_password, |
| 85 scoped_ptr<crypto::ECPrivateKey> channel_id_key); | 86 const std::string& cookie_value, |
| 87 std::unique_ptr<crypto::ECPrivateKey> channel_id_key); |
| 86 | 88 |
| 87 net::URLRequestContext* GetRequestContext( | 89 net::URLRequestContext* GetRequestContext( |
| 88 content::BrowserContext* browser_context); | 90 content::BrowserContext* browser_context); |
| 89 net::HttpAuthCache* GetProxyAuth(content::BrowserContext* browser_context); | 91 net::HttpAuthCache* GetProxyAuth(content::BrowserContext* browser_context); |
| 90 net::CookieStore* GetCookies(content::BrowserContext* browser_context); | 92 net::CookieStore* GetCookies(content::BrowserContext* browser_context); |
| 91 net::ChannelIDStore* GetChannelIDs(content::BrowserContext* browser_context); | 93 net::ChannelIDStore* GetChannelIDs(content::BrowserContext* browser_context); |
| 92 | 94 |
| 93 void QuitLoop(const net::CookieList& ignored); | 95 void QuitLoop(const net::CookieList& ignored); |
| 94 void StoreCookieListAndQuitLoop(const net::CookieList& cookie_list); | 96 void StoreCookieListAndQuitLoop(const net::CookieList& cookie_list); |
| 95 void StoreChannelIDListAndQuitLoop( | 97 void StoreChannelIDListAndQuitLoop( |
| 96 const net::ChannelIDStore::ChannelIDList& channel_id_list); | 98 const net::ChannelIDStore::ChannelIDList& channel_id_list); |
| 97 | 99 |
| 98 content::TestBrowserThreadBundle thread_bundle_; | 100 content::TestBrowserThreadBundle thread_bundle_; |
| 99 | 101 |
| 100 TestingProfile login_browser_context_; | 102 TestingProfile login_browser_context_; |
| 101 TestingProfile user_browser_context_; | 103 TestingProfile user_browser_context_; |
| 102 | 104 |
| 103 net::CookieList user_cookie_list_; | 105 net::CookieList user_cookie_list_; |
| 104 net::ChannelIDStore::ChannelIDList user_channel_id_list_; | 106 net::ChannelIDStore::ChannelIDList user_channel_id_list_; |
| 105 | 107 |
| 106 scoped_ptr<base::RunLoop> run_loop_; | 108 std::unique_ptr<base::RunLoop> run_loop_; |
| 107 }; | 109 }; |
| 108 | 110 |
| 109 void ProfileAuthDataTest::SetUp() { | 111 void ProfileAuthDataTest::SetUp() { |
| 110 channel_id_key1_.reset(crypto::ECPrivateKey::Create()); | 112 channel_id_key1_.reset(crypto::ECPrivateKey::Create()); |
| 111 channel_id_key2_.reset(crypto::ECPrivateKey::Create()); | 113 channel_id_key2_.reset(crypto::ECPrivateKey::Create()); |
| 112 PopulateBrowserContext(&login_browser_context_, kProxyAuthPassword1, | 114 PopulateBrowserContext(&login_browser_context_, kProxyAuthPassword1, |
| 113 kCookieValue1, | 115 kCookieValue1, |
| 114 make_scoped_ptr(channel_id_key1_->Copy())); | 116 base::WrapUnique(channel_id_key1_->Copy())); |
| 115 } | 117 } |
| 116 | 118 |
| 117 void ProfileAuthDataTest::PopulateUserBrowserContext() { | 119 void ProfileAuthDataTest::PopulateUserBrowserContext() { |
| 118 PopulateBrowserContext(&user_browser_context_, kProxyAuthPassword2, | 120 PopulateBrowserContext(&user_browser_context_, kProxyAuthPassword2, |
| 119 kCookieValue2, | 121 kCookieValue2, |
| 120 make_scoped_ptr(channel_id_key2_->Copy())); | 122 base::WrapUnique(channel_id_key2_->Copy())); |
| 121 } | 123 } |
| 122 | 124 |
| 123 void ProfileAuthDataTest::Transfer( | 125 void ProfileAuthDataTest::Transfer( |
| 124 bool transfer_auth_cookies_and_channel_ids_on_first_login, | 126 bool transfer_auth_cookies_and_channel_ids_on_first_login, |
| 125 bool transfer_saml_auth_cookies_on_subsequent_login) { | 127 bool transfer_saml_auth_cookies_on_subsequent_login) { |
| 126 base::RunLoop run_loop; | 128 base::RunLoop run_loop; |
| 127 ProfileAuthData::Transfer( | 129 ProfileAuthData::Transfer( |
| 128 login_browser_context_.GetRequestContext(), | 130 login_browser_context_.GetRequestContext(), |
| 129 user_browser_context_.GetRequestContext(), | 131 user_browser_context_.GetRequestContext(), |
| 130 transfer_auth_cookies_and_channel_ids_on_first_login, | 132 transfer_auth_cookies_and_channel_ids_on_first_login, |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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_TRUE(net::KeysEqual(expected_key, channel_id->key())); | 199 EXPECT_TRUE(net::KeysEqual(expected_key, channel_id->key())); |
| 198 } | 200 } |
| 199 | 201 |
| 200 void ProfileAuthDataTest::PopulateBrowserContext( | 202 void ProfileAuthDataTest::PopulateBrowserContext( |
| 201 content::BrowserContext* browser_context, | 203 content::BrowserContext* browser_context, |
| 202 const std::string& proxy_auth_password, | 204 const std::string& proxy_auth_password, |
| 203 const std::string& cookie_value, | 205 const std::string& cookie_value, |
| 204 scoped_ptr<crypto::ECPrivateKey> channel_id_key) { | 206 std::unique_ptr<crypto::ECPrivateKey> channel_id_key) { |
| 205 GetProxyAuth(browser_context)->Add( | 207 GetProxyAuth(browser_context)->Add( |
| 206 GURL(kProxyAuthURL), | 208 GURL(kProxyAuthURL), |
| 207 kProxyAuthRealm, | 209 kProxyAuthRealm, |
| 208 net::HttpAuth::AUTH_SCHEME_BASIC, | 210 net::HttpAuth::AUTH_SCHEME_BASIC, |
| 209 kProxyAuthChallenge, | 211 kProxyAuthChallenge, |
| 210 net::AuthCredentials(base::string16(), | 212 net::AuthCredentials(base::string16(), |
| 211 base::ASCIIToUTF16(proxy_auth_password)), | 213 base::ASCIIToUTF16(proxy_auth_password)), |
| 212 std::string()); | 214 std::string()); |
| 213 | 215 |
| 214 net::CookieStore* cookies = GetCookies(browser_context); | 216 net::CookieStore* cookies = GetCookies(browser_context); |
| 215 // Ensure |cookies| is fully initialized. | 217 // Ensure |cookies| is fully initialized. |
| 216 run_loop_.reset(new base::RunLoop); | 218 run_loop_.reset(new base::RunLoop); |
| 217 cookies->GetAllCookiesAsync(base::Bind(&ProfileAuthDataTest::QuitLoop, | 219 cookies->GetAllCookiesAsync(base::Bind(&ProfileAuthDataTest::QuitLoop, |
| 218 base::Unretained(this))); | 220 base::Unretained(this))); |
| 219 run_loop_->Run(); | 221 run_loop_->Run(); |
| 220 | 222 |
| 221 cookies->SetCookieWithDetailsAsync( | 223 cookies->SetCookieWithDetailsAsync( |
| 222 GURL(kSAMLIdPCookieURL), kCookieName, cookie_value, std::string(), | 224 GURL(kSAMLIdPCookieURL), kCookieName, cookie_value, std::string(), |
| 223 std::string(), base::Time(), base::Time(), base::Time(), true, false, | 225 std::string(), base::Time(), base::Time(), base::Time(), true, false, |
| 224 net::CookieSameSite::DEFAULT_MODE, false, net::COOKIE_PRIORITY_DEFAULT, | 226 net::CookieSameSite::DEFAULT_MODE, false, net::COOKIE_PRIORITY_DEFAULT, |
| 225 net::CookieStore::SetCookiesCallback()); | 227 net::CookieStore::SetCookiesCallback()); |
| 226 cookies->SetCookieWithDetailsAsync( | 228 cookies->SetCookieWithDetailsAsync( |
| 227 GURL(kGAIACookieURL), kCookieName, cookie_value, std::string(), | 229 GURL(kGAIACookieURL), kCookieName, cookie_value, std::string(), |
| 228 std::string(), base::Time(), base::Time(), base::Time(), true, false, | 230 std::string(), base::Time(), base::Time(), base::Time(), true, false, |
| 229 net::CookieSameSite::DEFAULT_MODE, false, net::COOKIE_PRIORITY_DEFAULT, | 231 net::CookieSameSite::DEFAULT_MODE, false, net::COOKIE_PRIORITY_DEFAULT, |
| 230 net::CookieStore::SetCookiesCallback()); | 232 net::CookieStore::SetCookiesCallback()); |
| 231 | 233 |
| 232 GetChannelIDs(browser_context) | 234 GetChannelIDs(browser_context) |
| 233 ->SetChannelID(make_scoped_ptr(new net::ChannelIDStore::ChannelID( | 235 ->SetChannelID(base::WrapUnique(new net::ChannelIDStore::ChannelID( |
| 234 kChannelIDServerIdentifier, base::Time(), | 236 kChannelIDServerIdentifier, base::Time(), |
| 235 std::move(channel_id_key)))); | 237 std::move(channel_id_key)))); |
| 236 } | 238 } |
| 237 | 239 |
| 238 net::URLRequestContext* ProfileAuthDataTest::GetRequestContext( | 240 net::URLRequestContext* ProfileAuthDataTest::GetRequestContext( |
| 239 content::BrowserContext* browser_context) { | 241 content::BrowserContext* browser_context) { |
| 240 return browser_context->GetRequestContext()->GetURLRequestContext(); | 242 return browser_context->GetRequestContext()->GetURLRequestContext(); |
| 241 } | 243 } |
| 242 | 244 |
| 243 net::HttpAuthCache* ProfileAuthDataTest::GetProxyAuth( | 245 net::HttpAuthCache* ProfileAuthDataTest::GetProxyAuth( |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 PopulateUserBrowserContext(); | 316 PopulateUserBrowserContext(); |
| 315 | 317 |
| 316 Transfer(false, true); | 318 Transfer(false, true); |
| 317 | 319 |
| 318 VerifyTransferredUserProxyAuthEntry(); | 320 VerifyTransferredUserProxyAuthEntry(); |
| 319 VerifyUserCookies(kCookieValue2, kCookieValue1); | 321 VerifyUserCookies(kCookieValue2, kCookieValue1); |
| 320 VerifyUserChannelID(channel_id_key2_.get()); | 322 VerifyUserChannelID(channel_id_key2_.get()); |
| 321 } | 323 } |
| 322 | 324 |
| 323 } // namespace chromeos | 325 } // namespace chromeos |
| OLD | NEW |