X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/860887de5272c3e2a39cb7e0c9db6f0acba1b4c6..56e96d856c7fc168b37cf9d26a58a6da8094cedb:/test/integration/user_login_test.rb diff --git a/test/integration/user_login_test.rb b/test/integration/user_login_test.rb index 155905ca9..be95d0f17 100644 --- a/test/integration/user_login_test.rb +++ b/test/integration/user_login_test.rb @@ -1,7 +1,7 @@ require "test_helper" class UserLoginTest < ActionDispatch::IntegrationTest - fixtures :users, :user_blocks + fixtures :users, :user_roles def setup OmniAuth.config.test_mode = true @@ -12,6 +12,8 @@ class UserLoginTest < ActionDispatch::IntegrationTest OmniAuth.config.mock_auth[:google] = nil 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 @@ -128,6 +130,7 @@ class UserLoginTest < ActionDispatch::IntegrationTest def test_login_email_password_blocked user = users(:blocked_user) + create(:user_block, :needs_view, :user => user) try_password_login user.email, "test" @@ -137,6 +140,7 @@ class UserLoginTest < ActionDispatch::IntegrationTest def test_login_email_password_blocked_upcase user = users(:blocked_user) + create(:user_block, :needs_view, :user => user) try_password_login user.email.upcase, "test" @@ -146,6 +150,7 @@ class UserLoginTest < ActionDispatch::IntegrationTest def test_login_email_password_blocked_titlecase user = users(:blocked_user) + create(:user_block, :needs_view, :user => user) try_password_login user.email.titlecase, "test" @@ -266,6 +271,7 @@ class UserLoginTest < ActionDispatch::IntegrationTest def test_login_username_password_blocked user = users(:blocked_user) + create(:user_block, :needs_view, :user => user) try_password_login user.display_name.upcase, "test" @@ -275,6 +281,7 @@ class UserLoginTest < ActionDispatch::IntegrationTest def test_login_username_password_blocked_upcase user = users(:blocked_user) + create(:user_block, :needs_view, :user => user) try_password_login user.display_name, "test" @@ -284,6 +291,7 @@ class UserLoginTest < ActionDispatch::IntegrationTest def test_login_username_password_blocked_titlecase user = users(:blocked_user) + create(:user_block, :needs_view, :user => user) try_password_login user.display_name.titlecase, "test" @@ -548,7 +556,7 @@ class UserLoginTest < ActionDispatch::IntegrationTest assert_template "changeset/history" assert_select "span.username", "openIDuser" - user = User.find_by_display_name("openIDuser") + user = User.find_by(:display_name => "openIDuser") assert_equal "google", user.auth_provider assert_equal "987654321", user.auth_uid end @@ -652,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! @@ -672,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") @@ -696,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") @@ -720,7 +728,183 @@ 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! + assert_response :success + assert_template "user/new" + assert_select "span.username", false + end + + def test_login_github_success + OmniAuth.config.add_mock(:github, :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 => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history") + assert_response :redirect + assert_redirected_to auth_success_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history") + follow_redirect! + assert_response :redirect + follow_redirect! + assert_response :success + assert_template "changeset/history" + assert_select "span.username", "githubuser" + end + + def test_login_github_connection_failed + OmniAuth.config.mock_auth[:github] = :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 => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history") + assert_response :redirect + assert_redirected_to auth_success_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history") + follow_redirect! + assert_response :redirect + assert_redirected_to auth_failure_path(:strategy => "github", :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_github_invalid_credentials + OmniAuth.config.mock_auth[:github] = :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 => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history") + assert_response :redirect + assert_redirected_to auth_success_path(:provider => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history") + follow_redirect! + assert_response :redirect + assert_redirected_to auth_failure_path(:strategy => "github", :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_github_unknown + OmniAuth.config.add_mock(:github, :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 => "github", :origin => "/login?referer=%2Fhistory", :referer => "/history") + assert_response :redirect + assert_redirected_to auth_success_path(:provider => "github", :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 + + 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!