Skip to content
Permalink
Browse files Browse the repository at this point in the history
[api] support binary package upload for the admin
  • Loading branch information
adrianschroeter committed Dec 12, 2011
1 parent 6a1c1a1 commit 5281e4b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 17 deletions.
31 changes: 14 additions & 17 deletions src/api/app/controllers/build_controller.rb
@@ -1,7 +1,7 @@
class BuildController < ApplicationController

def index
valid_http_methods :get, :post, :put
valid_http_methods :get, :post

# for permission check
if params[:package] and not ["_repository", "_jobhistory"].include?(params[:package])
Expand All @@ -10,7 +10,19 @@ def index
prj = DbProject.get_by_name params[:project]
end

pass_to_backend
if request.get?
pass_to_backend
return
end

if @http_user.is_admin?
# check for a local package instance
DbPackage.get_by_project_and_name( params[:project], params[:package], follow_project_links=false )
pass_to_backend
else
render_error :status => 403, :errorcode => "execute_cmd_no_permission",
:message => "Upload of binaries is only permitted for administrators"
end
end

def project_index
Expand Down Expand Up @@ -128,21 +140,6 @@ def builddepinfo
pass_to_backend
end

# /build/:prj/:repo/:arch/:pkg
def package_index
valid_http_methods :get
required_parameters :project, :repository, :arch, :package

# read access permission check
if params[:package] == "_repository"
prj = DbProject.get_by_name params[:project], use_source=false
else
pkg = DbPackage.get_by_project_and_name params[:project], params[:package], use_source=false
end

pass_to_backend
end

# /build/:project/:repository/:arch/:package/:filename
def file
valid_http_methods :get, :delete
Expand Down
26 changes: 26 additions & 0 deletions src/api/test/functional/build_controller_test.rb
Expand Up @@ -39,6 +39,32 @@ def test_index
assert_response 404
end

def test_upload_binaries
ActionController::IntegrationTest::reset_auth
post "/build/home:Iggy/10.2/i586/TestPack", nil
assert_response 401

prepare_request_with_user "adrian", "so_alone"
post "/build/home:Iggy/10.2/i586/TestPack", nil
assert_response 403

prepare_request_with_user "king", "sunflower"
post "/build/home:Iggy/10.2/i586/TestPack", nil
assert_response 400 # actually a success, it reached the backend

This comment has been minimized.

Copy link
@saschpe

saschpe Dec 13, 2011

Member

Huh?

This comment has been minimized.

Copy link
@lnussel

lnussel via email Dec 13, 2011

Member
assert_tag :tag => "status", :attributes => { :code => "400", :origin => "backend" }

# check not supported methods
post "/build/home:Iggy/10.2/i586/_repository", nil
assert_response 404
assert_tag :tag => "status", :attributes => { :code => "unknown_package" }
put "/build/home:Iggy/10.2/i586/TestPack", nil
assert_response 400
assert_tag :tag => "status", :attributes => { :code => "invalid_http_method" }
delete "/build/home:Iggy/10.2/i586/TestPack"
assert_response 400
assert_tag :tag => "status", :attributes => { :code => "invalid_http_method" }
end

def test_dispatchprios
ActionController::IntegrationTest::reset_auth
get "/build/_dispatchprios"
Expand Down

0 comments on commit 5281e4b

Please sign in to comment.