#192: updated controller and specs of Platform API
This commit is contained in:
parent
48bcb1a870
commit
4d719f2d88
|
@ -8,7 +8,9 @@ class Api::V1::PlatformsController < Api::V1::BaseController
|
|||
|
||||
def allowed
|
||||
url = params[:url] || ''
|
||||
platform_name = url.gsub(/^http\:\/\/.+rosalinux\.ru\//, '').gsub(/\/.*/, '')
|
||||
downloads_url = APP_CONFIG['downloads_url'].gsub(/^http\:\/\//, '')
|
||||
platform_name = url.gsub(/^http\:\/\/.*#{downloads_url}[\/]+/, '')
|
||||
.gsub(/\/.*/, '')
|
||||
platform = Platform.find_by_name platform_name
|
||||
if platform && platform.hidden?
|
||||
token = url.gsub(/^http\:\/\//, '').match(/.*\:\@/)
|
||||
|
|
|
@ -255,36 +255,37 @@ describe Api::V1::PlatformsController do
|
|||
end
|
||||
|
||||
it 'ensures that status 403 if platform does not exist' do
|
||||
get :allowed, :url => 'http://abf-downloads.rosalinux.ru/rosa-server/repository/SRPMS/base/release/repodata/'
|
||||
get :allowed, :url => "#{APP_CONFIG['downloads_url']}/rosa-server/repository/SRPMS/base/release/repodata/"
|
||||
response.status.should == 403
|
||||
end
|
||||
|
||||
it 'ensures that status 200 if platform open' do
|
||||
get :allowed, :url => "http://abf-downloads.rosalinux.ru/#{@platform.name}/repository/SRPMS/base/release/repodata/"
|
||||
get :allowed, :url => "#{APP_CONFIG['downloads_url']}/#{@platform.name}/repository/SRPMS/base/release/repodata/"
|
||||
response.status.should == 200
|
||||
end
|
||||
|
||||
context 'for hidden platform' do
|
||||
let(:downloads_url) { APP_CONFIG['downloads_url'].gsub(/^http\:\/\//, '') }
|
||||
before { @platform.change_visibility }
|
||||
|
||||
it 'ensures that status 403 if no token' do
|
||||
get :allowed, :url => "http://abf-downloads.rosalinux.ru/#{@platform.name}/repository/SRPMS/base/release/repodata/"
|
||||
get :allowed, :url => "#{APP_CONFIG['downloads_url']}/#{@platform.name}/repository/SRPMS/base/release/repodata/"
|
||||
response.status.should == 403
|
||||
end
|
||||
|
||||
it 'ensures that status 403 if wrong token' do
|
||||
get :allowed, :url => "http://KuKu:@abf-downloads.rosalinux.ru/#{@platform.name}/repository/SRPMS/base/release/repodata/"
|
||||
get :allowed, :url => "http://KuKu:@#{downloads_url}/#{@platform.name}/repository/SRPMS/base/release/repodata/"
|
||||
response.status.should == 403
|
||||
end
|
||||
|
||||
it 'ensures that status 200 if token correct' do
|
||||
token = FactoryGirl.create(:platform_token, :subject => @platform)
|
||||
get :allowed, :url => "http://#{token.authentication_token}:@abf-downloads.rosalinux.ru/#{@platform.name}/repository/SRPMS/base/release/repodata/"
|
||||
get :allowed, :url => "http://#{token.authentication_token}:@#{downloads_url}/#{@platform.name}/repository/SRPMS/base/release/repodata/"
|
||||
response.status.should == 200
|
||||
end
|
||||
|
||||
it 'ensures that status 200 if user token correct and user has ability to read platform' do
|
||||
get :allowed, :url => "http://#{@platform.owner.authentication_token}:@abf-downloads.rosalinux.ru/#{@platform.name}/repository/SRPMS/base/release/repodata/"
|
||||
get :allowed, :url => "http://#{@platform.owner.authentication_token}:@#{downloads_url}/#{@platform.name}/repository/SRPMS/base/release/repodata/"
|
||||
response.status.should == 200
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue