mirror of
https://github.com/neocities/neocities.git
synced 2025-08-04 00:31:59 +02:00
fix migrations, acceptance testing for auth, 32 char username limit
This commit is contained in:
parent
fdd4017523
commit
5dfc715148
18 changed files with 247 additions and 125 deletions
144
tests/acceptance_tests.rb
Normal file
144
tests/acceptance_tests.rb
Normal file
|
@ -0,0 +1,144 @@
|
|||
require_relative './environment'
|
||||
|
||||
Capybara.app = Sinatra::Application
|
||||
|
||||
def teardown
|
||||
Capybara.reset_sessions!
|
||||
Capybara.use_default_driver
|
||||
end
|
||||
|
||||
describe 'index' do
|
||||
include Capybara::DSL
|
||||
it 'goes to signup' do
|
||||
visit '/'
|
||||
click_button 'Create My Website'
|
||||
page.must_have_content('Create a New Home Page')
|
||||
end
|
||||
end
|
||||
|
||||
describe 'signup' do
|
||||
include Capybara::DSL
|
||||
|
||||
def fill_in_valid
|
||||
@site = Fabricate.attributes_for(:site)
|
||||
fill_in 'username', with: @site[:username]
|
||||
fill_in 'password', with: @site[:password]
|
||||
end
|
||||
|
||||
def visit_signup
|
||||
visit '/'
|
||||
click_button 'Create My Website'
|
||||
end
|
||||
|
||||
before do
|
||||
Capybara.reset_sessions!
|
||||
visit_signup
|
||||
end
|
||||
|
||||
it 'succeeds with valid data' do
|
||||
fill_in_valid
|
||||
click_button 'Create Home Page'
|
||||
page.must_have_content 'Your Website'
|
||||
assert_equal(
|
||||
true,
|
||||
File.exist?(File.join(Site::SITE_FILES_ROOT, @site[:username], 'index.html'))
|
||||
)
|
||||
end
|
||||
|
||||
it 'fails to create for existing site' do
|
||||
fill_in_valid
|
||||
click_button 'Create Home Page'
|
||||
page.must_have_content 'Your Website'
|
||||
Capybara.reset_sessions!
|
||||
visit_signup
|
||||
fill_in 'username', with: @site[:username]
|
||||
fill_in 'password', with: @site[:password]
|
||||
click_button 'Create Home Page'
|
||||
page.must_have_content 'already taken'
|
||||
end
|
||||
|
||||
it 'fails with missing password' do
|
||||
fill_in_valid
|
||||
fill_in 'password', with: ''
|
||||
click_button 'Create Home Page'
|
||||
page.must_have_content 'Password must be at least 5 characters'
|
||||
end
|
||||
|
||||
it 'fails with short password' do
|
||||
fill_in_valid
|
||||
fill_in 'password', with: 'derp'
|
||||
click_button 'Create Home Page'
|
||||
page.must_have_content 'Password must be at least 5 characters'
|
||||
end
|
||||
|
||||
it 'fails with invalid hostname for username' do
|
||||
fill_in_valid
|
||||
fill_in 'username', with: '|\|0p|E'
|
||||
click_button 'Create Home Page'
|
||||
page.current_path.must_equal '/create'
|
||||
page.must_have_content 'A valid user/site name is required'
|
||||
fill_in 'username', with: 'nope-'
|
||||
click_button 'Create Home Page'
|
||||
page.must_have_content 'A valid user/site name is required'
|
||||
fill_in 'username', with: '-nope'
|
||||
click_button 'Create Home Page'
|
||||
page.must_have_content 'A valid user/site name is required'
|
||||
end
|
||||
|
||||
it 'fails with username greater than 32 characters' do
|
||||
fill_in_valid
|
||||
fill_in 'username', with: SecureRandom.hex+'1'
|
||||
click_button 'Create Home Page'
|
||||
page.current_path.must_equal '/create'
|
||||
page.must_have_content 'cannot exceed 32 characters'
|
||||
end
|
||||
end
|
||||
|
||||
describe 'signin' do
|
||||
include Capybara::DSL
|
||||
|
||||
def fill_in_valid
|
||||
site = Fabricate.attributes_for :site
|
||||
fill_in 'username', with: site[:username]
|
||||
fill_in 'password', with: site[:password]
|
||||
end
|
||||
|
||||
before do
|
||||
Capybara.reset_sessions!
|
||||
end
|
||||
|
||||
it 'fails for invalid login' do
|
||||
visit '/'
|
||||
click_link 'Sign In'
|
||||
page.must_have_content 'Welcome back'
|
||||
fill_in_valid
|
||||
click_button 'Sign in'
|
||||
page.must_have_content 'Invalid login'
|
||||
end
|
||||
|
||||
it 'fails for missing login' do
|
||||
visit '/'
|
||||
click_link 'Sign In'
|
||||
auth = {username: SecureRandom.hex, password: Faker::Internet.password}
|
||||
fill_in 'username', with: auth[:username]
|
||||
fill_in 'password', with: auth[:password]
|
||||
click_button 'Sign in'
|
||||
page.must_have_content 'Invalid login'
|
||||
end
|
||||
|
||||
it 'logs in with proper credentials' do
|
||||
visit '/'
|
||||
click_button 'Create My Website'
|
||||
site = Fabricate.attributes_for(:site)
|
||||
fill_in 'username', with: site[:username]
|
||||
fill_in 'password', with: site[:password]
|
||||
click_button 'Create Home Page'
|
||||
Capybara.reset_sessions!
|
||||
visit '/'
|
||||
click_link 'Sign In'
|
||||
fill_in 'username', with: site[:username]
|
||||
fill_in 'password', with: site[:password]
|
||||
click_button 'Sign in'
|
||||
page.must_have_content 'Your Website'
|
||||
end
|
||||
end
|
|
@ -1,93 +0,0 @@
|
|||
require_relative './environment'
|
||||
|
||||
include Rack::Test::Methods
|
||||
|
||||
def app; App end
|
||||
def status; last_response.status end
|
||||
def headers; last_response.headers end
|
||||
def body; last_response.body end
|
||||
|
||||
describe 'index' do
|
||||
it 'loads' do
|
||||
get '/'
|
||||
status.must_equal 200
|
||||
end
|
||||
end
|
||||
|
||||
describe 'signin' do
|
||||
it 'fails for missing login' do
|
||||
post '/signin', username: 'derpie', password: 'lol'
|
||||
fail_signin
|
||||
end
|
||||
|
||||
it 'fails for bad password' do
|
||||
@site = Fabricate :site
|
||||
post '/signin', username: @site.username, password: 'derp'
|
||||
fail_signin
|
||||
end
|
||||
|
||||
it 'fails for no input' do
|
||||
post '/signin'
|
||||
fail_signin
|
||||
end
|
||||
|
||||
it 'succeeds for valid input' do
|
||||
password = '1tw0rkz'
|
||||
@account = Fabricate :account, password: password
|
||||
post '/accounts/signin', username: @account.email, password: password
|
||||
headers['Location'].must_equal 'http://example.org/dashboard'
|
||||
mock_dashboard_calls @account.email
|
||||
get '/dashboard'
|
||||
body.must_match /Dashboard/
|
||||
end
|
||||
end
|
||||
|
||||
describe 'account creation' do
|
||||
it 'fails for no input' do
|
||||
post '/accounts/create'
|
||||
status.must_equal 200
|
||||
body.must_match /There were some errors.+Valid email address is required.+Password must be/
|
||||
end
|
||||
|
||||
it 'fails with invalid email' do
|
||||
post '/accounts/create', email: 'derplol'
|
||||
status.must_equal 200
|
||||
body.must_match /errors.+valid email/i
|
||||
end
|
||||
|
||||
it 'fails with invalid password' do
|
||||
post '/accounts/create', 'email@example.com', password: 'sdd'
|
||||
status.must_equal 200
|
||||
body.must_match /errors.+Password must be at least #{Account::MINIMUM_PASSWORD_LENGTH} characters/i
|
||||
end
|
||||
|
||||
it 'succeeds with valid info' do
|
||||
account_attributes = Fabricate.attributes_for :account
|
||||
|
||||
mock_dashboard_calls account_attributes[:email]
|
||||
|
||||
post '/accounts/create', account_attributes
|
||||
status.must_equal 302
|
||||
headers['Location'].must_equal 'http://example.org/dashboard'
|
||||
|
||||
get '/dashboard'
|
||||
body.must_match /Dashboard/
|
||||
end
|
||||
end
|
||||
|
||||
describe 'temporary account login' do
|
||||
end
|
||||
|
||||
def fail_signin
|
||||
headers['Location'].must_equal 'http://example.org/'
|
||||
get '/'
|
||||
body.must_match /invalid signin/i
|
||||
end
|
||||
|
||||
def api_url
|
||||
uri = Addressable::URI.parse $config['bitcoind_rpchost'] ? $config['bitcoind_rpchost'] : 'http://localhost'
|
||||
uri.port = 8332 if uri.port.nil?
|
||||
uri.user = $config['bitcoind_rpcuser'] if uri.user.nil?
|
||||
uri.password = $config['bitcoind_rpcpassword'] if uri.password.nil?
|
||||
"#{uri.to_s}/"
|
||||
end
|
|
@ -20,7 +20,7 @@ Bundler.require :test
|
|||
require 'minitest/autorun'
|
||||
require 'sidekiq/testing/inline'
|
||||
|
||||
Account.bcrypt_cost = BCrypt::Engine::MIN_COST
|
||||
Site.bcrypt_cost = BCrypt::Engine::MIN_COST
|
||||
|
||||
MiniTest::Reporters.use! MiniTest::Reporters::SpecReporter.new
|
||||
|
||||
|
@ -29,8 +29,11 @@ Sequel.extension :migration
|
|||
|
||||
Sequel::Migrator.apply DB, './migrations', 0
|
||||
Sequel::Migrator.apply DB, './migrations'
|
||||
Server.create ip: '127.0.0.1', slots_available: 999999
|
||||
|
||||
Fabrication.configure do |config|
|
||||
config.fabricator_path = 'tests/fabricators'
|
||||
config.path_prefix = DIR_ROOT
|
||||
end
|
||||
end
|
||||
|
||||
I18n.enforce_available_locales = true
|
|
@ -1,4 +1,4 @@
|
|||
Fabricator(:site) do
|
||||
username { Faker::Internet.email }
|
||||
username { SecureRandom.hex }
|
||||
password { 'abcde' }
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue