ssh_access_controller_spec.rb revision f198c0ec200763fe1b0db998cd9418f412be8361
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenrequire 'spec_helper'
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainendescribe SSHAccessController do
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen let(:repository) { create :repository }
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen let(:user) { create :user }
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen context 'should return valid response when encountering error' do
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen before do
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen get :index, repository_id: repository.to_param, key_id: nil, permission: 'write'
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen end
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen it { should respond_with :success }
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen it 'contains error-reason' do
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen expect(response.body).to include('reason')
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen end
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen end
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen context 'should return false-permission on valid request without access permission' do
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen let!(:key) { create :key, user: user }
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen before do
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen get :index, repository_id: repository.to_param, key_id: key.id.to_s, permission: 'write'
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen end
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen it { should respond_with :success }
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen it 'contains correct permission' do
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen expect(response.body).to include('"allowed":false')
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen end
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen it 'does not include error-reason' do
f16c114c20bbd7d292d93415d1e56c8dd6abd3e7Timo Sirainen expect(response.body).not_to include('reason')
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen end
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen end
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainen
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen context 'should return true-permission on valid request with access permission' do
98c1cf256927e254f0c092acd2ddcd7ea50bd009Timo Sirainen let!(:key) { create :key, user: user }
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen before do
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen get :index, repository_id: repository.to_param, key_id: key.id.to_s, permission: 'read'
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen end
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen
98c1cf256927e254f0c092acd2ddcd7ea50bd009Timo Sirainen it { should respond_with :success }
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen it 'contains correct permission' do
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainen expect(response.body).to include('"allowed":true')
98c1cf256927e254f0c092acd2ddcd7ea50bd009Timo Sirainen end
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainen
9aa52288a4b53186d81b0ec9afa7d9e0a8ee8753Timo Sirainen it 'does not include error-reason' do
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen expect(response.body).not_to include('reason')
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen end
e06c0b65c16ccce69bbee009ead14d7d3d17a256Timo Sirainen
7a6b45405fb1544ac476e6eb1402a70cc1ddcdcfTimo Sirainen end
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainen
8fcff4c5b52f24d9c681805fdf06b486f1d0fcbeTimo Sirainen context 'should return false-permission on valid request with write to mirror' do
abe8230dd1dd37d7ccf0163100e934bb5e658c20Timo Sirainen let(:repository) { create :repository, source_address: 'http://some_source_address.example.com', source_type: 'git' }
abe8230dd1dd37d7ccf0163100e934bb5e658c20Timo Sirainen let!(:key) { create :key, user: user }
98c1cf256927e254f0c092acd2ddcd7ea50bd009Timo Sirainen before do
98c1cf256927e254f0c092acd2ddcd7ea50bd009Timo Sirainen get :index, repository_id: repository.to_param, key_id: key.id.to_s, permission: 'write'
98c1cf256927e254f0c092acd2ddcd7ea50bd009Timo Sirainen end
98c1cf256927e254f0c092acd2ddcd7ea50bd009Timo Sirainen
98c1cf256927e254f0c092acd2ddcd7ea50bd009Timo Sirainen it { should respond_with :success }
98c1cf256927e254f0c092acd2ddcd7ea50bd009Timo Sirainen it 'contains correct permission' do
98c1cf256927e254f0c092acd2ddcd7ea50bd009Timo Sirainen expect(response.body).to include('"allowed":false')
98c1cf256927e254f0c092acd2ddcd7ea50bd009Timo Sirainen end
02b79f9c2636da1829eee5b92753602bba8b67edTimo Sirainen
02b79f9c2636da1829eee5b92753602bba8b67edTimo Sirainen it 'contains error message which is suitable for the user' do
02b79f9c2636da1829eee5b92753602bba8b67edTimo Sirainen expect(response.body).to include('"provide_to_user":true')
02b79f9c2636da1829eee5b92753602bba8b67edTimo Sirainen end
02b79f9c2636da1829eee5b92753602bba8b67edTimo Sirainen
02b79f9c2636da1829eee5b92753602bba8b67edTimo Sirainen end
02b79f9c2636da1829eee5b92753602bba8b67edTimo Sirainen
02b79f9c2636da1829eee5b92753602bba8b67edTimo Sirainenend
02b79f9c2636da1829eee5b92753602bba8b67edTimo Sirainen