180 lines
6.0 KiB
Ruby
180 lines
6.0 KiB
Ruby
require 'spec_helper'
|
|
|
|
describe "signin" do
|
|
|
|
subject { page }
|
|
|
|
let(:user) { FactoryGirl.create(:user) }
|
|
|
|
before(:each) do
|
|
visit signin_path
|
|
end
|
|
|
|
it "success" do
|
|
visit signin_path
|
|
fill_in "Email", with: user.email
|
|
fill_in "Password", with: user.password
|
|
click_button "SIGN IN"
|
|
|
|
find('.curtain', text: 'Connecting...')
|
|
end
|
|
|
|
it "success with redirect" do
|
|
visit signin_path + '?' + {'redirect-to' => '/'}.to_query
|
|
fill_in "Email", with: user.email
|
|
fill_in "Password", with: user.password
|
|
click_button "SIGN IN"
|
|
|
|
find('h1', text: 'Play music together over the Internet as if in the same room')
|
|
end
|
|
|
|
# proves that redirect-to is preserved between failure
|
|
it 'failure, then success with redirect' do
|
|
|
|
visit signin_path + '?' + {'redirect-to' => '/'}.to_query
|
|
fill_in "Email", with: user.email
|
|
fill_in "Password", with: 'wrong'
|
|
click_button "SIGN IN"
|
|
|
|
find('h1', text:'sign in or register')
|
|
find('.login-error')
|
|
|
|
fill_in "Email", with: user.email
|
|
fill_in "Password", with: user.password
|
|
click_button "SIGN IN"
|
|
|
|
find('h1', text: 'Play music together over the Internet as if in the same room')
|
|
end
|
|
|
|
it "success with forum sso" do
|
|
visit signin_path + '?' + {:sso => :forums}.to_query
|
|
fill_in "Email", with: user.email
|
|
fill_in "Password", with: user.password
|
|
click_button "SIGN IN"
|
|
|
|
find('h1', text: 'welcome to fake login page')
|
|
|
|
# should be sent to the login url
|
|
current_url.include? Rails.application.config.vanilla_login_url
|
|
# and that login url should contain a 'Target' which is a post-redirect enacted by vanilla
|
|
uri = URI.parse(current_url)
|
|
Rack::Utils.parse_nested_query(uri.query)['Target'].should == '/'
|
|
end
|
|
|
|
it "failure, then success with forum sso" do
|
|
visit signin_path + '?' + {:sso => :forums}.to_query
|
|
|
|
fill_in "Email", with: user.email
|
|
fill_in "Password", with: 'wrong'
|
|
click_button "SIGN IN"
|
|
|
|
find('h1', text:'sign in or register')
|
|
find('.login-error')
|
|
|
|
fill_in "Email", with: user.email
|
|
fill_in "Password", with: user.password
|
|
click_button "SIGN IN"
|
|
|
|
find('h1', text: 'welcome to fake login page')
|
|
|
|
# should be sent to the login url
|
|
current_url.include? Rails.application.config.vanilla_login_url
|
|
# and that login url should contain a 'Target' which is a post-redirect enacted by vanilla
|
|
uri = URI.parse(current_url)
|
|
Rack::Utils.parse_nested_query(uri.query)['Target'].should == '/'
|
|
end
|
|
|
|
it "success with forum sso w/ custom redirect" do
|
|
visit signin_path + '?' + {:sso => :forums, send_back_to: '/junk'}.to_query
|
|
|
|
fill_in "Email", with: user.email
|
|
fill_in "Password", with: user.password
|
|
click_button "SIGN IN"
|
|
|
|
find('h1', text: 'welcome to fake login page')
|
|
|
|
# should be sent to the login url
|
|
current_url.include? Rails.application.config.vanilla_login_url
|
|
# and that login url should contain a 'Target' which is a post-redirect enacted by vanilla
|
|
uri = URI.parse(current_url)
|
|
Rack::Utils.parse_nested_query(uri.query)['Target'].should == '/junk'
|
|
end
|
|
|
|
describe "already logged in" do
|
|
|
|
it "redirects back to /client" do
|
|
visit signin_path
|
|
|
|
fill_in "Email", with: user.email
|
|
fill_in "Password", with: user.password
|
|
click_button "SIGN IN"
|
|
find('.curtain', text: 'Connecting...')
|
|
|
|
visit signin_path
|
|
|
|
find('.curtain', text: 'Connecting...')
|
|
end
|
|
|
|
it "redirects back to forum if sso=forum" do
|
|
visit signin_path
|
|
|
|
fill_in "Email", with: user.email
|
|
fill_in "Password", with: user.password
|
|
click_button "SIGN IN"
|
|
find('.curtain', text: 'Connecting...')
|
|
|
|
visit signin_path + '?' + {:sso => :forums}.to_query
|
|
|
|
find('h1', text: 'welcome to fake login page')
|
|
end
|
|
end
|
|
|
|
describe "with javascript", :js => true, :type => :feature, :capybara_feature => true do
|
|
|
|
# if a cookie with the default domain is found with another, delete the one with the default domain
|
|
it "delete duplicate session cookies" do
|
|
|
|
# this has the opposite effect of what you normally want, but still proves thath the cookie deleter is doing it's thing
|
|
# here's why: by default, in our poltergeist tests are have a cookie domain of 127.0.0.1.
|
|
# The ClearDuplicatedSession middleware will delete the 'default' domain cookie (in this case, the one that the server is making on logon)
|
|
# any sort of wildcard cookie (like the one we create here, with a 'junk' value, will not be deleted, and
|
|
# prevent successful log in indefinitely)
|
|
page.driver.set_cookie(:remember_token, 'junk', domain: '.127.0.0.1')
|
|
|
|
visit signin_path
|
|
|
|
fill_in "Email", with: user.email
|
|
fill_in "Password", with: user.password
|
|
click_button "SIGN IN"
|
|
|
|
find('h1', text: 'Play music together over the Internet as if in the same room')
|
|
end
|
|
|
|
# if a cookie with the default domain is found with another, delete the one with the default domain
|
|
it "delete duplicate session cookies - verify middleware called" do
|
|
|
|
# this has the opposite effect of what you normally want, but still proves thath the cookie deleter is doing it's thing
|
|
# here's why: by default, in our poltergeist tests are have a cookie domain of 127.0.0.1.
|
|
# The ClearDuplicatedSession middleware will delete the 'default' domain cookie (in this case, the one that the server is making on logon)
|
|
# any sort of wildcard cookie (like the one we create here, with a 'junk' value, will not be deleted, and
|
|
# prevent successful log in indefinitely)
|
|
page.driver.set_cookie(:remember_token, 'junk', domain: '.127.0.0.1')
|
|
|
|
delete_called = false
|
|
Middlewares::ClearDuplicatedSession.any_instance.stub(:delete_session_cookie_for_current_domain) do
|
|
delete_called = true
|
|
end
|
|
|
|
visit signin_path
|
|
|
|
fill_in "Email", with: user.email
|
|
fill_in "Password", with: user.password
|
|
click_button "SIGN IN"
|
|
|
|
find('h1', text: 'Play music together over the Internet as if in the same room')
|
|
|
|
delete_called.should be_true
|
|
end
|
|
end
|
|
end
|