]> git.openstreetmap.org Git - rails.git/blobdiff - test/integration/user_login_test.rb
Use user factory for user_roles_controller tests.
[rails.git] / test / integration / user_login_test.rb
index d027334d0d3cad5b85eff9b2903334854b8e8dcd..be95d0f178ac766057fcda5745e0d0f2a49a3be1 100644 (file)
@@ -13,6 +13,7 @@ class UserLoginTest < ActionDispatch::IntegrationTest
     OmniAuth.config.mock_auth[:facebook] = nil
     OmniAuth.config.mock_auth[:windowslive] = nil
     OmniAuth.config.mock_auth[:github] = nil
+    OmniAuth.config.mock_auth[:wikipedia] = nil
     OmniAuth.config.test_mode = false
   end
 
@@ -659,7 +660,7 @@ class UserLoginTest < ActionDispatch::IntegrationTest
     assert_template "user/login"
     get auth_path(:provider => "windowslive", :origin => "/login?referer=%2Fhistory", :referer => "/history")
     assert_response :redirect
-    assert_redirected_to auth_success_path(:provider => "windowslive", :origin => "/login?referer=%2Fhistory", :referer => "/history")
+    assert_redirected_to auth_success_path(:provider => "windowslive")
     follow_redirect!
     assert_response :redirect
     follow_redirect!
@@ -679,7 +680,7 @@ class UserLoginTest < ActionDispatch::IntegrationTest
     assert_template "user/login"
     get auth_path(:provider => "windowslive", :origin => "/login?referer=%2Fhistory", :referer => "/history")
     assert_response :redirect
-    assert_redirected_to auth_success_path(:provider => "windowslive", :origin => "/login?referer=%2Fhistory", :referer => "/history")
+    assert_redirected_to auth_success_path(:provider => "windowslive")
     follow_redirect!
     assert_response :redirect
     assert_redirected_to auth_failure_path(:strategy => "windowslive", :message => "connection_failed", :origin => "/login?referer=%2Fhistory")
@@ -703,7 +704,7 @@ class UserLoginTest < ActionDispatch::IntegrationTest
     assert_template "user/login"
     get auth_path(:provider => "windowslive", :origin => "/login?referer=%2Fhistory", :referer => "/history")
     assert_response :redirect
-    assert_redirected_to auth_success_path(:provider => "windowslive", :origin => "/login?referer=%2Fhistory", :referer => "/history")
+    assert_redirected_to auth_success_path(:provider => "windowslive")
     follow_redirect!
     assert_response :redirect
     assert_redirected_to auth_failure_path(:strategy => "windowslive", :message => "invalid_credentials", :origin => "/login?referer=%2Fhistory")
@@ -727,7 +728,7 @@ class UserLoginTest < ActionDispatch::IntegrationTest
     assert_template "user/login"
     get auth_path(:provider => "windowslive", :origin => "/login?referer=%2Fhistory", :referer => "/history")
     assert_response :redirect
-    assert_redirected_to auth_success_path(:provider => "windowslive", :origin => "/login?referer=%2Fhistory", :referer => "/history")
+    assert_redirected_to auth_success_path(:provider => "windowslive")
     follow_redirect!
     assert_response :redirect
     follow_redirect!
@@ -824,6 +825,94 @@ class UserLoginTest < ActionDispatch::IntegrationTest
     assert_select "span.username", false
   end
 
+  def test_login_wikipedia_success
+    OmniAuth.config.add_mock(:wikipedia, :uid => "123456789")
+
+    get "/login", :referer => "/history"
+    assert_response :redirect
+    assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
+    follow_redirect!
+    assert_response :success
+    assert_template "user/login"
+    get auth_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
+    assert_response :redirect
+    assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
+    follow_redirect!
+    assert_response :redirect
+    follow_redirect!
+    assert_response :success
+    assert_template "changeset/history"
+    assert_select "span.username", "wikipediauser"
+  end
+
+  def test_login_wikipedia_connection_failed
+    OmniAuth.config.mock_auth[:wikipedia] = :connection_failed
+
+    get "/login", :referer => "/history"
+    assert_response :redirect
+    assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
+    follow_redirect!
+    assert_response :success
+    assert_template "user/login"
+    get auth_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
+    assert_response :redirect
+    assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
+    follow_redirect!
+    assert_response :redirect
+    assert_redirected_to auth_failure_path(:strategy => "wikipedia", :message => "connection_failed", :origin => "/login?referer=%2Fhistory")
+    follow_redirect!
+    assert_response :redirect
+    follow_redirect!
+    assert_response :success
+    assert_template "login"
+    assert_select "div.flash.error", "Connection to authentication provider failed"
+    assert_select "span.username", false
+  end
+
+  def test_login_wikipedia_invalid_credentials
+    OmniAuth.config.mock_auth[:wikipedia] = :invalid_credentials
+
+    get "/login", :referer => "/history"
+    assert_response :redirect
+    assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
+    follow_redirect!
+    assert_response :success
+    assert_template "user/login"
+    get auth_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
+    assert_response :redirect
+    assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
+    follow_redirect!
+    assert_response :redirect
+    assert_redirected_to auth_failure_path(:strategy => "wikipedia", :message => "invalid_credentials", :origin => "/login?referer=%2Fhistory")
+    follow_redirect!
+    assert_response :redirect
+    follow_redirect!
+    assert_response :success
+    assert_template "login"
+    assert_select "div.flash.error", "Invalid authentication credentials"
+    assert_select "span.username", false
+  end
+
+  def test_login_wikipedia_unknown
+    OmniAuth.config.add_mock(:wikipedia, :uid => "987654321")
+
+    get "/login", :referer => "/history"
+    assert_response :redirect
+    assert_redirected_to "controller" => "user", "action" => "login", "cookie_test" => "true", "referer" => "/history"
+    follow_redirect!
+    assert_response :success
+    assert_template "user/login"
+    get auth_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
+    assert_response :redirect
+    assert_redirected_to auth_success_path(:provider => "wikipedia", :origin => "/login?referer=%2Fhistory", :referer => "/history")
+    follow_redirect!
+    assert_response :redirect
+    follow_redirect!
+    assert_response :success
+    assert_template "user/new"
+    assert_select "span.username", false
+  end
+
   private
 
   def try_password_login(username, password, remember_me = nil)