mirror of
https://github.com/neocities/neocities.git
synced 2025-04-25 01:32:36 +02:00
working to get the tests back online. deprecated zipruby to make selenium work, need to refactor zip code
This commit is contained in:
parent
10ff8a7cc7
commit
ed02178289
16 changed files with 174 additions and 309 deletions
3
Gemfile
3
Gemfile
|
@ -15,7 +15,6 @@ gem 'tilt'
|
||||||
gem 'erubis'
|
gem 'erubis'
|
||||||
gem 'stripe' #, source: 'https://code.stripe.com/'
|
gem 'stripe' #, source: 'https://code.stripe.com/'
|
||||||
gem 'terrapin'
|
gem 'terrapin'
|
||||||
gem 'zipruby'
|
|
||||||
gem 'sass', require: nil
|
gem 'sass', require: nil
|
||||||
gem 'dav4rack', git: 'https://github.com/neocities/dav4rack.git', ref: '3ecde122a0b8bcc1d85581dc85ef3a7120b6a8f0'
|
gem 'dav4rack', git: 'https://github.com/neocities/dav4rack.git', ref: '3ecde122a0b8bcc1d85581dc85ef3a7120b6a8f0'
|
||||||
gem 'filesize'
|
gem 'filesize'
|
||||||
|
@ -82,6 +81,7 @@ group :test do
|
||||||
gem 'mocha', require: nil
|
gem 'mocha', require: nil
|
||||||
gem 'rake', '>= 12.3.3', require: nil
|
gem 'rake', '>= 12.3.3', require: nil
|
||||||
gem 'capybara', require: nil #, '2.10.1', require: nil
|
gem 'capybara', require: nil #, '2.10.1', require: nil
|
||||||
|
gem 'selenium-webdriver'
|
||||||
gem 'rack_session_access', require: nil
|
gem 'rack_session_access', require: nil
|
||||||
gem 'webmock', require: nil
|
gem 'webmock', require: nil
|
||||||
gem 'stripe-ruby-mock', '~> 3.1.0.rc3', require: 'stripe_mock'
|
gem 'stripe-ruby-mock', '~> 3.1.0.rc3', require: 'stripe_mock'
|
||||||
|
@ -89,5 +89,4 @@ group :test do
|
||||||
gem 'mock_redis'
|
gem 'mock_redis'
|
||||||
gem 'simplecov', require: nil
|
gem 'simplecov', require: nil
|
||||||
gem 'm'
|
gem 'm'
|
||||||
gem 'apparition', github: 'twalpole/apparition', ref: 'ca86be4d54af835d531dbcd2b86e7b2c77f85f34'
|
|
||||||
end
|
end
|
||||||
|
|
33
Gemfile.lock
33
Gemfile.lock
|
@ -10,15 +10,6 @@ GIT
|
||||||
rack (>= 1.6)
|
rack (>= 1.6)
|
||||||
uuidtools (~> 2.1.1)
|
uuidtools (~> 2.1.1)
|
||||||
|
|
||||||
GIT
|
|
||||||
remote: https://github.com/twalpole/apparition.git
|
|
||||||
revision: ca86be4d54af835d531dbcd2b86e7b2c77f85f34
|
|
||||||
ref: ca86be4d54af835d531dbcd2b86e7b2c77f85f34
|
|
||||||
specs:
|
|
||||||
apparition (0.6.0)
|
|
||||||
capybara (~> 3.13, < 4)
|
|
||||||
websocket-driver (>= 0.6.5)
|
|
||||||
|
|
||||||
GEM
|
GEM
|
||||||
remote: https://rubygems.org/
|
remote: https://rubygems.org/
|
||||||
specs:
|
specs:
|
||||||
|
@ -190,7 +181,6 @@ GEM
|
||||||
maxmind-geoip2 (~> 1.2)
|
maxmind-geoip2 (~> 1.2)
|
||||||
simpleidn (~> 0.1, >= 0.1.1)
|
simpleidn (~> 0.1, >= 0.1.1)
|
||||||
mini_mime (1.1.5)
|
mini_mime (1.1.5)
|
||||||
mini_portile2 (2.8.5)
|
|
||||||
minitest (5.20.0)
|
minitest (5.20.0)
|
||||||
minitest-reporters (1.6.1)
|
minitest-reporters (1.6.1)
|
||||||
ansi
|
ansi
|
||||||
|
@ -221,8 +211,7 @@ GEM
|
||||||
net-protocol
|
net-protocol
|
||||||
netrc (0.11.0)
|
netrc (0.11.0)
|
||||||
nio4r (2.7.0)
|
nio4r (2.7.0)
|
||||||
nokogiri (1.15.5)
|
nokogiri (1.16.0-x86_64-linux)
|
||||||
mini_portile2 (~> 2.8.2)
|
|
||||||
racc (~> 1.4)
|
racc (~> 1.4)
|
||||||
ox (2.14.17)
|
ox (2.14.17)
|
||||||
paypal-recurring (1.1.0)
|
paypal-recurring (1.1.0)
|
||||||
|
@ -239,7 +228,8 @@ GEM
|
||||||
rack (2.2.8)
|
rack (2.2.8)
|
||||||
rack-cache (1.15.0)
|
rack-cache (1.15.0)
|
||||||
rack (>= 0.4)
|
rack (>= 0.4)
|
||||||
rack-protection (3.1.0)
|
rack-protection (3.2.0)
|
||||||
|
base64 (>= 0.1.0)
|
||||||
rack (~> 2.2, >= 2.2.4)
|
rack (~> 2.2, >= 2.2.4)
|
||||||
rack-test (2.1.0)
|
rack-test (2.1.0)
|
||||||
rack (>= 1.3)
|
rack (>= 1.3)
|
||||||
|
@ -269,6 +259,7 @@ GEM
|
||||||
rszr (1.3.0)
|
rszr (1.3.0)
|
||||||
ruby-progressbar (1.13.0)
|
ruby-progressbar (1.13.0)
|
||||||
ruby2_keywords (0.0.5)
|
ruby2_keywords (0.0.5)
|
||||||
|
rubyzip (2.3.2)
|
||||||
sanitize (6.1.0)
|
sanitize (6.1.0)
|
||||||
crass (~> 1.0.2)
|
crass (~> 1.0.2)
|
||||||
nokogiri (>= 1.12.0)
|
nokogiri (>= 1.12.0)
|
||||||
|
@ -278,6 +269,10 @@ GEM
|
||||||
rb-fsevent (~> 0.9, >= 0.9.4)
|
rb-fsevent (~> 0.9, >= 0.9.4)
|
||||||
rb-inotify (~> 0.9, >= 0.9.7)
|
rb-inotify (~> 0.9, >= 0.9.7)
|
||||||
sax-machine (1.3.2)
|
sax-machine (1.3.2)
|
||||||
|
selenium-webdriver (4.16.0)
|
||||||
|
rexml (~> 3.2, >= 3.2.5)
|
||||||
|
rubyzip (>= 1.2.2, < 3.0)
|
||||||
|
websocket (~> 1.0)
|
||||||
sequel (5.75.0)
|
sequel (5.75.0)
|
||||||
bigdecimal
|
bigdecimal
|
||||||
sequel_pg (1.17.1)
|
sequel_pg (1.17.1)
|
||||||
|
@ -298,10 +293,10 @@ GEM
|
||||||
simplecov_json_formatter (0.1.4)
|
simplecov_json_formatter (0.1.4)
|
||||||
simpleidn (0.2.1)
|
simpleidn (0.2.1)
|
||||||
unf (~> 0.1.4)
|
unf (~> 0.1.4)
|
||||||
sinatra (3.1.0)
|
sinatra (3.2.0)
|
||||||
mustermann (~> 3.0)
|
mustermann (~> 3.0)
|
||||||
rack (~> 2.2, >= 2.2.4)
|
rack (~> 2.2, >= 2.2.4)
|
||||||
rack-protection (= 3.1.0)
|
rack-protection (= 3.2.0)
|
||||||
tilt (~> 2.0)
|
tilt (~> 2.0)
|
||||||
sinatra-flash (0.3.0)
|
sinatra-flash (0.3.0)
|
||||||
sinatra (>= 1.0.0)
|
sinatra (>= 1.0.0)
|
||||||
|
@ -342,16 +337,13 @@ GEM
|
||||||
ffi (>= 1.9.0)
|
ffi (>= 1.9.0)
|
||||||
ffi-compiler (>= 0.1.2)
|
ffi-compiler (>= 0.1.2)
|
||||||
webrick (1.8.1)
|
webrick (1.8.1)
|
||||||
websocket-driver (0.7.6)
|
websocket (1.2.10)
|
||||||
websocket-extensions (>= 0.1.0)
|
|
||||||
websocket-extensions (0.1.5)
|
|
||||||
will_paginate (4.0.0)
|
will_paginate (4.0.0)
|
||||||
xmlrpc (0.3.3)
|
xmlrpc (0.3.3)
|
||||||
webrick
|
webrick
|
||||||
xpath (3.2.0)
|
xpath (3.2.0)
|
||||||
nokogiri (~> 1.8)
|
nokogiri (~> 1.8)
|
||||||
zip_tricks (5.6.0)
|
zip_tricks (5.6.0)
|
||||||
zipruby (0.3.6)
|
|
||||||
|
|
||||||
PLATFORMS
|
PLATFORMS
|
||||||
x86_64-linux
|
x86_64-linux
|
||||||
|
@ -361,7 +353,6 @@ DEPENDENCIES
|
||||||
activesupport
|
activesupport
|
||||||
addressable (>= 2.8.0)
|
addressable (>= 2.8.0)
|
||||||
adequate_crypto_address
|
adequate_crypto_address
|
||||||
apparition!
|
|
||||||
bcrypt
|
bcrypt
|
||||||
capybara
|
capybara
|
||||||
certified
|
certified
|
||||||
|
@ -416,6 +407,7 @@ DEPENDENCIES
|
||||||
rszr
|
rszr
|
||||||
sanitize
|
sanitize
|
||||||
sass
|
sass
|
||||||
|
selenium-webdriver
|
||||||
sequel
|
sequel
|
||||||
sequel_pg
|
sequel_pg
|
||||||
shotgun
|
shotgun
|
||||||
|
@ -437,7 +429,6 @@ DEPENDENCIES
|
||||||
will_paginate
|
will_paginate
|
||||||
xmlrpc
|
xmlrpc
|
||||||
zip_tricks
|
zip_tricks
|
||||||
zipruby
|
|
||||||
|
|
||||||
BUNDLED WITH
|
BUNDLED WITH
|
||||||
2.3.10
|
2.3.10
|
||||||
|
|
|
@ -813,33 +813,6 @@ class Site < Sequel::Model
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
def files_zip
|
|
||||||
zip_name = "neocities-#{username}"
|
|
||||||
|
|
||||||
tmpfile = Tempfile.new 'neocities-site-zip'
|
|
||||||
tmpfile.close
|
|
||||||
|
|
||||||
begin
|
|
||||||
Zip::Archive.open(tmpfile.path, Zip::CREATE) do |ar|
|
|
||||||
ar.add_dir(zip_name)
|
|
||||||
|
|
||||||
Dir.glob("#{base_files_path}/**/*").each do |path|
|
|
||||||
relative_path = path.gsub(base_files_path+'/', '')
|
|
||||||
if File.directory?(path)
|
|
||||||
ar.add_dir(zip_name+'/'+relative_path)
|
|
||||||
else
|
|
||||||
ar.add_file(zip_name+'/'+relative_path, path) # add_file(<entry name>, <source path>)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
rescue => e
|
|
||||||
tmpfile.unlink
|
|
||||||
raise e
|
|
||||||
end
|
|
||||||
|
|
||||||
tmpfile.path
|
|
||||||
end
|
|
||||||
|
|
||||||
def move_files_from(oldusername)
|
def move_files_from(oldusername)
|
||||||
FileUtils.mkdir_p self.class.sharding_base_path(username)
|
FileUtils.mkdir_p self.class.sharding_base_path(username)
|
||||||
FileUtils.mkdir_p self.class.sharding_screenshots_path(username)
|
FileUtils.mkdir_p self.class.sharding_screenshots_path(username)
|
||||||
|
|
|
@ -2,6 +2,8 @@ require_relative './environment.rb'
|
||||||
|
|
||||||
describe '/admin' do
|
describe '/admin' do
|
||||||
include Capybara::DSL
|
include Capybara::DSL
|
||||||
|
include Capybara::Minitest::Assertions
|
||||||
|
|
||||||
|
|
||||||
before do
|
before do
|
||||||
Capybara.reset_sessions!
|
Capybara.reset_sessions!
|
||||||
|
|
|
@ -2,6 +2,7 @@ require_relative './environment.rb'
|
||||||
|
|
||||||
describe '/browse' do
|
describe '/browse' do
|
||||||
include Capybara::DSL
|
include Capybara::DSL
|
||||||
|
include Capybara::Minitest::Assertions
|
||||||
|
|
||||||
=begin
|
=begin
|
||||||
describe 'as admin' do
|
describe 'as admin' do
|
||||||
|
|
|
@ -4,8 +4,8 @@ describe 'dashboard' do
|
||||||
describe 'create directory' do
|
describe 'create directory' do
|
||||||
|
|
||||||
describe 'logged in' do
|
describe 'logged in' do
|
||||||
|
|
||||||
include Capybara::DSL
|
include Capybara::DSL
|
||||||
|
include Capybara::Minitest::Assertions
|
||||||
|
|
||||||
before do
|
before do
|
||||||
Capybara.reset_sessions!
|
Capybara.reset_sessions!
|
||||||
|
|
|
@ -2,6 +2,7 @@ require_relative './environment.rb'
|
||||||
|
|
||||||
describe 'signup' do
|
describe 'signup' do
|
||||||
include Capybara::DSL
|
include Capybara::DSL
|
||||||
|
include Capybara::Minitest::Assertions
|
||||||
|
|
||||||
def fill_in_valid
|
def fill_in_valid
|
||||||
@site = Fabricate.attributes_for(:site)
|
@site = Fabricate.attributes_for(:site)
|
||||||
|
@ -13,7 +14,7 @@ describe 'signup' do
|
||||||
end
|
end
|
||||||
|
|
||||||
before do
|
before do
|
||||||
Capybara.default_driver = :apparition
|
Capybara.default_driver = :selenium_chrome_headless
|
||||||
Capybara.reset_sessions!
|
Capybara.reset_sessions!
|
||||||
visit '/education'
|
visit '/education'
|
||||||
_(page).must_have_content 'Neocities' # Used to force load wait
|
_(page).must_have_content 'Neocities' # Used to force load wait
|
||||||
|
|
|
@ -1,38 +1,17 @@
|
||||||
require_relative '../environment'
|
require_relative '../environment'
|
||||||
|
|
||||||
|
require 'capybara'
|
||||||
require 'capybara/minitest'
|
require 'capybara/minitest'
|
||||||
require 'capybara/minitest/spec'
|
require 'capybara/minitest/spec'
|
||||||
require 'rack_session_access/capybara'
|
require 'rack_session_access/capybara'
|
||||||
require 'capybara/apparition'
|
|
||||||
|
|
||||||
Capybara.app = Sinatra::Application
|
Capybara.app = Sinatra::Application
|
||||||
|
|
||||||
include Capybara::Minitest::Assertions
|
|
||||||
Capybara.default_max_wait_time = 5
|
Capybara.default_max_wait_time = 5
|
||||||
|
|
||||||
#Capybara.register_driver :apparition do |app|
|
Capybara.register_driver :selenium_chrome_headless_largewindow do |app|
|
||||||
# Capybara::Apparition::Driver.new(app, headless: false)
|
options = ::Selenium::WebDriver::Chrome::Options.new
|
||||||
#end
|
options.add_argument('--headless')
|
||||||
|
options.add_argument('--window-size=1280,800') # Set your desired window size
|
||||||
|
|
||||||
=begin
|
Capybara::Selenium::Driver.new(app, browser: :chrome, options: options)
|
||||||
def setup
|
end
|
||||||
Capybara.current_driver = :apparition
|
|
||||||
end
|
|
||||||
|
|
||||||
def teardown
|
|
||||||
Capybara.reset_sessions!
|
|
||||||
Capybara.use_default_driver
|
|
||||||
end
|
|
||||||
=end
|
|
||||||
=begin
|
|
||||||
require 'capybara'
|
|
||||||
require 'capybara/dsl'
|
|
||||||
require 'capybara/poltergeist'
|
|
||||||
require 'rack_session_access/capybara'
|
|
||||||
|
|
||||||
Capybara.app = Sinatra::Application
|
|
||||||
|
|
||||||
def teardown
|
|
||||||
Capybara.reset_sessions!
|
|
||||||
end
|
|
||||||
=end
|
|
|
@ -2,6 +2,7 @@ require_relative './environment.rb'
|
||||||
|
|
||||||
describe '/' do
|
describe '/' do
|
||||||
include Capybara::DSL
|
include Capybara::DSL
|
||||||
|
include Capybara::Minitest::Assertions
|
||||||
|
|
||||||
describe 'news feed' do
|
describe 'news feed' do
|
||||||
before do
|
before do
|
||||||
|
@ -21,7 +22,8 @@ describe '/' do
|
||||||
@another_site = Fabricate :site
|
@another_site = Fabricate :site
|
||||||
@followed_site.toggle_follow @another_site
|
@followed_site.toggle_follow @another_site
|
||||||
visit '/'
|
visit '/'
|
||||||
_(find('.news-item', match: :first).text).must_match /#{@followed_site.username} followed #{@another_site.username}/i
|
_(page).must_have_link(@followed_site.title, href: "/site/#{@followed_site.username}")
|
||||||
|
#_(find('.news-item', match: :first).text).must_match /#{@followed_site.username} followed #{@another_site.username}/i
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'loads my activities only' do
|
it 'loads my activities only' do
|
||||||
|
@ -30,7 +32,7 @@ describe '/' do
|
||||||
@another_site = Fabricate :site
|
@another_site = Fabricate :site
|
||||||
@followed_site.toggle_follow @another_site
|
@followed_site.toggle_follow @another_site
|
||||||
visit '/?activity=mine'
|
visit '/?activity=mine'
|
||||||
_(find('.news-item').text).must_match //i
|
_(page).must_have_link(@followed_site.title, href: "/site/#{@followed_site.username}")
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'loads a specific event with the id' do
|
it 'loads a specific event with the id' do
|
||||||
|
|
|
@ -2,6 +2,7 @@ require_relative './environment.rb'
|
||||||
|
|
||||||
describe '/password_reset' do
|
describe '/password_reset' do
|
||||||
include Capybara::DSL
|
include Capybara::DSL
|
||||||
|
include Capybara::Minitest::Assertions
|
||||||
|
|
||||||
before do
|
before do
|
||||||
Capybara.reset_sessions!
|
Capybara.reset_sessions!
|
||||||
|
@ -67,7 +68,7 @@ describe '/password_reset' do
|
||||||
fill_in 'email', with: @site.email
|
fill_in 'email', with: @site.email
|
||||||
click_button 'Send Reset Token'
|
click_button 'Send Reset Token'
|
||||||
|
|
||||||
_(body).must_match /send an e-mail to your account with password reset instructions/
|
_(body).must_match /We sent an e-mail with password reset instructions/
|
||||||
_(@site.reload.password_reset_token.blank?).must_equal false
|
_(@site.reload.password_reset_token.blank?).must_equal false
|
||||||
_(EmailWorker.jobs.first['args'].first['body']).must_match /#{Rack::Utils.build_query(username: @site.username, token: @site.password_reset_token)}/
|
_(EmailWorker.jobs.first['args'].first['body']).must_match /#{Rack::Utils.build_query(username: @site.username, token: @site.password_reset_token)}/
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
require_relative '../environment.rb'
|
require_relative '../environment.rb'
|
||||||
|
|
||||||
describe 'site/settings' do
|
describe 'site/settings' do
|
||||||
describe 'email' do
|
include Capybara::DSL
|
||||||
include Capybara::DSL
|
include Capybara::Minitest::Assertions
|
||||||
|
|
||||||
|
describe 'email' do
|
||||||
before do
|
before do
|
||||||
EmailWorker.jobs.clear
|
EmailWorker.jobs.clear
|
||||||
@email = "#{SecureRandom.uuid.gsub('-', '')}@exampleedsdfdsf.com"
|
@email = "#{SecureRandom.uuid.gsub('-', '')}@exampleedsdfdsf.com"
|
||||||
|
@ -84,8 +85,6 @@ describe 'site/settings' do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'unsubscribe email' do
|
describe 'unsubscribe email' do
|
||||||
include Capybara::DSL
|
|
||||||
|
|
||||||
before do
|
before do
|
||||||
@email = "#{SecureRandom.uuid.gsub('-', '')}@exampleedsdfdsf.com"
|
@email = "#{SecureRandom.uuid.gsub('-', '')}@exampleedsdfdsf.com"
|
||||||
@site = Fabricate :site, email: @email
|
@site = Fabricate :site, email: @email
|
||||||
|
@ -127,8 +126,6 @@ describe 'site/settings' do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'change password' do
|
describe 'change password' do
|
||||||
include Capybara::DSL
|
|
||||||
|
|
||||||
before do
|
before do
|
||||||
EmailWorker.jobs.clear
|
EmailWorker.jobs.clear
|
||||||
@site = Fabricate :site, password: 'derpie'
|
@site = Fabricate :site, password: 'derpie'
|
||||||
|
|
|
@ -1,88 +1,10 @@
|
||||||
require_relative '../environment.rb'
|
require_relative '../environment.rb'
|
||||||
|
|
||||||
def generate_ssl_certs(opts={})
|
|
||||||
# https://github.com/kyledrake/ruby-openssl-cheat-sheet/blob/master/certificate_authority.rb
|
|
||||||
res = {}
|
|
||||||
|
|
||||||
ca_keypair = OpenSSL::PKey::RSA.new(2048)
|
|
||||||
ca_cert = OpenSSL::X509::Certificate.new
|
|
||||||
ca_cert.not_before = Time.now
|
|
||||||
ca_cert.subject = OpenSSL::X509::Name.new([
|
|
||||||
["C", "US"],
|
|
||||||
["ST", "Oregon"],
|
|
||||||
["L", "Portland"],
|
|
||||||
["CN", "Neocities CA"]
|
|
||||||
])
|
|
||||||
ca_cert.issuer = ca_cert.subject
|
|
||||||
ca_cert.not_after = Time.now + 1000000000 # 40 or so years
|
|
||||||
ca_cert.serial = 1
|
|
||||||
ca_cert.public_key = ca_keypair.public_key
|
|
||||||
ef = OpenSSL::X509::ExtensionFactory.new
|
|
||||||
ef.subject_certificate = ca_cert
|
|
||||||
ef.issuer_certificate = ca_cert
|
|
||||||
# Read more about the various extensions here: http://www.openssl.org/docs/apps/x509v3_config.html
|
|
||||||
ca_cert.add_extension(ef.create_extension("basicConstraints", "CA:TRUE", true))
|
|
||||||
ca_cert.add_extension(ef.create_extension("keyUsage","keyCertSign, cRLSign", true))
|
|
||||||
ca_cert.add_extension(ef.create_extension("subjectKeyIdentifier", "hash", false))
|
|
||||||
ca_cert.add_extension(ef.create_extension("authorityKeyIdentifier", "keyid:always", false))
|
|
||||||
ca_cert.sign(ca_keypair, OpenSSL::Digest::SHA256.new)
|
|
||||||
res[:ca_cert] = ca_cert
|
|
||||||
res[:ca_keypair] = ca_keypair
|
|
||||||
|
|
||||||
ca_cert = OpenSSL::X509::Certificate.new(res[:ca_cert].to_pem)
|
|
||||||
our_cert_keypair = OpenSSL::PKey::RSA.new(2048)
|
|
||||||
our_cert_req = OpenSSL::X509::Request.new
|
|
||||||
our_cert_req.subject = OpenSSL::X509::Name.new([
|
|
||||||
["C", "US"],
|
|
||||||
["ST", "Oregon"],
|
|
||||||
["L", "Portland"],
|
|
||||||
["O", "Neocities User"],
|
|
||||||
["CN", "*.#{opts[:domain]}"]
|
|
||||||
])
|
|
||||||
our_cert_req.public_key = our_cert_keypair.public_key
|
|
||||||
our_cert_req.sign our_cert_keypair, OpenSSL::Digest::SHA1.new
|
|
||||||
our_cert = OpenSSL::X509::Certificate.new
|
|
||||||
our_cert.subject = our_cert_req.subject
|
|
||||||
our_cert.issuer = ca_cert.subject
|
|
||||||
our_cert.not_before = Time.now
|
|
||||||
if opts[:expired]
|
|
||||||
our_cert.not_after = Time.now - 100000000
|
|
||||||
else
|
|
||||||
our_cert.not_after = Time.now + 100000000
|
|
||||||
end
|
|
||||||
our_cert.serial = 123 # Should be an unique number, the CA probably has a database.
|
|
||||||
our_cert.public_key = our_cert_req.public_key
|
|
||||||
# To make the certificate valid for both wildcard and top level domain name, we need an extension.
|
|
||||||
ef = OpenSSL::X509::ExtensionFactory.new
|
|
||||||
ef.subject_certificate = our_cert
|
|
||||||
ef.issuer_certificate = ca_cert
|
|
||||||
our_cert.add_extension(ef.create_extension("subjectAltName", "DNS:#{@domain}, DNS:*.#{@domain}", false))
|
|
||||||
our_cert.sign res[:ca_keypair], OpenSSL::Digest::SHA1.new
|
|
||||||
|
|
||||||
our_cert_tmpfile = Tempfile.new 'our_cert'
|
|
||||||
our_cert_tmpfile.write our_cert.to_pem
|
|
||||||
our_cert_tmpfile.close
|
|
||||||
res[:cert_path] = our_cert_tmpfile.path
|
|
||||||
|
|
||||||
res[:key_path] = '/tmp/nc_test_our_cert_keypair'
|
|
||||||
File.write res[:key_path], our_cert_keypair.to_pem
|
|
||||||
|
|
||||||
res[:cert_intermediate_path] = '/tmp/nc_test_ca_cert'
|
|
||||||
File.write res[:cert_intermediate_path], res[:ca_cert].to_pem
|
|
||||||
|
|
||||||
res[:combined_cert_path] = '/tmp/nc_test_combined_cert'
|
|
||||||
File.write res[:combined_cert_path], "#{File.read(res[:cert_path])}\n#{File.read(res[:cert_intermediate_path])}"
|
|
||||||
|
|
||||||
res[:bad_combined_cert_path] = '/tmp/nc_test_bad_combined_cert'
|
|
||||||
File.write res[:bad_combined_cert_path], "#{File.read(res[:cert_intermediate_path])}\n#{File.read(res[:cert_path])}"
|
|
||||||
|
|
||||||
res
|
|
||||||
end
|
|
||||||
|
|
||||||
describe 'site/settings' do
|
describe 'site/settings' do
|
||||||
describe 'permissions' do
|
include Capybara::DSL
|
||||||
include Capybara::DSL
|
include Capybara::Minitest::Assertions
|
||||||
|
|
||||||
|
describe 'permissions' do
|
||||||
before do
|
before do
|
||||||
@parent_site = Fabricate :site
|
@parent_site = Fabricate :site
|
||||||
@child_site = Fabricate :site, parent_site_id: @parent_site.id
|
@child_site = Fabricate :site, parent_site_id: @parent_site.id
|
||||||
|
@ -104,8 +26,6 @@ describe 'site/settings' do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'changing username' do
|
describe 'changing username' do
|
||||||
include Capybara::DSL
|
|
||||||
|
|
||||||
before do
|
before do
|
||||||
Capybara.reset_sessions!
|
Capybara.reset_sessions!
|
||||||
@site = Fabricate :site
|
@site = Fabricate :site
|
||||||
|
@ -143,142 +63,138 @@ describe 'site/settings' do
|
||||||
_(page).must_have_content /You already have this name/
|
_(page).must_have_content /You already have this name/
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
describe 'api key' do
|
describe 'api key' do
|
||||||
include Capybara::DSL
|
before do
|
||||||
|
Capybara.reset_sessions!
|
||||||
|
@site = Fabricate :site
|
||||||
|
@child_site = Fabricate :site, parent_site_id: @site.id
|
||||||
|
page.set_rack_session id: @site.id
|
||||||
|
end
|
||||||
|
|
||||||
before do
|
it 'sets api key' do
|
||||||
Capybara.reset_sessions!
|
visit "/settings/#{@child_site[:username]}#api_key"
|
||||||
@site = Fabricate :site
|
_(@site.api_key).must_be_nil
|
||||||
@child_site = Fabricate :site, parent_site_id: @site.id
|
_(@child_site.api_key).must_be_nil
|
||||||
page.set_rack_session id: @site.id
|
click_button 'Generate API Key'
|
||||||
|
_(@site.reload.api_key).must_be_nil
|
||||||
|
_(@child_site.reload.api_key).wont_be_nil
|
||||||
|
_(page.body).must_match @child_site.api_key
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'regenerates api key for child site' do
|
||||||
|
visit "/settings/#{@child_site[:username]}#api_key"
|
||||||
|
@child_site.generate_api_key!
|
||||||
|
api_key = @child_site.api_key
|
||||||
|
click_button 'Generate API Key'
|
||||||
|
_(@child_site.reload.api_key).wont_equal api_key
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'sets api key' do
|
describe 'delete' do
|
||||||
visit "/settings/#{@child_site[:username]}#api_key"
|
before do
|
||||||
_(@site.api_key).must_be_nil
|
Capybara.reset_sessions!
|
||||||
_(@child_site.api_key).must_be_nil
|
@site = Fabricate :site
|
||||||
click_button 'Generate API Key'
|
page.set_rack_session id: @site.id
|
||||||
_(@site.reload.api_key).must_be_nil
|
visit "/settings/#{@site[:username]}#delete"
|
||||||
_(@child_site.reload.api_key).wont_be_nil
|
end
|
||||||
_(page.body).must_match @child_site.api_key
|
|
||||||
|
it 'fails for incorrect entered username' do
|
||||||
|
fill_in 'username', with: 'NOPE'
|
||||||
|
click_button 'Delete Site'
|
||||||
|
|
||||||
|
_(page.body).must_match /Site user name and entered user name did not match/i
|
||||||
|
_(@site.reload.is_deleted).must_equal false
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'succeeds' do
|
||||||
|
deleted_reason = 'Penelope left a hairball on my site'
|
||||||
|
|
||||||
|
fill_in 'confirm_username', with: @site.username
|
||||||
|
fill_in 'deleted_reason', with: deleted_reason
|
||||||
|
click_button 'Delete Site'
|
||||||
|
|
||||||
|
@site.reload
|
||||||
|
_(@site.is_deleted).must_equal true
|
||||||
|
_(@site.deleted_reason).must_equal deleted_reason
|
||||||
|
_(page.current_path).must_equal '/'
|
||||||
|
|
||||||
|
_(File.exist?(@site.files_path('./index.html'))).must_equal false
|
||||||
|
_(Dir.exist?(@site.files_path)).must_equal false
|
||||||
|
|
||||||
|
path = File.join Site::DELETED_SITES_ROOT, Site.sharding_dir(@site.username), @site.username
|
||||||
|
_(Dir.exist?(path)).must_equal true
|
||||||
|
_(File.exist?(File.join(path, 'index.html'))).must_equal true
|
||||||
|
|
||||||
|
visit "/site/#{@site.username}"
|
||||||
|
_(page.status_code).must_equal 404
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'stops charging for supporter account' do
|
||||||
|
customer = Stripe::Customer.create(
|
||||||
|
source: $stripe_helper.generate_card_token
|
||||||
|
)
|
||||||
|
|
||||||
|
subscription = customer.subscriptions.create plan: 'supporter'
|
||||||
|
|
||||||
|
@site.update(
|
||||||
|
stripe_customer_id: customer.id,
|
||||||
|
stripe_subscription_id: subscription.id,
|
||||||
|
plan_type: 'supporter'
|
||||||
|
)
|
||||||
|
|
||||||
|
@site.plan_type = subscription.plan.id
|
||||||
|
@site.save_changes
|
||||||
|
|
||||||
|
fill_in 'confirm_username', with: @site.username
|
||||||
|
fill_in 'deleted_reason', with: 'derp'
|
||||||
|
click_button 'Delete Site'
|
||||||
|
|
||||||
|
_(Stripe::Customer.retrieve(@site.stripe_customer_id).subscriptions.count).must_equal 0
|
||||||
|
@site.reload
|
||||||
|
_(@site.stripe_subscription_id).must_be_nil
|
||||||
|
_(@site.is_deleted).must_equal true
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should fail unless owned by current user' do
|
||||||
|
someone_elses_site = Fabricate :site
|
||||||
|
page.set_rack_session id: @site.id
|
||||||
|
|
||||||
|
page.driver.post "/settings/#{someone_elses_site.username}/delete", {
|
||||||
|
username: someone_elses_site.username,
|
||||||
|
deleted_reason: 'Dade Murphy enters Acid Burns turf'
|
||||||
|
}
|
||||||
|
|
||||||
|
_(page.driver.status_code).must_equal 302
|
||||||
|
_(URI.parse(page.driver.response_headers['Location']).path).must_equal '/'
|
||||||
|
someone_elses_site.reload
|
||||||
|
_(someone_elses_site.is_deleted).must_equal false
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should not show NSFW tab for admin NSFW flag' do
|
||||||
|
owned_site = Fabricate :site, parent_site_id: @site.id, admin_nsfw: true
|
||||||
|
visit "/settings/#{owned_site.username}"
|
||||||
|
_(page.body).wont_match /18\+/
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'should succeed if you own the site' do
|
||||||
|
owned_site = Fabricate :site, parent_site_id: @site.id
|
||||||
|
visit "/settings/#{owned_site.username}#delete"
|
||||||
|
fill_in 'confirm_username', with: owned_site.username
|
||||||
|
click_button 'Delete Site'
|
||||||
|
|
||||||
|
@site.reload
|
||||||
|
owned_site.reload
|
||||||
|
_(owned_site.is_deleted).must_equal true
|
||||||
|
_(@site.is_deleted).must_equal false
|
||||||
|
|
||||||
|
_(page.current_path).must_equal "/settings"
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'fails to delete parent site if children exist' do
|
||||||
|
owned_site = Fabricate :site, parent_site_id: @site.id
|
||||||
|
visit "/settings/#{@site.username}#delete"
|
||||||
|
_(page.body).must_match /You cannot delete the parent site without deleting the children sites first/i
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
it 'regenerates api key for child site' do
|
|
||||||
visit "/settings/#{@child_site[:username]}#api_key"
|
|
||||||
@child_site.generate_api_key!
|
|
||||||
api_key = @child_site.api_key
|
|
||||||
click_button 'Generate API Key'
|
|
||||||
_(@child_site.reload.api_key).wont_equal api_key
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe 'delete' do
|
|
||||||
include Capybara::DSL
|
|
||||||
|
|
||||||
before do
|
|
||||||
Capybara.reset_sessions!
|
|
||||||
@site = Fabricate :site
|
|
||||||
page.set_rack_session id: @site.id
|
|
||||||
visit "/settings/#{@site[:username]}#delete"
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'fails for incorrect entered username' do
|
|
||||||
fill_in 'username', with: 'NOPE'
|
|
||||||
click_button 'Delete Site'
|
|
||||||
|
|
||||||
_(page.body).must_match /Site user name and entered user name did not match/i
|
|
||||||
_(@site.reload.is_deleted).must_equal false
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'succeeds' do
|
|
||||||
deleted_reason = 'Penelope left a hairball on my site'
|
|
||||||
|
|
||||||
fill_in 'confirm_username', with: @site.username
|
|
||||||
fill_in 'deleted_reason', with: deleted_reason
|
|
||||||
click_button 'Delete Site'
|
|
||||||
|
|
||||||
@site.reload
|
|
||||||
_(@site.is_deleted).must_equal true
|
|
||||||
_(@site.deleted_reason).must_equal deleted_reason
|
|
||||||
_(page.current_path).must_equal '/'
|
|
||||||
|
|
||||||
_(File.exist?(@site.files_path('./index.html'))).must_equal false
|
|
||||||
_(Dir.exist?(@site.files_path)).must_equal false
|
|
||||||
|
|
||||||
path = File.join Site::DELETED_SITES_ROOT, Site.sharding_dir(@site.username), @site.username
|
|
||||||
_(Dir.exist?(path)).must_equal true
|
|
||||||
_(File.exist?(File.join(path, 'index.html'))).must_equal true
|
|
||||||
|
|
||||||
visit "/site/#{@site.username}"
|
|
||||||
_(page.status_code).must_equal 404
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'stops charging for supporter account' do
|
|
||||||
customer = Stripe::Customer.create(
|
|
||||||
source: $stripe_helper.generate_card_token
|
|
||||||
)
|
|
||||||
|
|
||||||
subscription = customer.subscriptions.create plan: 'supporter'
|
|
||||||
|
|
||||||
@site.update(
|
|
||||||
stripe_customer_id: customer.id,
|
|
||||||
stripe_subscription_id: subscription.id,
|
|
||||||
plan_type: 'supporter'
|
|
||||||
)
|
|
||||||
|
|
||||||
@site.plan_type = subscription.plan.id
|
|
||||||
@site.save_changes
|
|
||||||
|
|
||||||
fill_in 'confirm_username', with: @site.username
|
|
||||||
fill_in 'deleted_reason', with: 'derp'
|
|
||||||
click_button 'Delete Site'
|
|
||||||
|
|
||||||
_(Stripe::Customer.retrieve(@site.stripe_customer_id).subscriptions.count).must_equal 0
|
|
||||||
@site.reload
|
|
||||||
_(@site.stripe_subscription_id).must_be_nil
|
|
||||||
_(@site.is_deleted).must_equal true
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should fail unless owned by current user' do
|
|
||||||
someone_elses_site = Fabricate :site
|
|
||||||
page.set_rack_session id: @site.id
|
|
||||||
|
|
||||||
page.driver.post "/settings/#{someone_elses_site.username}/delete", {
|
|
||||||
username: someone_elses_site.username,
|
|
||||||
deleted_reason: 'Dade Murphy enters Acid Burns turf'
|
|
||||||
}
|
|
||||||
|
|
||||||
_(page.driver.status_code).must_equal 302
|
|
||||||
_(URI.parse(page.driver.response_headers['Location']).path).must_equal '/'
|
|
||||||
someone_elses_site.reload
|
|
||||||
_(someone_elses_site.is_deleted).must_equal false
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should not show NSFW tab for admin NSFW flag' do
|
|
||||||
owned_site = Fabricate :site, parent_site_id: @site.id, admin_nsfw: true
|
|
||||||
visit "/settings/#{owned_site.username}"
|
|
||||||
_(page.body).wont_match /18\+/
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'should succeed if you own the site' do
|
|
||||||
owned_site = Fabricate :site, parent_site_id: @site.id
|
|
||||||
visit "/settings/#{owned_site.username}#delete"
|
|
||||||
fill_in 'confirm_username', with: owned_site.username
|
|
||||||
click_button 'Delete Site'
|
|
||||||
|
|
||||||
@site.reload
|
|
||||||
owned_site.reload
|
|
||||||
_(owned_site.is_deleted).must_equal true
|
|
||||||
_(@site.is_deleted).must_equal false
|
|
||||||
|
|
||||||
_(page.current_path).must_equal "/settings"
|
|
||||||
end
|
|
||||||
|
|
||||||
it 'fails to delete parent site if children exist' do
|
|
||||||
owned_site = Fabricate :site, parent_site_id: @site.id
|
|
||||||
visit "/settings/#{@site.username}#delete"
|
|
||||||
_(page.body).must_match /You cannot delete the parent site without deleting the children sites first/i
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -2,6 +2,7 @@ require_relative './environment.rb'
|
||||||
|
|
||||||
describe 'signin' do
|
describe 'signin' do
|
||||||
include Capybara::DSL
|
include Capybara::DSL
|
||||||
|
include Capybara::Minitest::Assertions
|
||||||
|
|
||||||
def fill_in_valid
|
def fill_in_valid
|
||||||
@site = Fabricate.attributes_for :site
|
@site = Fabricate.attributes_for :site
|
||||||
|
|
|
@ -2,6 +2,7 @@ require_relative './environment.rb'
|
||||||
|
|
||||||
describe 'signup' do
|
describe 'signup' do
|
||||||
include Capybara::DSL
|
include Capybara::DSL
|
||||||
|
include Capybara::Minitest::Assertions
|
||||||
|
|
||||||
def fill_in_valid
|
def fill_in_valid
|
||||||
@site = Fabricate.attributes_for(:site)
|
@site = Fabricate.attributes_for(:site)
|
||||||
|
@ -24,7 +25,7 @@ describe 'signup' do
|
||||||
end
|
end
|
||||||
|
|
||||||
before do
|
before do
|
||||||
Capybara.default_driver = :apparition
|
Capybara.default_driver = :selenium_chrome_headless_largewindow
|
||||||
Capybara.reset_sessions!
|
Capybara.reset_sessions!
|
||||||
visit_signup
|
visit_signup
|
||||||
end
|
end
|
||||||
|
@ -39,7 +40,6 @@ describe 'signup' do
|
||||||
fill_in_valid
|
fill_in_valid
|
||||||
click_signup_button
|
click_signup_button
|
||||||
site_created?
|
site_created?
|
||||||
|
|
||||||
click_link 'Continue'
|
click_link 'Continue'
|
||||||
_(page).must_have_content /almost ready!/
|
_(page).must_have_content /almost ready!/
|
||||||
fill_in 'token', with: Site[username: @site[:username]].email_confirmation_token
|
fill_in 'token', with: Site[username: @site[:username]].email_confirmation_token
|
||||||
|
|
|
@ -2,6 +2,7 @@ require_relative './environment.rb'
|
||||||
|
|
||||||
describe 'site page' do
|
describe 'site page' do
|
||||||
include Capybara::DSL
|
include Capybara::DSL
|
||||||
|
include Capybara::Minitest::Assertions
|
||||||
|
|
||||||
after do
|
after do
|
||||||
Capybara.default_driver = :rack_test
|
Capybara.default_driver = :rack_test
|
||||||
|
|
|
@ -2,9 +2,10 @@ require_relative './environment.rb'
|
||||||
|
|
||||||
describe '/supporter' do
|
describe '/supporter' do
|
||||||
include Capybara::DSL
|
include Capybara::DSL
|
||||||
|
include Capybara::Minitest::Assertions
|
||||||
|
|
||||||
before do
|
before do
|
||||||
Capybara.default_driver = :apparition
|
Capybara.default_driver = :selenium_chrome_headless
|
||||||
Capybara.reset_sessions!
|
Capybara.reset_sessions!
|
||||||
|
|
||||||
@site = Fabricate :site
|
@site = Fabricate :site
|
||||||
|
|
Loading…
Add table
Reference in a new issue