2017-01-14 01:58:59 +01:00
|
|
|
describe 'File Upload and Download' do
|
|
|
|
request('/user/logout')
|
|
|
|
Scripts.login('creator@os4.com', 'creator')
|
|
|
|
|
|
|
|
it 'should upload file when creating ticket' do
|
2017-06-20 21:47:27 +02:00
|
|
|
file = File.new('../server/files/upload(3).txt', 'w+')
|
2017-01-14 01:58:59 +01:00
|
|
|
file.puts('file content')
|
|
|
|
file.close
|
|
|
|
|
|
|
|
result = request('/ticket/create', {
|
|
|
|
'csrf_userid' => $csrf_userid,
|
|
|
|
'csrf_token' => $csrf_token,
|
|
|
|
'title' => 'Ticket with file',
|
|
|
|
'content' => 'this is a ticket that contains a file',
|
|
|
|
'language' => 'en',
|
|
|
|
'departmentId' => 1,
|
2017-06-20 21:47:27 +02:00
|
|
|
'file' => File.open( "../server/files/upload(3).txt")
|
2017-01-14 01:58:59 +01:00
|
|
|
})
|
|
|
|
(result['status']).should.equal('success')
|
|
|
|
|
|
|
|
ticket = $database.getLastRow('ticket')
|
|
|
|
|
2017-06-20 21:47:27 +02:00
|
|
|
(ticket['file'].include? 'upload_3_.txt').should.equal(true)
|
2017-01-14 01:58:59 +01:00
|
|
|
(File.exist? ('../server/files/' + ticket['file'])).should.equal(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should download file if author is logged' do
|
|
|
|
ticket = $database.getLastRow('ticket')
|
|
|
|
file = File.open("../server/files/" + ticket['file'])
|
|
|
|
|
|
|
|
result = plainRequest('/system/download', {
|
|
|
|
'csrf_userid' => $csrf_userid,
|
|
|
|
'csrf_token' => $csrf_token,
|
|
|
|
'file' => ticket['file']
|
2017-02-15 07:08:48 +01:00
|
|
|
}, 'GET')
|
2017-01-14 01:58:59 +01:00
|
|
|
|
|
|
|
(result.body).should.equal(file.read)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should not download if author is not logged' do
|
|
|
|
request('/user/logout')
|
|
|
|
Scripts.login('staff@opensupports.com', 'staff', true)
|
|
|
|
|
|
|
|
ticket = $database.getLastRow('ticket')
|
|
|
|
|
|
|
|
result = plainRequest('/system/download', {
|
|
|
|
'csrf_userid' => $csrf_userid,
|
|
|
|
'csrf_token' => $csrf_token,
|
|
|
|
'file' => ticket['file']
|
2017-02-15 07:08:48 +01:00
|
|
|
}, 'GET')
|
2017-01-14 01:58:59 +01:00
|
|
|
|
|
|
|
(result.body).should.equal('')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'should download if owner is logged' do
|
|
|
|
ticket = $database.getLastRow('ticket')
|
|
|
|
file = File.open("../server/files/" + ticket['file'])
|
|
|
|
|
|
|
|
request('/staff/assign-ticket', {
|
|
|
|
'csrf_userid' => $csrf_userid,
|
|
|
|
'csrf_token' => $csrf_token,
|
|
|
|
'ticketNumber' => ticket['ticket_number']
|
|
|
|
})
|
|
|
|
|
|
|
|
result = plainRequest('/system/download', {
|
|
|
|
'csrf_userid' => $csrf_userid,
|
|
|
|
'csrf_token' => $csrf_token,
|
|
|
|
'file' => ticket['file']
|
2017-02-15 07:08:48 +01:00
|
|
|
}, 'GET')
|
2017-01-14 01:58:59 +01:00
|
|
|
|
|
|
|
(result.body).should.equal(file.read)
|
|
|
|
end
|
|
|
|
|
2017-02-18 19:55:09 +01:00
|
|
|
it 'should upload profile picture' do
|
|
|
|
file = File.new('../server/files/profile.jpg', 'w+')
|
|
|
|
file.puts('file content')
|
|
|
|
file.close
|
|
|
|
|
|
|
|
request('/staff/edit', {
|
|
|
|
'csrf_userid' => $csrf_userid,
|
|
|
|
'csrf_token' => $csrf_token,
|
|
|
|
'staffId' => $csrf_userid,
|
|
|
|
'file' => File.open( "../server/files/profile.jpg")
|
|
|
|
})
|
|
|
|
|
|
|
|
user = $database.getRow('staff', $csrf_userid)
|
|
|
|
|
|
|
|
result = plainRequest('/system/download', {
|
|
|
|
'csrf_userid' => $csrf_userid,
|
|
|
|
'csrf_token' => $csrf_token,
|
|
|
|
'file' => user['profile_pic']
|
|
|
|
}, 'GET')
|
|
|
|
|
|
|
|
(result.body).should.include('file content')
|
|
|
|
end
|
2017-01-14 01:58:59 +01:00
|
|
|
end
|