Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing installation secured #1107

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/travis/api/v3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def location(env)
JobUnfinished = ClientError .create('job still running, cannot remove log yet', status: 409)
LogAlreadyRemoved = ClientError .create('log has already been removed', status: 409)
LoginRequired = ClientError .create('login required', status: 403)
InstallationMissing = ClientError .create('installation required', status: 403)
MethodNotAllowed = ClientError .create('method not allowed', status: 405)
NotImplemented = ServerError .create('request not (yet) implemented', status: 501)
PrivateRepoFeature = ClientError .create('this feature is only available on private repositories and for Travis CI Enterprise customers', status: 403)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class Services::Repositories::ForCurrentUser < Service

def run!
raise LoginRequired unless access_control.logged_in?
raise InstallationMissing unless Travis.config.org? || access_control.user.vcs_type != 'GithubUser' || access_control.user.installation
result query.for_member(access_control.user)
end
end
Expand Down
1 change: 1 addition & 0 deletions lib/travis/api/v3/services/repositories/for_owner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class Services::Repositories::ForOwner < Service
paginate(default_limit: 100)

def run!
raise InstallationMissing unless Travis.config.org? || access_control.user.installation
unfiltered = query.for_owner(find(:owner), user: access_control.user)
result access_control.visible_repositories(unfiltered)
end
Expand Down
1 change: 1 addition & 0 deletions spec/v3/services/repositories/filter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
let(:headers) { { 'HTTP_AUTHORIZATION' => "token #{token}" } }

before { ActiveRecord::Base.connection.execute("truncate repositories cascade") }
before { Travis::API::V3::Models::Installation.create(owner_type: 'User', owner_id: user.id, github_id: 789) }

describe 'name_filter' do
let(:web_repo) { FactoryBot.create(:repository, name: 'travis-web') }
Expand Down
1 change: 1 addition & 0 deletions spec/v3/services/repositories/for_current_user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
let(:token) { Travis::Api::App::AccessToken.create(user: repo.owner, app_id: 1) }
let(:headers) {{ 'HTTP_AUTHORIZATION' => "token #{token}" }}
before { Travis::API::V3::Models::Permission.create(repository: repo, user: repo.owner, pull: true, push: true, admin: true) }
before { Travis::API::V3::Models::Installation.create(owner_type: 'User', owner_id: repo.owner.id, github_id: 789) }
before { repo.update_attribute(:private, true) }
after { repo.update_attribute(:private, false) }
before { Travis::Features.activate_owner(:allow_migration, repo.owner) }
Expand Down
1 change: 1 addition & 0 deletions spec/v3/services/repositories/for_owner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
let(:token_collaborator) { Travis::Api::App::AccessToken.create(user: Travis::API::V3::Models::User.find_by_login('johndoe'), app_id: 1) }
let(:headers_collaborator) {{ 'HTTP_AUTHORIZATION' => "token #{token_collaborator}" }}
before { Travis::API::V3::Models::Permission.create(repository: repo, user: repo.owner, pull: true) }
before { Travis::API::V3::Models::Installation.create(owner_type: 'User', owner_id: repo.owner.id, github_id: 789) }
before { repo.update_attribute(:private, true) }
before { repo.update_attribute(:current_build, build) }
after { repo.update_attribute(:private, false) }
Expand Down