Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Side by Side Diff: chrome/browser/chromeos/login/saml/saml_browsertest.cc

Issue 1870793002: Convert //chrome/browser/chromeos from scoped_ptr to std::unique_ptr (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <cstring> 5 #include <cstring>
6 #include <memory>
6 #include <string> 7 #include <string>
7 #include <utility> 8 #include <utility>
8 9
9 #include "base/bind.h" 10 #include "base/bind.h"
10 #include "base/bind_helpers.h" 11 #include "base/bind_helpers.h"
11 #include "base/callback.h" 12 #include "base/callback.h"
12 #include "base/command_line.h" 13 #include "base/command_line.h"
13 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
14 #include "base/files/file_util.h" 15 #include "base/files/file_util.h"
15 #include "base/files/scoped_temp_dir.h" 16 #include "base/files/scoped_temp_dir.h"
16 #include "base/location.h" 17 #include "base/location.h"
17 #include "base/macros.h" 18 #include "base/macros.h"
18 #include "base/memory/ref_counted.h" 19 #include "base/memory/ref_counted.h"
19 #include "base/memory/scoped_ptr.h"
20 #include "base/path_service.h" 20 #include "base/path_service.h"
21 #include "base/run_loop.h" 21 #include "base/run_loop.h"
22 #include "base/strings/string16.h" 22 #include "base/strings/string16.h"
23 #include "base/strings/string_util.h" 23 #include "base/strings/string_util.h"
24 #include "base/strings/stringprintf.h" 24 #include "base/strings/stringprintf.h"
25 #include "base/strings/utf_string_conversions.h" 25 #include "base/strings/utf_string_conversions.h"
26 #include "base/values.h" 26 #include "base/values.h"
27 #include "chrome/browser/chrome_notification_types.h" 27 #include "chrome/browser/chrome_notification_types.h"
28 #include "chrome/browser/chromeos/login/existing_user_controller.h" 28 #include "chrome/browser/chromeos/login/existing_user_controller.h"
29 #include "chrome/browser/chromeos/login/startup_utils.h" 29 #include "chrome/browser/chromeos/login/startup_utils.h"
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 FakeSamlIdp(); 146 FakeSamlIdp();
147 ~FakeSamlIdp(); 147 ~FakeSamlIdp();
148 148
149 void SetUp(const std::string& base_path, const GURL& gaia_url); 149 void SetUp(const std::string& base_path, const GURL& gaia_url);
150 150
151 void SetLoginHTMLTemplate(const std::string& template_file); 151 void SetLoginHTMLTemplate(const std::string& template_file);
152 void SetLoginAuthHTMLTemplate(const std::string& template_file); 152 void SetLoginAuthHTMLTemplate(const std::string& template_file);
153 void SetRefreshURL(const GURL& refresh_url); 153 void SetRefreshURL(const GURL& refresh_url);
154 void SetCookieValue(const std::string& cookie_value); 154 void SetCookieValue(const std::string& cookie_value);
155 155
156 scoped_ptr<HttpResponse> HandleRequest(const HttpRequest& request); 156 std::unique_ptr<HttpResponse> HandleRequest(const HttpRequest& request);
157 157
158 private: 158 private:
159 scoped_ptr<HttpResponse> BuildHTMLResponse(const std::string& html_template, 159 std::unique_ptr<HttpResponse> BuildHTMLResponse(
160 const std::string& relay_state, 160 const std::string& html_template,
161 const std::string& next_path); 161 const std::string& relay_state,
162 const std::string& next_path);
162 163
163 base::FilePath html_template_dir_; 164 base::FilePath html_template_dir_;
164 165
165 std::string login_path_; 166 std::string login_path_;
166 std::string login_auth_path_; 167 std::string login_auth_path_;
167 168
168 std::string login_html_template_; 169 std::string login_html_template_;
169 std::string login_auth_html_template_; 170 std::string login_auth_html_template_;
170 GURL gaia_assertion_url_; 171 GURL gaia_assertion_url_;
171 GURL refresh_url_; 172 GURL refresh_url_;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 } 204 }
204 205
205 void FakeSamlIdp::SetRefreshURL(const GURL& refresh_url) { 206 void FakeSamlIdp::SetRefreshURL(const GURL& refresh_url) {
206 refresh_url_ = refresh_url; 207 refresh_url_ = refresh_url;
207 } 208 }
208 209
209 void FakeSamlIdp::SetCookieValue(const std::string& cookie_value) { 210 void FakeSamlIdp::SetCookieValue(const std::string& cookie_value) {
210 cookie_value_ = cookie_value; 211 cookie_value_ = cookie_value;
211 } 212 }
212 213
213 scoped_ptr<HttpResponse> FakeSamlIdp::HandleRequest( 214 std::unique_ptr<HttpResponse> FakeSamlIdp::HandleRequest(
214 const HttpRequest& request) { 215 const HttpRequest& request) {
215 // The scheme and host of the URL is actually not important but required to 216 // The scheme and host of the URL is actually not important but required to
216 // get a valid GURL in order to parse |request.relative_url|. 217 // get a valid GURL in order to parse |request.relative_url|.
217 GURL request_url = GURL("http://localhost").Resolve(request.relative_url); 218 GURL request_url = GURL("http://localhost").Resolve(request.relative_url);
218 std::string request_path = request_url.path(); 219 std::string request_path = request_url.path();
219 220
220 if (request_path == login_path_) { 221 if (request_path == login_path_) {
221 std::string relay_state; 222 std::string relay_state;
222 net::GetValueForKeyInQuery(request_url, kRelayState, &relay_state); 223 net::GetValueForKeyInQuery(request_url, kRelayState, &relay_state);
223 return BuildHTMLResponse(login_html_template_, 224 return BuildHTMLResponse(login_html_template_,
224 relay_state, 225 relay_state,
225 login_auth_path_); 226 login_auth_path_);
226 } 227 }
227 228
228 if (request_path != login_auth_path_) { 229 if (request_path != login_auth_path_) {
229 // Request not understood. 230 // Request not understood.
230 return scoped_ptr<HttpResponse>(); 231 return std::unique_ptr<HttpResponse>();
231 } 232 }
232 233
233 std::string relay_state; 234 std::string relay_state;
234 FakeGaia::GetQueryParameter(request.content, kRelayState, &relay_state); 235 FakeGaia::GetQueryParameter(request.content, kRelayState, &relay_state);
235 GURL redirect_url = gaia_assertion_url_; 236 GURL redirect_url = gaia_assertion_url_;
236 237
237 if (!login_auth_html_template_.empty()) { 238 if (!login_auth_html_template_.empty()) {
238 return BuildHTMLResponse(login_auth_html_template_, 239 return BuildHTMLResponse(login_auth_html_template_,
239 relay_state, 240 relay_state,
240 redirect_url.spec()); 241 redirect_url.spec());
241 } 242 }
242 243
243 redirect_url = net::AppendQueryParameter( 244 redirect_url = net::AppendQueryParameter(
244 redirect_url, "SAMLResponse", "fake_response"); 245 redirect_url, "SAMLResponse", "fake_response");
245 redirect_url = net::AppendQueryParameter( 246 redirect_url = net::AppendQueryParameter(
246 redirect_url, kRelayState, relay_state); 247 redirect_url, kRelayState, relay_state);
247 248
248 scoped_ptr<BasicHttpResponse> http_response(new BasicHttpResponse()); 249 std::unique_ptr<BasicHttpResponse> http_response(new BasicHttpResponse());
249 http_response->set_code(net::HTTP_TEMPORARY_REDIRECT); 250 http_response->set_code(net::HTTP_TEMPORARY_REDIRECT);
250 http_response->AddCustomHeader("Location", redirect_url.spec()); 251 http_response->AddCustomHeader("Location", redirect_url.spec());
251 http_response->AddCustomHeader( 252 http_response->AddCustomHeader(
252 "Set-cookie", 253 "Set-cookie",
253 base::StringPrintf("saml=%s", cookie_value_.c_str())); 254 base::StringPrintf("saml=%s", cookie_value_.c_str()));
254 return std::move(http_response); 255 return std::move(http_response);
255 } 256 }
256 257
257 scoped_ptr<HttpResponse> FakeSamlIdp::BuildHTMLResponse( 258 std::unique_ptr<HttpResponse> FakeSamlIdp::BuildHTMLResponse(
258 const std::string& html_template, 259 const std::string& html_template,
259 const std::string& relay_state, 260 const std::string& relay_state,
260 const std::string& next_path) { 261 const std::string& next_path) {
261 std::string response_html = html_template; 262 std::string response_html = html_template;
262 base::ReplaceSubstringsAfterOffset( 263 base::ReplaceSubstringsAfterOffset(
263 &response_html, 0, "$RelayState", relay_state); 264 &response_html, 0, "$RelayState", relay_state);
264 base::ReplaceSubstringsAfterOffset( 265 base::ReplaceSubstringsAfterOffset(
265 &response_html, 0, "$Post", next_path); 266 &response_html, 0, "$Post", next_path);
266 base::ReplaceSubstringsAfterOffset( 267 base::ReplaceSubstringsAfterOffset(
267 &response_html, 0, "$Refresh", refresh_url_.spec()); 268 &response_html, 0, "$Refresh", refresh_url_.spec());
268 269
269 scoped_ptr<BasicHttpResponse> http_response(new BasicHttpResponse()); 270 std::unique_ptr<BasicHttpResponse> http_response(new BasicHttpResponse());
270 http_response->set_code(net::HTTP_OK); 271 http_response->set_code(net::HTTP_OK);
271 http_response->set_content(response_html); 272 http_response->set_content(response_html);
272 http_response->set_content_type("text/html"); 273 http_response->set_content_type("text/html");
273 274
274 return std::move(http_response); 275 return std::move(http_response);
275 } 276 }
276 277
277 // A FakeCryptohomeClient that stores the salted and hashed secret passed to 278 // A FakeCryptohomeClient that stores the salted and hashed secret passed to
278 // MountEx(). 279 // MountEx().
279 class SecretInterceptingFakeCryptohomeClient : public FakeCryptohomeClient { 280 class SecretInterceptingFakeCryptohomeClient : public FakeCryptohomeClient {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
329 kHTTPSAMLUserEmail, 330 kHTTPSAMLUserEmail,
330 embedded_test_server()->base_url().Resolve("/SAML")); 331 embedded_test_server()->base_url().Resolve("/SAML"));
331 fake_gaia_->RegisterSamlUser(kDifferentDomainSAMLUserEmail, saml_idp_url); 332 fake_gaia_->RegisterSamlUser(kDifferentDomainSAMLUserEmail, saml_idp_url);
332 fake_gaia_->RegisterSamlDomainRedirectUrl("example.com", saml_idp_url); 333 fake_gaia_->RegisterSamlDomainRedirectUrl("example.com", saml_idp_url);
333 334
334 OobeBaseTest::SetUpCommandLine(command_line); 335 OobeBaseTest::SetUpCommandLine(command_line);
335 } 336 }
336 337
337 void SetUpInProcessBrowserTestFixture() override { 338 void SetUpInProcessBrowserTestFixture() override {
338 DBusThreadManager::GetSetterForTesting()->SetCryptohomeClient( 339 DBusThreadManager::GetSetterForTesting()->SetCryptohomeClient(
339 scoped_ptr<CryptohomeClient>(cryptohome_client_)); 340 std::unique_ptr<CryptohomeClient>(cryptohome_client_));
340 341
341 OobeBaseTest::SetUpInProcessBrowserTestFixture(); 342 OobeBaseTest::SetUpInProcessBrowserTestFixture();
342 } 343 }
343 344
344 void SetUpOnMainThread() override { 345 void SetUpOnMainThread() override {
345 fake_gaia_->SetFakeMergeSessionParams( 346 fake_gaia_->SetFakeMergeSessionParams(
346 kFirstSAMLUserEmail, kTestAuthSIDCookie1, kTestAuthLSIDCookie1); 347 kFirstSAMLUserEmail, kTestAuthSIDCookie1, kTestAuthLSIDCookie1);
347 348
348 embedded_test_server()->RegisterRequestHandler(base::Bind( 349 embedded_test_server()->RegisterRequestHandler(base::Bind(
349 &FakeSamlIdp::HandleRequest, base::Unretained(&fake_saml_idp_))); 350 &FakeSamlIdp::HandleRequest, base::Unretained(&fake_saml_idp_)));
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
746 747
747 // content::WebContentsObserver: 748 // content::WebContentsObserver:
748 void DidFinishLoad(content::RenderFrameHost* render_frame_host, 749 void DidFinishLoad(content::RenderFrameHost* render_frame_host,
749 const GURL& validated_url) override; 750 const GURL& validated_url) override;
750 751
751 void WaitForEnrollmentSuccess(); 752 void WaitForEnrollmentSuccess();
752 guest_view::TestGuestViewManager* GetGuestViewManager(); 753 guest_view::TestGuestViewManager* GetGuestViewManager();
753 content::WebContents* GetEnrollmentContents(); 754 content::WebContents* GetEnrollmentContents();
754 755
755 private: 756 private:
756 scoped_ptr<policy::LocalPolicyTestServer> test_server_; 757 std::unique_ptr<policy::LocalPolicyTestServer> test_server_;
757 base::ScopedTempDir temp_dir_; 758 base::ScopedTempDir temp_dir_;
758 759
759 scoped_ptr<base::RunLoop> run_loop_; 760 std::unique_ptr<base::RunLoop> run_loop_;
760 761
761 guest_view::TestGuestViewManagerFactory guest_view_manager_factory_; 762 guest_view::TestGuestViewManagerFactory guest_view_manager_factory_;
762 763
763 DISALLOW_COPY_AND_ASSIGN(SAMLEnrollmentTest); 764 DISALLOW_COPY_AND_ASSIGN(SAMLEnrollmentTest);
764 }; 765 };
765 766
766 SAMLEnrollmentTest::SAMLEnrollmentTest() { 767 SAMLEnrollmentTest::SAMLEnrollmentTest() {
767 guest_view::GuestViewManager::set_factory_for_testing( 768 guest_view::GuestViewManager::set_factory_for_testing(
768 &guest_view_manager_factory_); 769 &guest_view_manager_factory_);
769 gaia_frame_parent_ = "oauth-enroll-auth-view"; 770 gaia_frame_parent_ = "oauth-enroll-auth-view";
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
950 SAMLPolicyTest::SAMLPolicyTest() 951 SAMLPolicyTest::SAMLPolicyTest()
951 : fake_session_manager_client_(new FakeSessionManagerClient), 952 : fake_session_manager_client_(new FakeSessionManagerClient),
952 device_policy_(test_helper_.device_policy()) { 953 device_policy_(test_helper_.device_policy()) {
953 } 954 }
954 955
955 SAMLPolicyTest::~SAMLPolicyTest() { 956 SAMLPolicyTest::~SAMLPolicyTest() {
956 } 957 }
957 958
958 void SAMLPolicyTest::SetUpInProcessBrowserTestFixture() { 959 void SAMLPolicyTest::SetUpInProcessBrowserTestFixture() {
959 DBusThreadManager::GetSetterForTesting()->SetSessionManagerClient( 960 DBusThreadManager::GetSetterForTesting()->SetSessionManagerClient(
960 scoped_ptr<SessionManagerClient>(fake_session_manager_client_)); 961 std::unique_ptr<SessionManagerClient>(fake_session_manager_client_));
961 962
962 SamlTest::SetUpInProcessBrowserTestFixture(); 963 SamlTest::SetUpInProcessBrowserTestFixture();
963 964
964 // Initialize device policy. 965 // Initialize device policy.
965 std::set<std::string> device_affiliation_ids; 966 std::set<std::string> device_affiliation_ids;
966 device_affiliation_ids.insert(kAffiliationID); 967 device_affiliation_ids.insert(kAffiliationID);
967 policy::affiliation_test_helper::SetDeviceAffiliationID( 968 policy::affiliation_test_helper::SetDeviceAffiliationID(
968 &test_helper_, fake_session_manager_client_, device_affiliation_ids); 969 &test_helper_, fake_session_manager_client_, device_affiliation_ids);
969 970
970 // Initialize user policy. 971 // Initialize user policy.
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
1016 NULL); 1017 NULL);
1017 provider_.UpdateChromePolicy(user_policy); 1018 provider_.UpdateChromePolicy(user_policy);
1018 base::RunLoop().RunUntilIdle(); 1019 base::RunLoop().RunUntilIdle();
1019 } 1020 }
1020 1021
1021 void SAMLPolicyTest::EnableTransferSAMLCookiesPolicy() { 1022 void SAMLPolicyTest::EnableTransferSAMLCookiesPolicy() {
1022 em::ChromeDeviceSettingsProto& proto(device_policy_->payload()); 1023 em::ChromeDeviceSettingsProto& proto(device_policy_->payload());
1023 proto.mutable_saml_settings()->set_transfer_saml_cookies(true); 1024 proto.mutable_saml_settings()->set_transfer_saml_cookies(true);
1024 1025
1025 base::RunLoop run_loop; 1026 base::RunLoop run_loop;
1026 scoped_ptr<CrosSettings::ObserverSubscription> observer = 1027 std::unique_ptr<CrosSettings::ObserverSubscription> observer =
1027 CrosSettings::Get()->AddSettingsObserver( 1028 CrosSettings::Get()->AddSettingsObserver(kAccountsPrefTransferSAMLCookies,
1028 kAccountsPrefTransferSAMLCookies, 1029 run_loop.QuitClosure());
1029 run_loop.QuitClosure());
1030 device_policy_->SetDefaultSigningKey(); 1030 device_policy_->SetDefaultSigningKey();
1031 device_policy_->Build(); 1031 device_policy_->Build();
1032 fake_session_manager_client_->set_device_policy(device_policy_->GetBlob()); 1032 fake_session_manager_client_->set_device_policy(device_policy_->GetBlob());
1033 fake_session_manager_client_->OnPropertyChangeComplete(true); 1033 fake_session_manager_client_->OnPropertyChangeComplete(true);
1034 run_loop.Run(); 1034 run_loop.Run();
1035 } 1035 }
1036 1036
1037 void SAMLPolicyTest::SetLoginBehaviorPolicyToSAMLInterstitial() { 1037 void SAMLPolicyTest::SetLoginBehaviorPolicyToSAMLInterstitial() {
1038 em::ChromeDeviceSettingsProto& proto(device_policy_->payload()); 1038 em::ChromeDeviceSettingsProto& proto(device_policy_->payload());
1039 proto.mutable_login_authentication_behavior() 1039 proto.mutable_login_authentication_behavior()
1040 ->set_login_authentication_behavior( 1040 ->set_login_authentication_behavior(
1041 em::LoginAuthenticationBehaviorProto_LoginBehavior_SAML_INTERSTITIAL); 1041 em::LoginAuthenticationBehaviorProto_LoginBehavior_SAML_INTERSTITIAL);
1042 1042
1043 base::RunLoop run_loop; 1043 base::RunLoop run_loop;
1044 scoped_ptr<CrosSettings::ObserverSubscription> observer = 1044 std::unique_ptr<CrosSettings::ObserverSubscription> observer =
1045 CrosSettings::Get()->AddSettingsObserver(kLoginAuthenticationBehavior, 1045 CrosSettings::Get()->AddSettingsObserver(kLoginAuthenticationBehavior,
1046 run_loop.QuitClosure()); 1046 run_loop.QuitClosure());
1047 device_policy_->SetDefaultSigningKey(); 1047 device_policy_->SetDefaultSigningKey();
1048 device_policy_->Build(); 1048 device_policy_->Build();
1049 fake_session_manager_client_->set_device_policy(device_policy_->GetBlob()); 1049 fake_session_manager_client_->set_device_policy(device_policy_->GetBlob());
1050 fake_session_manager_client_->OnPropertyChangeComplete(true); 1050 fake_session_manager_client_->OnPropertyChangeComplete(true);
1051 run_loop.Run(); 1051 run_loop.Run();
1052 } 1052 }
1053 1053
1054 void SAMLPolicyTest::ShowGAIALoginForm() { 1054 void SAMLPolicyTest::ShowGAIALoginForm() {
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
1358 chrome::NOTIFICATION_SESSION_STARTED, 1358 chrome::NOTIFICATION_SESSION_STARTED,
1359 content::NotificationService::AllSources()); 1359 content::NotificationService::AllSources());
1360 1360
1361 OobeScreenWaiter(OobeScreen::SCREEN_CONFIRM_PASSWORD).Wait(); 1361 OobeScreenWaiter(OobeScreen::SCREEN_CONFIRM_PASSWORD).Wait();
1362 SendConfirmPassword("fake_password"); 1362 SendConfirmPassword("fake_password");
1363 // Login should finish login and a session should start. 1363 // Login should finish login and a session should start.
1364 session_start_waiter.Wait(); 1364 session_start_waiter.Wait();
1365 } 1365 }
1366 1366
1367 } // namespace chromeos 1367 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/login/reset_browsertest.cc ('k') | chrome/browser/chromeos/login/saml/saml_offline_signin_limiter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698