api: add upload_hash for checking file hash before uploading

This commit is contained in:
Kyle Drake 2017-05-21 17:32:26 -05:00
parent 7d17202f39
commit 4a2926508e
3 changed files with 55 additions and 0 deletions

View file

@ -222,6 +222,39 @@ describe 'api key' do
end
end
describe 'api upload hash' do
it 'succeeds' do
create_site
basic_authorize @user, @pass
test_hash = Digest::SHA1.file('./tests/files/test.jpg').hexdigest
post '/api/upload', {
'test.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')
res[:result].must_equal 'success'
res[:files][:'test.jpg'].must_equal true
res[:files][:'test2.jpg'].must_equal false
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
describe 'api upload' do
it 'fails with no auth' do
post '/api/upload'