mirror of
https://github.com/neocities/neocities.git
synced 2025-07-24 19:38:25 +02:00
api: add upload_hash for checking file hash before uploading
This commit is contained in:
parent
7d17202f39
commit
4a2926508e
3 changed files with 55 additions and 0 deletions
|
@ -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'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue