mirror of
https://github.com/neocities/neocities.git
synced 2025-07-21 01:56:03 +02:00
mostly finished port to ruby3
This commit is contained in:
parent
a9dd102383
commit
0ca1473d22
30 changed files with 765 additions and 731 deletions
|
@ -26,9 +26,9 @@ describe 'api' do
|
|||
describe 'not found' do
|
||||
it 'returns json for missing route' do
|
||||
get '/api/sdlfkjsdlfjds'
|
||||
last_response.status.must_equal 404
|
||||
res[:result].must_equal 'error'
|
||||
res[:error_type].must_equal 'not_found'
|
||||
_(last_response.status).must_equal 404
|
||||
_(res[:result]).must_equal 'error'
|
||||
_(res[:error_type]).must_equal 'not_found'
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -38,15 +38,15 @@ describe 'api' do
|
|||
basic_authorize @user, @pass
|
||||
get '/api/list'
|
||||
|
||||
res[:result].must_equal 'success'
|
||||
res[:files].length.must_equal @site.site_files.length
|
||||
_(res[:result]).must_equal 'success'
|
||||
_(res[:files].length).must_equal @site.site_files.length
|
||||
|
||||
res[:files].each do |file|
|
||||
site_file = @site.site_files.select {|s| s[:path] == file[:path]}.first
|
||||
site_file[:is_directory].must_equal file[:is_directory]
|
||||
site_file[:size].must_equal file[:size]
|
||||
site_file[:updated_at].rfc2822.must_equal file[:updated_at]
|
||||
site_file[:sha1_hash].must_equal file[:sha1_hash]
|
||||
_(site_file[:is_directory]).must_equal file[:is_directory]
|
||||
_(site_file[:size]).must_equal file[:size]
|
||||
_(site_file[:updated_at].rfc2822).must_equal file[:updated_at]
|
||||
_(site_file[:sha1_hash]).must_equal file[:sha1_hash]
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -54,8 +54,8 @@ describe 'api' do
|
|||
create_site
|
||||
basic_authorize @user, @pass
|
||||
get '/api/list', path: '/fail'
|
||||
res[:result].must_equal 'success'
|
||||
res[:files].must_equal []
|
||||
_(res[:result]).must_equal 'success'
|
||||
_(res[:files]).must_equal []
|
||||
end
|
||||
|
||||
it 'shows files in path' do
|
||||
|
@ -65,11 +65,11 @@ describe 'api' do
|
|||
@site.store_files [{filename: '/derp/test.html', tempfile: tempfile}]
|
||||
basic_authorize @user, @pass
|
||||
get '/api/list', path: '/derp'
|
||||
res[:result].must_equal 'success'
|
||||
res[:files].length.must_equal 1
|
||||
_(res[:result]).must_equal 'success'
|
||||
_(res[:files].length).must_equal 1
|
||||
file = res[:files].first
|
||||
file[:path].must_equal 'derp/test.html'
|
||||
file[:updated_at].must_equal @site.site_files.select {|s| s.path == 'derp/test.html'}.first.updated_at.rfc2822
|
||||
_(file[:path]).must_equal 'derp/test.html'
|
||||
_(file[:updated_at]).must_equal @site.site_files.select {|s| s.path == 'derp/test.html'}.first.updated_at.rfc2822
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -83,13 +83,13 @@ describe 'api' do
|
|||
create_site
|
||||
@site.update is_banned: true
|
||||
get '/api/info', sitename: @site.username
|
||||
res[:error_type].must_equal 'site_not_found'
|
||||
@site.reload.api_calls.must_equal 0
|
||||
_(res[:error_type]).must_equal 'site_not_found'
|
||||
_(@site.reload.api_calls).must_equal 0
|
||||
end
|
||||
|
||||
it 'fails for nonexistent site' do
|
||||
get '/api/info', sitename: 'notexist'
|
||||
res[:error_type].must_equal 'site_not_found'
|
||||
_(res[:error_type]).must_equal 'site_not_found'
|
||||
end
|
||||
|
||||
it 'succeeds for valid sitename' do
|
||||
|
@ -97,27 +97,27 @@ describe 'api' do
|
|||
@site.update hits: 31337, domain: 'derp.com', new_tags_string: 'derpie, man'
|
||||
@site.add_archive ipfs_hash: 'QmXGTaGWTT1uUtfSb2sBAvArMEVLK4rQEcQg5bv7wwdzwU'
|
||||
get '/api/info', sitename: @user
|
||||
res[:result].must_equal 'success'
|
||||
res[:info][:sitename].must_equal @site.username
|
||||
res[:info][:hits].must_equal 31337
|
||||
res[:info][:created_at].must_equal @site.created_at.rfc2822
|
||||
res[:info][:last_updated].must_be_nil
|
||||
res[:info][:domain].must_equal 'derp.com'
|
||||
res[:info][:tags].must_equal ['derpie', 'man']
|
||||
res[:info][:latest_ipfs_hash].must_equal 'QmXGTaGWTT1uUtfSb2sBAvArMEVLK4rQEcQg5bv7wwdzwU'
|
||||
@site.reload.api_calls.must_equal 0
|
||||
_(res[:result]).must_equal 'success'
|
||||
_(res[:info][:sitename]).must_equal @site.username
|
||||
_(res[:info][:hits]).must_equal 31337
|
||||
_(res[:info][:created_at]).must_equal @site.created_at.rfc2822
|
||||
_(res[:info][:last_updated]).must_be_nil
|
||||
_(res[:info][:domain]).must_equal 'derp.com'
|
||||
_(res[:info][:tags]).must_equal ['derpie', 'man']
|
||||
_(res[:info][:latest_ipfs_hash]).must_equal 'QmXGTaGWTT1uUtfSb2sBAvArMEVLK4rQEcQg5bv7wwdzwU'
|
||||
_(@site.reload.api_calls).must_equal 0
|
||||
end
|
||||
|
||||
it 'shows latest ipfs hash as nil when not present' do
|
||||
create_site
|
||||
get '/api/info', sitename: @user
|
||||
res[:info][:latest_ipfs_hash].must_be_nil
|
||||
_(res[:info][:latest_ipfs_hash]).must_be_nil
|
||||
end
|
||||
|
||||
it 'fails for bad auth' do
|
||||
basic_authorize 'derp', 'fake'
|
||||
get '/api/info'
|
||||
res[:error_type].must_equal 'invalid_auth'
|
||||
_(res[:error_type]).must_equal 'invalid_auth'
|
||||
end
|
||||
|
||||
it 'succeeds for api auth' do
|
||||
|
@ -132,25 +132,25 @@ describe 'api' do
|
|||
describe 'delete' do
|
||||
it 'fails with no or bad auth' do
|
||||
post '/api/delete', filenames: ['hi.html']
|
||||
res[:error_type].must_equal 'invalid_auth'
|
||||
_(res[:error_type]).must_equal 'invalid_auth'
|
||||
create_site
|
||||
basic_authorize 'derp', 'fake'
|
||||
post '/api/delete', filenames: ['hi.html']
|
||||
res[:error_type].must_equal 'invalid_auth'
|
||||
_(res[:error_type]).must_equal 'invalid_auth'
|
||||
end
|
||||
|
||||
it 'fails with missing filename argument' do
|
||||
create_site
|
||||
basic_authorize @user, @pass
|
||||
post '/api/delete'
|
||||
res[:error_type].must_equal 'missing_filenames'
|
||||
_(res[:error_type]).must_equal 'missing_filenames'
|
||||
end
|
||||
|
||||
it 'fails to delete index.html' do
|
||||
create_site
|
||||
basic_authorize @user, @pass
|
||||
post '/api/delete', filenames: ['index.html']
|
||||
res[:error_type].must_equal 'cannot_delete_index'
|
||||
_(res[:error_type]).must_equal 'cannot_delete_index'
|
||||
end
|
||||
|
||||
it 'succeeds with weird filenames' do
|
||||
|
@ -158,12 +158,12 @@ describe 'api' do
|
|||
basic_authorize @user, @pass
|
||||
@site.store_files [{filename: 't$st.jpg', tempfile: Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')}]
|
||||
post '/api/delete', filenames: ['t$st.jpg']
|
||||
res[:result].must_equal 'success'
|
||||
_(res[:result]).must_equal 'success'
|
||||
|
||||
create_site
|
||||
basic_authorize @user, @pass
|
||||
post '/api/delete', filenames: ['./config.yml']
|
||||
res[:error_type].must_equal 'missing_files'
|
||||
_(res[:error_type]).must_equal 'missing_files'
|
||||
end
|
||||
|
||||
it 'fails with missing files' do
|
||||
|
@ -171,15 +171,15 @@ describe 'api' do
|
|||
basic_authorize @user, @pass
|
||||
@site.store_files [{filename: 'test.jpg', tempfile: Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')}]
|
||||
post '/api/delete', filenames: ['doesntexist.jpg']
|
||||
res[:error_type].must_equal 'missing_files'
|
||||
_(res[:error_type]).must_equal 'missing_files'
|
||||
end
|
||||
|
||||
it 'fails to delete site directory' do
|
||||
create_site
|
||||
basic_authorize @user, @pass
|
||||
post '/api/delete', filenames: ['/']
|
||||
res[:error_type].must_equal 'cannot_delete_site_directory'
|
||||
File.exist?(@site.files_path).must_equal true
|
||||
_(res[:error_type]).must_equal 'cannot_delete_site_directory'
|
||||
_(File.exist?(@site.files_path)).must_equal true
|
||||
end
|
||||
|
||||
it 'fails to delete other directories' do
|
||||
|
@ -188,11 +188,11 @@ describe 'api' do
|
|||
create_site
|
||||
basic_authorize @user, @pass
|
||||
post '/api/delete', filenames: ["../#{@other_site.username}"]
|
||||
File.exist?(@other_site.base_files_path).must_equal true
|
||||
res[:error_type].must_equal 'missing_files'
|
||||
_(File.exist?(@other_site.base_files_path)).must_equal true
|
||||
_(res[:error_type]).must_equal 'missing_files'
|
||||
post '/api/delete', filenames: ["../#{@other_site.username}/index.html"]
|
||||
File.exist?(@other_site.base_files_path+'/index.html').must_equal true
|
||||
res[:error_type].must_equal 'missing_files'
|
||||
_(File.exist?(@other_site.base_files_path+'/index.html')).must_equal true
|
||||
_(res[:error_type]).must_equal 'missing_files'
|
||||
end
|
||||
|
||||
it 'succeeds with valid filenames' do
|
||||
|
@ -201,9 +201,9 @@ describe 'api' do
|
|||
@site.store_files [{filename: 'test.jpg', tempfile: Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')}]
|
||||
@site.store_files [{filename: 'test2.jpg', tempfile: Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')}]
|
||||
post '/api/delete', filenames: ['test.jpg', 'test2.jpg']
|
||||
res[:result].must_equal 'success'
|
||||
site_file_exists?('test.jpg').must_equal false
|
||||
site_file_exists?('test2.jpg').must_equal false
|
||||
_(res[:result]).must_equal 'success'
|
||||
_(site_file_exists?('test.jpg')).must_equal false
|
||||
_(site_file_exists?('test2.jpg')).must_equal false
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -212,8 +212,8 @@ describe 'api' do
|
|||
create_site
|
||||
basic_authorize @user, @pass
|
||||
get '/api/key'
|
||||
res[:result].must_equal 'success'
|
||||
res[:api_key].must_equal @site.reload.api_key
|
||||
_(res[:result]).must_equal 'success'
|
||||
_(res[:api_key]).must_equal @site.reload.api_key
|
||||
end
|
||||
|
||||
it 'returns existing key' do
|
||||
|
@ -221,14 +221,14 @@ describe 'api' do
|
|||
@site.generate_api_key!
|
||||
basic_authorize @user, @pass
|
||||
get '/api/key'
|
||||
res[:api_key].must_equal @site.api_key
|
||||
_(res[:api_key]).must_equal @site.api_key
|
||||
end
|
||||
|
||||
it 'fails for bad login' do
|
||||
create_site
|
||||
basic_authorize 'zero', 'cool'
|
||||
get '/api/key'
|
||||
res[:error_type].must_equal 'invalid_auth'
|
||||
_(res[:error_type]).must_equal 'invalid_auth'
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -245,9 +245,9 @@ describe 'api' do
|
|||
|
||||
post '/api/upload_hash', "test.jpg" => test_hash, "test2.jpg" => Digest::SHA1.hexdigest('herpderp')
|
||||
|
||||
res[:result].must_equal 'success'
|
||||
res[:files][:'test.jpg'].must_equal true
|
||||
res[:files][:'test2.jpg'].must_equal false
|
||||
_(res[:result]).must_equal 'success'
|
||||
_(res[:files][:'test.jpg']).must_equal true
|
||||
_(res[:files][:'test2.jpg']).must_equal false
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -262,58 +262,58 @@ describe 'api' do
|
|||
|
||||
it 'succeeds' do
|
||||
post '/api/rename', path: 'testdir/test.jpg', new_path: 'testdir/test2.jpg'
|
||||
res[:result].must_equal 'success'
|
||||
_(res[:result]).must_equal 'success'
|
||||
end
|
||||
|
||||
it 'fails to overwrite index file' do
|
||||
post '/api/rename', path: 'testdir/test.jpg', new_path: 'index.html'
|
||||
res[:result].must_equal 'error'
|
||||
res[:error_type].must_equal 'rename_error'
|
||||
res[:message].must_equal 'file already exists'
|
||||
_(res[:result]).must_equal 'error'
|
||||
_(res[:error_type]).must_equal 'rename_error'
|
||||
_(res[:message]).must_equal 'file already exists'
|
||||
end
|
||||
|
||||
it 'fails to overwrite existing file' do
|
||||
post '/api/rename', path: 'testdir/test.jpg', new_path: 'not_found.html'
|
||||
res[:result].must_equal 'error'
|
||||
res[:error_type].must_equal 'rename_error'
|
||||
_(res[:result]).must_equal 'error'
|
||||
_(res[:error_type]).must_equal 'rename_error'
|
||||
end
|
||||
|
||||
it 'succeeds with directory' do
|
||||
@site.create_directory 'derpiedir'
|
||||
post '/api/rename', path: 'derpiedir', new_path: 'notderpiedir'
|
||||
res[:result].must_equal 'success'
|
||||
_(res[:result]).must_equal 'success'
|
||||
end
|
||||
end
|
||||
|
||||
describe 'upload' do
|
||||
it 'fails with no auth' do
|
||||
post '/api/upload'
|
||||
res[:result].must_equal 'error'
|
||||
res[:error_type].must_equal 'invalid_auth'
|
||||
_(res[:result]).must_equal 'error'
|
||||
_(res[:error_type]).must_equal 'invalid_auth'
|
||||
end
|
||||
|
||||
it 'fails for bad auth' do
|
||||
basic_authorize 'username', 'password'
|
||||
post '/api/upload'
|
||||
res[:error_type].must_equal 'invalid_auth'
|
||||
_(res[:error_type]).must_equal 'invalid_auth'
|
||||
end
|
||||
|
||||
it 'fails with missing files' do
|
||||
create_site
|
||||
basic_authorize @user, @pass
|
||||
post '/api/upload'
|
||||
res[:error_type].must_equal 'missing_files'
|
||||
_(res[:error_type]).must_equal 'missing_files'
|
||||
end
|
||||
|
||||
it 'succeeds with valid api key' do
|
||||
create_site
|
||||
@site.api_key.must_be_nil
|
||||
_(@site.api_key).must_be_nil
|
||||
@site.generate_api_key!
|
||||
@site.reload.api_key.wont_equal nil
|
||||
_(@site.reload.api_key).wont_equal nil
|
||||
header 'Authorization', "Bearer #{@site.api_key}"
|
||||
post '/api/upload', 'test.jpg' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
|
||||
res[:result].must_equal 'success'
|
||||
site_file_exists?('test.jpg').must_equal true
|
||||
_(res[:result]).must_equal 'success'
|
||||
_(site_file_exists?('test.jpg')).must_equal true
|
||||
end
|
||||
|
||||
it 'fails with bad api key' do
|
||||
|
@ -321,8 +321,8 @@ describe 'api' do
|
|||
@site.generate_api_key!
|
||||
header 'Authorization', "Bearer zerocool"
|
||||
post '/api/upload', 'test.jpg' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
|
||||
res[:result].must_equal 'error'
|
||||
res[:error_type].must_equal 'invalid_auth'
|
||||
_(res[:result]).must_equal 'error'
|
||||
_(res[:error_type]).must_equal 'invalid_auth'
|
||||
end
|
||||
|
||||
=begin
|
||||
|
@ -337,7 +337,7 @@ describe 'api' do
|
|||
post '/api/upload', {
|
||||
'/lol.jpg' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
|
||||
}
|
||||
res[:error_type].must_equal 'too_many_files'
|
||||
_(res[:error_type]).must_equal 'too_many_files'
|
||||
end
|
||||
=end
|
||||
|
||||
|
@ -347,9 +347,9 @@ describe 'api' do
|
|||
post '/api/upload', {
|
||||
'../lol.jpg' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
|
||||
}
|
||||
res[:result].must_equal 'success'
|
||||
File.exist?(File.join(Site::SITE_FILES_ROOT, Site.sharding_dir(@site.username), @site.username, 'lol.jpg')).must_equal true
|
||||
@site.reload.api_calls.must_equal 1
|
||||
_(res[:result]).must_equal 'success'
|
||||
_(File.exist?(File.join(Site::SITE_FILES_ROOT, Site.sharding_dir(@site.username), @site.username, 'lol.jpg'))).must_equal true
|
||||
_(@site.reload.api_calls).must_equal 1
|
||||
end
|
||||
|
||||
it 'scrubs root path slash' do
|
||||
|
@ -358,8 +358,8 @@ describe 'api' do
|
|||
post '/api/upload', {
|
||||
'/lol.jpg' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
|
||||
}
|
||||
res[:result].must_equal 'success'
|
||||
File.exist?(File.join(Site::SITE_FILES_ROOT, Site.sharding_dir(@site.username), @site.username, 'lol.jpg')).must_equal true
|
||||
_(res[:result]).must_equal 'success'
|
||||
_(File.exist?(File.join(Site::SITE_FILES_ROOT, Site.sharding_dir(@site.username), @site.username, 'lol.jpg'))).must_equal true
|
||||
end
|
||||
|
||||
it 'fails for missing file name' do
|
||||
|
@ -368,7 +368,7 @@ describe 'api' do
|
|||
post '/api/upload', {
|
||||
'/' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
|
||||
}
|
||||
res[:error_type].must_equal 'invalid_file_type'
|
||||
_(res[:error_type]).must_equal 'invalid_file_type'
|
||||
end
|
||||
|
||||
it 'fails for file with no extension' do
|
||||
|
@ -377,7 +377,7 @@ describe 'api' do
|
|||
post '/api/upload', {
|
||||
'derpie' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
|
||||
}
|
||||
res[:error_type].must_equal 'invalid_file_type'
|
||||
_(res[:error_type]).must_equal 'invalid_file_type'
|
||||
end
|
||||
|
||||
it 'creates path for file uploads' do
|
||||
|
@ -386,8 +386,8 @@ describe 'api' do
|
|||
post '/api/upload', {
|
||||
'derpie/derpingtons/lol.jpg' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
|
||||
}
|
||||
res[:result].must_equal 'success'
|
||||
File.exist?(@site.files_path('derpie/derpingtons/lol.jpg')).must_equal true
|
||||
_(res[:result]).must_equal 'success'
|
||||
_(File.exist?(@site.files_path('derpie/derpingtons/lol.jpg'))).must_equal true
|
||||
end
|
||||
|
||||
it 'records api calls that require auth' do
|
||||
|
@ -400,7 +400,7 @@ describe 'api' do
|
|||
}
|
||||
}
|
||||
|
||||
@site.reload.api_calls.must_equal 2
|
||||
_(@site.reload.api_calls).must_equal 2
|
||||
end
|
||||
|
||||
it 'fails for invalid files' do
|
||||
|
@ -410,17 +410,17 @@ describe 'api' do
|
|||
'test.jpg' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg'),
|
||||
'nord.avi' => Rack::Test::UploadedFile.new('./tests/files/flowercrime.wav', 'image/jpeg')
|
||||
}
|
||||
res[:error_type].must_equal 'invalid_file_type'
|
||||
site_file_exists?('test.jpg').must_equal false
|
||||
site_file_exists?('nord.avi').must_equal false
|
||||
_(res[:error_type]).must_equal 'invalid_file_type'
|
||||
_(site_file_exists?('test.jpg')).must_equal false
|
||||
_(site_file_exists?('nord.avi')).must_equal false
|
||||
end
|
||||
|
||||
it 'succeeds with single file' do
|
||||
create_site
|
||||
basic_authorize @user, @pass
|
||||
post '/api/upload', 'test.jpg' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
|
||||
res[:result].must_equal 'success'
|
||||
site_file_exists?('test.jpg').must_equal true
|
||||
_(res[:result]).must_equal 'success'
|
||||
_(site_file_exists?('test.jpg')).must_equal true
|
||||
end
|
||||
|
||||
it 'succeeds with two files' do
|
||||
|
@ -430,18 +430,18 @@ describe 'api' do
|
|||
'test.jpg' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg'),
|
||||
'test2.jpg' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
|
||||
}
|
||||
res[:result].must_equal 'success'
|
||||
site_file_exists?('test.jpg').must_equal true
|
||||
site_file_exists?('test2.jpg').must_equal true
|
||||
_(res[:result]).must_equal 'success'
|
||||
_(site_file_exists?('test.jpg')).must_equal true
|
||||
_(site_file_exists?('test2.jpg')).must_equal true
|
||||
end
|
||||
|
||||
it 'fails with unwhitelisted file' do
|
||||
create_site
|
||||
basic_authorize @user, @pass
|
||||
post '/api/upload', 'flowercrime.wav' => Rack::Test::UploadedFile.new('./tests/files/flowercrime.wav', 'audio/x-wav')
|
||||
res[:result].must_equal 'error'
|
||||
res[:error_type].must_equal 'invalid_file_type'
|
||||
site_file_exists?('flowercrime.wav').must_equal false
|
||||
_(res[:result]).must_equal 'error'
|
||||
_(res[:error_type]).must_equal 'invalid_file_type'
|
||||
_(site_file_exists?('flowercrime.wav')).must_equal false
|
||||
end
|
||||
|
||||
it 'succeeds for unwhitelisted file on supported plans' do
|
||||
|
@ -450,8 +450,8 @@ describe 'api' do
|
|||
create_site plan_type: plan_type
|
||||
basic_authorize @user, @pass
|
||||
post '/api/upload', 'flowercrime.wav' => Rack::Test::UploadedFile.new('./tests/files/flowercrime.wav', 'audio/x-wav')
|
||||
res[:result].must_equal 'success'
|
||||
site_file_exists?('flowercrime.wav').must_equal true
|
||||
_(res[:result]).must_equal 'success'
|
||||
_(site_file_exists?('flowercrime.wav')).must_equal true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue