#192: added new specs, updated Platform API controller

This commit is contained in:
Vokhmin Alexey V 2013-07-03 19:02:50 +04:00
parent 38a4729cbc
commit 828ddc540f
2 changed files with 26 additions and 1 deletions

View File

@ -7,7 +7,8 @@ class Api::V1::PlatformsController < Api::V1::BaseController
load_and_authorize_resource :except => :allowed load_and_authorize_resource :except => :allowed
def allowed def allowed
platform_name = (params[:path] || '').match(/^\/#{Platform::NAME_PATTERN}\//) platform_name = (params[:path] || '').gsub(/^[\/]+/, '')
.match(/^(#{Platform::NAME_PATTERN}\/|#{Platform::NAME_PATTERN}$)/)
render(:inline => 'true') && return unless platform_name render(:inline => 'true') && return unless platform_name
platform_name = platform_name[0].gsub(/\//, '') platform_name = platform_name[0].gsub(/\//, '')

View File

@ -272,6 +272,30 @@ describe Api::V1::PlatformsController do
response.status.should == 403 response.status.should == 403
end end
it 'ensures that status 403 if no token and a lot of "/"' do
get :allowed, :path => "///#{@platform.name}///repository/SRPMS/base/release/repodata/"
response.status.should == 403
end
it 'ensures that status 200 if token correct and a lot of "/"' do
token = FactoryGirl.create(:platform_token, :subject => @platform)
http_login token.authentication_token, ''
get :allowed, :path => "///#{@platform.name}///repository/SRPMS/base/release/repodata/"
response.status.should == 200
end
it 'ensures that status 403 on access to root of platform if no token' do
get :allowed, :path => "///#{@platform.name}"
response.status.should == 403
end
it 'ensures that status 200 on access to root of platform if token correct' do
token = FactoryGirl.create(:platform_token, :subject => @platform)
http_login token.authentication_token, ''
get :allowed, :path => "///#{@platform.name}"
response.status.should == 200
end
it 'ensures that status 403 if wrong token' do it 'ensures that status 403 if wrong token' do
http_login 'KuKu', '' http_login 'KuKu', ''
get :allowed, :path => "/#{@platform.name}/repository/SRPMS/base/release/repodata/" get :allowed, :path => "/#{@platform.name}/repository/SRPMS/base/release/repodata/"