2014-08-30 17:38:47 +00:00
|
|
|
require 'rails_helper'
|
2013-08-08 13:41:57 +00:00
|
|
|
|
2014-02-25 17:28:57 +00:00
|
|
|
describe "Asciicast creation" do
|
2014-02-11 16:49:22 +00:00
|
|
|
|
2015-02-26 13:14:32 +00:00
|
|
|
let(:created_asciicast) { Asciicast.last }
|
|
|
|
|
|
|
|
def basic_auth_header(user, password)
|
|
|
|
{ 'HTTP_AUTHORIZATION' => ActionController::HttpAuthentication::Basic.encode_credentials(user, password) }
|
|
|
|
end
|
|
|
|
|
|
|
|
def user_agent_header(user_agent)
|
|
|
|
{ 'User-Agent' => user_agent }
|
|
|
|
end
|
|
|
|
|
|
|
|
def headers(user, password, user_agent)
|
2015-03-23 16:20:11 +00:00
|
|
|
{}.tap do |h|
|
|
|
|
h.merge!(basic_auth_header(user, password)) if user
|
|
|
|
h.merge!(user_agent_header(user_agent)) if user_agent
|
|
|
|
end
|
2014-02-11 16:49:22 +00:00
|
|
|
end
|
2013-08-08 13:41:57 +00:00
|
|
|
|
2015-02-26 13:14:32 +00:00
|
|
|
context '<= v0.9.7 client' do
|
|
|
|
subject { make_request }
|
|
|
|
|
|
|
|
def make_request
|
|
|
|
post '/api/asciicasts',
|
|
|
|
{
|
|
|
|
asciicast: {
|
|
|
|
meta: fixture_file('0.9.7/meta.json', 'application/json'),
|
|
|
|
stdout: fixture_file('0.9.7/stdout', 'application/octet-stream'),
|
|
|
|
stdout_timing: fixture_file('0.9.7/stdout.time', 'application/octet-stream')
|
|
|
|
}
|
|
|
|
}, headers(nil, nil, 'python-requests blah/blah')
|
|
|
|
end
|
|
|
|
|
|
|
|
before { subject }
|
|
|
|
|
2015-02-27 13:58:04 +00:00
|
|
|
it 'creates asciicast version 0' do
|
|
|
|
expect(created_asciicast.version).to eq(0)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates asciicast with given stdout data file' do
|
|
|
|
expect(created_asciicast.stdout_data).to_not be(nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates asciicast with given stdout timing file' do
|
|
|
|
expect(created_asciicast.stdout_timing).to_not be(nil)
|
|
|
|
end
|
|
|
|
|
2015-02-26 13:14:32 +00:00
|
|
|
it 'creates asciicast with given command' do
|
|
|
|
expect(created_asciicast.command).to eq('/bin/bash')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates asciicast with given duration' do
|
|
|
|
expect(created_asciicast.duration).to eq(11.146430015564)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates asciicast with given shell' do
|
|
|
|
expect(created_asciicast.shell).to eq('/bin/zsh')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates asciicast with given terminal type' do
|
|
|
|
expect(created_asciicast.terminal_type).to eq('screen-256color')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates asciicast with given terminal width' do
|
|
|
|
expect(created_asciicast.terminal_columns).to eq(96)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates asciicast with given terminal height' do
|
|
|
|
expect(created_asciicast.terminal_lines).to eq(26)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates asciicast with given title' do
|
|
|
|
expect(created_asciicast.title).to eq('bashing :)')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates asciicast with given uname' do
|
|
|
|
expect(created_asciicast.uname).to eq('Linux 3.9.9-302.fc19.x86_64 #1 SMP Sat Jul 6 13:41:07 UTC 2013 x86_64')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates asciicast with no user agent set' do
|
|
|
|
expect(created_asciicast.user_agent).to be(nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a user with given token does not exist' do
|
|
|
|
let(:created_user) { User.last }
|
|
|
|
|
|
|
|
it 'creates new user with given username and token' do
|
|
|
|
expect(created_user.temporary_username).to eq('kill')
|
|
|
|
expect(created_user.api_tokens.first.token).to eq('f33e6188-f53c-11e2-abf4-84a6c827e88b')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates asciicast assigned to newly created user' do
|
|
|
|
expect(created_asciicast.user).to eq(created_user)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a user with given token exists' do
|
2015-04-03 16:48:37 +00:00
|
|
|
let(:user) { ApiToken.create_with_tmp_user!('f33e6188-f53c-11e2-abf4-84a6c827e88b', 'kill').user }
|
2015-02-26 13:14:32 +00:00
|
|
|
|
|
|
|
subject do
|
|
|
|
user
|
|
|
|
make_request
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates asciicast assigned to a user with given token' do
|
|
|
|
expect(created_asciicast.user).to eq(user)
|
|
|
|
end
|
|
|
|
end
|
2014-02-11 16:49:22 +00:00
|
|
|
|
2015-02-26 13:14:32 +00:00
|
|
|
it 'returns the URL to the uploaded asciicast' do
|
|
|
|
expect(response.body).to eq(asciicast_url(created_asciicast))
|
|
|
|
end
|
2013-08-08 13:41:57 +00:00
|
|
|
end
|
2014-02-11 16:49:22 +00:00
|
|
|
|
2015-02-26 13:14:32 +00:00
|
|
|
context 'v0.9.8 client' do
|
|
|
|
subject { make_request }
|
|
|
|
|
|
|
|
def make_request
|
|
|
|
post '/api/asciicasts',
|
|
|
|
{
|
|
|
|
asciicast: {
|
|
|
|
meta: fixture_file('0.9.8/meta.json', 'application/json'),
|
|
|
|
stdout: fixture_file('0.9.8/stdout', 'application/octet-stream'),
|
|
|
|
stdout_timing: fixture_file('0.9.8/stdout.time', 'application/octet-stream')
|
|
|
|
}
|
|
|
|
}, headers(nil, nil, 'asciinema/0.9.8 CPython/2.7.4 Jola/Misio-Foo')
|
|
|
|
end
|
|
|
|
|
|
|
|
before { subject }
|
|
|
|
|
2015-02-27 13:58:04 +00:00
|
|
|
it 'creates asciicast version 0' do
|
|
|
|
expect(created_asciicast.version).to eq(0)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates asciicast with given stdout data file' do
|
|
|
|
expect(created_asciicast.stdout_data).to_not be(nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates asciicast with given stdout timing file' do
|
|
|
|
expect(created_asciicast.stdout_timing).to_not be(nil)
|
|
|
|
end
|
|
|
|
|
2015-02-26 13:14:32 +00:00
|
|
|
it 'creates asciicast with given command' do
|
|
|
|
expect(created_asciicast.command).to eq('/bin/bash')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates asciicast with given duration' do
|
|
|
|
expect(created_asciicast.duration).to eq(11.146430015564)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates asciicast with given shell' do
|
|
|
|
expect(created_asciicast.shell).to eq('/bin/zsh')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates asciicast with given terminal type' do
|
|
|
|
expect(created_asciicast.terminal_type).to eq('screen-256color')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates asciicast with given terminal width' do
|
|
|
|
expect(created_asciicast.terminal_columns).to eq(96)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates asciicast with given terminal height' do
|
|
|
|
expect(created_asciicast.terminal_lines).to eq(26)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates asciicast with given title' do
|
|
|
|
expect(created_asciicast.title).to eq('bashing :)')
|
|
|
|
end
|
|
|
|
|
2015-02-27 13:58:04 +00:00
|
|
|
it 'creates asciicast with nil uname' do
|
2015-02-26 13:14:32 +00:00
|
|
|
expect(created_asciicast.uname).to be(nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates asciicast with given user agent' do
|
|
|
|
expect(created_asciicast.user_agent).to eq('asciinema/0.9.8 CPython/2.7.4 Jola/Misio-Foo')
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a user with given token does not exist' do
|
|
|
|
let(:created_user) { User.last }
|
|
|
|
|
|
|
|
it 'creates new user with given username and token' do
|
|
|
|
expect(created_user.temporary_username).to eq('kill')
|
|
|
|
expect(created_user.api_tokens.first.token).to eq('f33e6188-f53c-11e2-abf4-84a6c827e88b')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates asciicast assigned to newly created user' do
|
|
|
|
expect(created_asciicast.user).to eq(created_user)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a user with given token exists' do
|
2015-04-03 16:48:37 +00:00
|
|
|
let(:user) { ApiToken.create_with_tmp_user!('f33e6188-f53c-11e2-abf4-84a6c827e88b', 'kill').user }
|
2015-02-26 13:14:32 +00:00
|
|
|
|
|
|
|
subject do
|
|
|
|
user
|
|
|
|
make_request
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates asciicast assigned to a user with given token' do
|
|
|
|
expect(created_asciicast.user).to eq(user)
|
|
|
|
end
|
|
|
|
end
|
2014-02-11 16:49:22 +00:00
|
|
|
|
|
|
|
it 'returns the URL to the uploaded asciicast' do
|
2015-02-26 13:14:32 +00:00
|
|
|
expect(response.body).to eq(asciicast_url(created_asciicast))
|
2014-02-11 16:49:22 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-02-26 13:14:32 +00:00
|
|
|
context 'v0.9.9 client' do
|
|
|
|
subject { make_request }
|
|
|
|
|
|
|
|
def make_request
|
|
|
|
post '/api/asciicasts',
|
|
|
|
{
|
|
|
|
asciicast: {
|
|
|
|
meta: fixture_file('0.9.9/meta.json', 'application/json'),
|
|
|
|
stdout: fixture_file('0.9.9/stdout', 'application/octet-stream'),
|
|
|
|
stdout_timing: fixture_file('0.9.9/stdout.time', 'application/octet-stream')
|
|
|
|
}
|
|
|
|
}, headers('kill', 'f33e6188-f53c-11e2-abf4-84a6c827e88b', 'asciinema/0.9.9 gc/go1.3 jola-amd64')
|
|
|
|
end
|
|
|
|
|
|
|
|
before { subject }
|
|
|
|
|
2015-02-27 13:58:04 +00:00
|
|
|
it 'creates asciicast version 0' do
|
|
|
|
expect(created_asciicast.version).to eq(0)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates asciicast with given stdout data file' do
|
|
|
|
expect(created_asciicast.stdout_data).to_not be(nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates asciicast with given stdout timing file' do
|
|
|
|
expect(created_asciicast.stdout_timing).to_not be(nil)
|
|
|
|
end
|
|
|
|
|
2015-02-26 13:14:32 +00:00
|
|
|
it 'creates asciicast with given command' do
|
|
|
|
expect(created_asciicast.command).to eq('/bin/bash')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates asciicast with given duration' do
|
|
|
|
expect(created_asciicast.duration).to eq(11.146430015564)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates asciicast with given shell' do
|
|
|
|
expect(created_asciicast.shell).to eq('/bin/zsh')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates asciicast with given terminal type' do
|
|
|
|
expect(created_asciicast.terminal_type).to eq('screen-256color')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates asciicast with given terminal width' do
|
|
|
|
expect(created_asciicast.terminal_columns).to eq(96)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates asciicast with given terminal height' do
|
|
|
|
expect(created_asciicast.terminal_lines).to eq(26)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates asciicast with given title' do
|
|
|
|
expect(created_asciicast.title).to eq('bashing :)')
|
|
|
|
end
|
|
|
|
|
2015-02-27 13:58:04 +00:00
|
|
|
it 'creates asciicast with nil uname' do
|
2015-02-26 13:14:32 +00:00
|
|
|
expect(created_asciicast.uname).to be(nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates asciicast with given user agent' do
|
|
|
|
expect(created_asciicast.user_agent).to eq('asciinema/0.9.9 gc/go1.3 jola-amd64')
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a user with given token does not exist' do
|
|
|
|
let(:created_user) { User.last }
|
|
|
|
|
|
|
|
it 'creates new user with given username and token' do
|
|
|
|
expect(created_user.temporary_username).to eq('kill')
|
|
|
|
expect(created_user.api_tokens.first.token).to eq('f33e6188-f53c-11e2-abf4-84a6c827e88b')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates asciicast assigned to newly created user' do
|
|
|
|
expect(created_asciicast.user).to eq(created_user)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a user with given token exists' do
|
2015-04-03 16:48:37 +00:00
|
|
|
let(:user) { ApiToken.create_with_tmp_user!('f33e6188-f53c-11e2-abf4-84a6c827e88b', 'kill').user }
|
2015-02-26 13:14:32 +00:00
|
|
|
|
|
|
|
subject do
|
|
|
|
user
|
|
|
|
make_request
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates asciicast assigned to a user with given token' do
|
|
|
|
expect(created_asciicast.user).to eq(user)
|
|
|
|
end
|
|
|
|
end
|
2014-02-11 16:49:22 +00:00
|
|
|
|
|
|
|
it 'returns the URL to the uploaded asciicast' do
|
2015-02-26 13:14:32 +00:00
|
|
|
expect(response.body).to eq(asciicast_url(created_asciicast))
|
2014-02-11 16:49:22 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-02-27 13:58:04 +00:00
|
|
|
context 'format 1' do
|
|
|
|
subject { make_request }
|
|
|
|
|
2015-04-04 17:48:01 +00:00
|
|
|
let(:username) { 'kill' }
|
|
|
|
let(:token) { 'f33e6188-f53c-11e2-abf4-84a6c827e88b' }
|
|
|
|
|
2015-03-23 16:40:11 +00:00
|
|
|
def make_request(asciicast_path = '1/asciicast.json')
|
2015-02-27 13:58:04 +00:00
|
|
|
post '/api/asciicasts',
|
2015-03-23 16:40:11 +00:00
|
|
|
{ asciicast: fixture_file(asciicast_path, 'application/json') },
|
2015-04-04 17:48:01 +00:00
|
|
|
headers(username, token, 'asciinema/1.0.0 gc/go1.3 jola-amd64')
|
2015-02-27 13:58:04 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
before { subject }
|
|
|
|
|
|
|
|
it 'creates asciicast version 1' do
|
|
|
|
expect(created_asciicast.version).to eq(1)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates asciicast with given file' do
|
|
|
|
expect(created_asciicast.file).to_not be(nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates asciicast with given command' do
|
|
|
|
expect(created_asciicast.command).to eq('/bin/bash')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates asciicast with given duration' do
|
|
|
|
expect(created_asciicast.duration).to eq(11.146430015564)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates asciicast with given shell' do
|
|
|
|
expect(created_asciicast.shell).to eq('/bin/zsh')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates asciicast with given terminal type' do
|
|
|
|
expect(created_asciicast.terminal_type).to eq('screen-256color')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates asciicast with given terminal width' do
|
|
|
|
expect(created_asciicast.terminal_columns).to eq(96)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates asciicast with given terminal height' do
|
|
|
|
expect(created_asciicast.terminal_lines).to eq(26)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates asciicast with given title' do
|
|
|
|
expect(created_asciicast.title).to eq('bashing :)')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates asciicast with nil uname' do
|
|
|
|
expect(created_asciicast.uname).to be(nil)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates asciicast with given user agent' do
|
|
|
|
expect(created_asciicast.user_agent).to eq('asciinema/1.0.0 gc/go1.3 jola-amd64')
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a user with given token does not exist' do
|
|
|
|
let(:created_user) { User.last }
|
|
|
|
|
|
|
|
it 'creates new user with given username and token' do
|
|
|
|
expect(created_user.temporary_username).to eq('kill')
|
|
|
|
expect(created_user.api_tokens.first.token).to eq('f33e6188-f53c-11e2-abf4-84a6c827e88b')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates asciicast assigned to newly created user' do
|
|
|
|
expect(created_asciicast.user).to eq(created_user)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a user with given token exists' do
|
2015-04-03 16:48:37 +00:00
|
|
|
let(:user) { ApiToken.create_with_tmp_user!('f33e6188-f53c-11e2-abf4-84a6c827e88b', 'kill').user }
|
2015-02-27 13:58:04 +00:00
|
|
|
|
|
|
|
subject do
|
|
|
|
user
|
|
|
|
make_request
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'creates asciicast assigned to a user with given token' do
|
|
|
|
expect(created_asciicast.user).to eq(user)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the URL to the uploaded asciicast' do
|
|
|
|
expect(response.body).to eq(asciicast_url(created_asciicast))
|
|
|
|
end
|
2015-03-23 16:40:11 +00:00
|
|
|
|
|
|
|
context 'when json is missing data / has invalid data' do
|
|
|
|
subject { make_request('1/invalid.json') }
|
|
|
|
|
|
|
|
it 'returns 422 status' do
|
|
|
|
expect(response.status).to eq(422)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when non-json file given' do
|
|
|
|
subject { make_request('stdout.decompressed') }
|
|
|
|
|
|
|
|
it 'returns 400 status' do
|
|
|
|
expect(response.status).to eq(400)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-04-04 17:48:01 +00:00
|
|
|
context 'when auth is not present' do
|
|
|
|
let(:username) { nil }
|
|
|
|
let(:token) { nil }
|
|
|
|
|
|
|
|
it 'returns 401 status' do
|
|
|
|
expect(response.status).to eq(401)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-04-04 17:59:58 +00:00
|
|
|
context 'when given token has been revoked' do
|
|
|
|
let(:token) { create(:revoked_api_token).token }
|
|
|
|
|
|
|
|
it 'returns 401 status' do
|
|
|
|
expect(response.status).to eq(401)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-04-04 17:57:34 +00:00
|
|
|
context 'when given token is invalid' do
|
|
|
|
let(:token) { 'foo' }
|
|
|
|
|
|
|
|
it 'returns 401 status' do
|
|
|
|
expect(response.status).to eq(401)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-02-27 13:58:04 +00:00
|
|
|
end
|
|
|
|
|
2013-08-08 13:41:57 +00:00
|
|
|
end
|