Files
danbooru/test/functional/sessions_controller_test.rb
evazion 93a60eebed ip bans: forbid all non-GET actions for ip banned users.
Previously only actions that were marked member_only or above were
subject to IP ban restrictions. This meant that certain actions that
weren't marked member_only, like creating new accounts, could still be
done by IP banned users.

Now IP banned users can't do any non-GET actions, which means they're
not allowed to even login to their accounts.
2020-03-16 15:35:46 -05:00

51 lines
1.3 KiB
Ruby

require 'test_helper'
class SessionsControllerTest < ActionDispatch::IntegrationTest
context "the sessions controller" do
setup do
@user = create(:user)
end
context "new action" do
should "render" do
get new_session_path
assert_response :success
end
end
context "create action" do
should "create a new session" do
post session_path, params: {:name => @user.name, :password => "password"}
assert_redirected_to posts_path
assert_equal(@user.id, session[:user_id])
assert_not_nil(@user.reload.last_ip_addr)
end
should "not allow IP banned users to create a new session" do
create(:ip_ban, ip_addr: "1.2.3.4")
post session_path, params: { name: @user.name, password: "password" }, headers: { REMOTE_ADDR: "1.2.3.4" }
assert_response 403
assert_not_equal(@user.id, session[:user_id])
end
end
context "destroy action" do
should "clear the session" do
delete_auth session_path, @user
assert_redirected_to posts_path
assert_nil(session[:user_id])
end
end
context "sign_out action" do
should "clear the session" do
get_auth sign_out_session_path, @user
assert_redirected_to posts_path
assert_nil(session[:user_id])
end
end
end
end