fixes for upload hash check, catch index.html delete scenario

This commit is contained in:
Kyle Drake 2017-05-21 20:16:37 -07:00
parent 61bf9012d6
commit bf089379aa
2 changed files with 4 additions and 24 deletions

View file

@ -7,17 +7,11 @@ end
post '/api/upload_hash' do post '/api/upload_hash' do
require_api_credentials require_api_credentials
res = {} res = {}
files = []
if params[:files].blank? || !params[:files].is_a?(Hash) params.each do |k,v|
api_error 400, 'no_file_hashes_provided', 'no file hashes provided'
end
params[:files].each do |k,v|
res[k] = current_site.sha1_hash_match? k, v res[k] = current_site.sha1_hash_match? k, v
end end
api_success files: res api_success files: res
end end
@ -101,7 +95,7 @@ post '/api/delete' do
api_error 400, 'missing_files', "#{path} was not found on your site, canceled deleting" api_error 400, 'missing_files', "#{path} was not found on your site, canceled deleting"
end end
if path == 'index.html' if path == 'index.html' || path == '/index.html'
api_error 400, 'cannot_delete_index', 'you cannot delete your index.html file, canceled deleting' api_error 400, 'cannot_delete_index', 'you cannot delete your index.html file, canceled deleting'
end end

View file

@ -233,26 +233,12 @@ describe 'api upload hash' do
'test2.jpg' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg') 'test2.jpg' => Rack::Test::UploadedFile.new('./tests/files/test.jpg', 'image/jpeg')
} }
post '/api/upload_hash', "files[test.jpg]" => test_hash, "files[test2.jpg]" => Digest::SHA1.hexdigest('herpderp') post '/api/upload_hash', "test.jpg" => test_hash, "test2.jpg" => Digest::SHA1.hexdigest('herpderp')
res[:result].must_equal 'success' res[:result].must_equal 'success'
res[:files][:'test.jpg'].must_equal true res[:files][:'test.jpg'].must_equal true
res[:files][:'test2.jpg'].must_equal false res[:files][:'test2.jpg'].must_equal false
end end
it 'throws error for missing data' do
create_site
basic_authorize @user, @pass
post '/api/upload_hash'
res[:error_type].must_equal 'no_file_hashes_provided'
end
it 'throws errors for weird data' do
create_site
basic_authorize @user, @pass
post '/api/upload_hash', 'files[]' => 'DUMPSTER FIRE'
res[:error_type].must_equal 'no_file_hashes_provided'
end
end end
describe 'api upload' do describe 'api upload' do