diff --git a/app/controllers/api/v1/platforms_controller.rb b/app/controllers/api/v1/platforms_controller.rb index 7618a03d6..d548fdea3 100644 --- a/app/controllers/api/v1/platforms_controller.rb +++ b/app/controllers/api/v1/platforms_controller.rb @@ -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(/.*\:\@/) diff --git a/spec/controllers/api/v1/platforms_controller_spec.rb b/spec/controllers/api/v1/platforms_controller_spec.rb index 55ffe7c0e..e2a52a902 100644 --- a/spec/controllers/api/v1/platforms_controller_spec.rb +++ b/spec/controllers/api/v1/platforms_controller_spec.rb @@ -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