Skip to content

Commit 6cfccc5

Browse files
authored
Ak vcs scopes (#1186)
1 parent 1d3a6c1 commit 6cfccc5

File tree

15 files changed

+151
-496
lines changed

15 files changed

+151
-496
lines changed

lib/travis/api/serialize/v2/http/user.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def user_data
5555
end
5656

5757
def check_scopes
58-
return Github::Oauth.correct_scopes?(user) if user.github?
58+
# return Github::Oauth.correct_scopes?(user) if user.github?
5959

6060
::Travis::RemoteVCS::User.new.check_scopes(user_id: user.id)
6161
rescue ::Travis::RemoteVCS::ResponseError

lib/travis/api/v3/services/repository/activate.rb

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,19 @@ def run!
99
return repo_migrated if migrated?(repository)
1010

1111
admin = access_control.admin_for(repository)
12-
if Travis::Features.user_active?(:use_vcs, admin) || !admin.github?
13-
remote_vcs_repository.set_hook(
14-
repository_id: repository.id,
15-
user_id: admin.id
16-
)
17-
else
18-
github(admin).set_hook(repository, true)
19-
end
12+
remote_vcs_repository.set_hook(
13+
repository_id: repository.id,
14+
user_id: admin.id
15+
)
16+
2017
repository.update_attributes(active: true)
2118

2219
if repository.private? || access_control.enterprise?
23-
if Travis::Features.deactivate_owner(:use_vcs, admin) || !admin.github?
24-
remote_vcs_repository.upload_key(
25-
repository_id: repository.id,
26-
user_id: admin.id,
27-
read_only: !Travis::Features.owner_active?(:read_write_github_keys, repository.owner)
28-
)
29-
else
30-
github(admin).upload_key(repository)
31-
end
20+
remote_vcs_repository.upload_key(
21+
repository_id: repository.id,
22+
user_id: admin.id,
23+
read_only: !Travis::Features.owner_active?(:read_write_github_keys, repository.owner)
24+
)
3225
end
3326

3427
query.sync(access_control.user || access_control.admin_for(repository))

lib/travis/api/v3/services/repository/deactivate.rb

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,12 @@ def run!(activate = false)
77

88
admin = access_control.admin_for(repository)
99

10-
if Travis::Features.user_active?(:use_vcs, admin) || !admin.github?
11-
remote_vcs_repository.set_hook(
12-
repository_id: repository.id,
13-
user_id: admin.id,
14-
activate: activate
15-
)
16-
else
17-
github(admin).set_hook(repository, activate)
18-
end
10+
remote_vcs_repository.set_hook(
11+
repository_id: repository.id,
12+
user_id: admin.id,
13+
activate: activate
14+
)
1915
repository.update_attributes(active: activate)
20-
2116
result repository
2217
end
2318

lib/travis/github/services/set_hook.rb

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,11 @@ class SetHook < Travis::Services::Base
1111
register :github_set_hook
1212

1313
def run
14-
if Travis::Features.user_active?(:use_vcs, current_user) || !current_user.github?
15-
remote_vcs_repository.set_hook(
16-
repository_id: repo.id,
17-
user_id: current_user.id,
18-
activate: active?
19-
)
20-
else
21-
v3_github.set_hook(repo, active?)
22-
end
14+
remote_vcs_repository.set_hook(
15+
repository_id: repo.id,
16+
user_id: current_user.id,
17+
activate: active?
18+
)
2319
end
2420

2521
private

lib/travis/github/services/set_key.rb

Lines changed: 14 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -25,54 +25,30 @@ def has_key?
2525
private
2626

2727
def keys
28-
if Travis::Features.user_active?(:use_vcs, current_user) || !current_user.github?
29-
@keys ||= remote_vcs_repository.keys(
30-
repository_id: repo.id,
31-
user_id: current_user.id
32-
)
33-
else
34-
@keys ||= authenticated do
35-
GH[keys_path]
36-
end
37-
end
28+
@keys ||= remote_vcs_repository.keys(
29+
repository_id: repo.id,
30+
user_id: current_user.id
31+
)
3832
end
3933

4034
def key
4135
keys.detect { |e| e['key'] == repo.key.encoded_public_key }
4236
end
4337

4438
def set_key
45-
read_only = !Travis::Features.owner_active?(:read_write_github_keys, repo.owner)
46-
if Travis::Features.user_active?(:use_vcs, current_user) || !current_user.github?
47-
remote_vcs_repository.upload_key(
48-
repository_id: repo.id,
49-
user_id: current_user.id,
50-
read_only: read_only
51-
)
52-
else
53-
authenticated do
54-
GH.post keys_path, {
55-
title: Travis.config.host.to_s,
56-
key: repo.key.encoded_public_key,
57-
read_only: read_only
58-
}
59-
end
60-
end
39+
remote_vcs_repository.upload_key(
40+
repository_id: repo.id,
41+
user_id: current_user.id,
42+
read_only: !Travis::Features.owner_active?(:read_write_github_keys, repo.owner)
43+
)
6144
end
6245

6346
def delete_key
64-
if Travis::Features.user_active?(:use_vcs, current_user) || !current_user.github?
65-
remote_vcs_repository.delete_key(
66-
repository_id: repo.id,
67-
user_id: current_user.id,
68-
id: key['id']
69-
)
70-
else
71-
authenticated do
72-
GH.delete "#{keys_path}/#{key['id']}" #key['_links']['self']['href']
73-
@keys = []
74-
end
75-
end
47+
remote_vcs_repository.delete_key(
48+
repository_id: repo.id,
49+
user_id: current_user.id,
50+
id: key['id']
51+
)
7652
end
7753

7854
def keys_path

spec/auth/v2.1/users_spec.rb

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,145 +1,134 @@
11
describe 'v2.1 users', auth_helpers: true, api_version: :'v2.1', set_app: true do
22
let(:user) { User.first }
33
let(:repo) { Repository.by_slug('svenfuchs/minimal').first }
4-
4+
let!(:request) do
5+
WebMock.stub_request(:post, 'http://vcsfake.travis-ci.com/users/1/check_scopes')
6+
.to_return(
7+
status: 200,
8+
body: nil,
9+
)
10+
end
11+
before do
12+
Travis.config.vcs.url = 'http://vcsfake.travis-ci.com'
13+
Travis.config.vcs.token = 'vcs-token'
14+
end
515
# TODO put /users/
616
# TODO put /users/:id ?
717
# TODO post /users/sync
8-
918
describe 'in public, with a private repo', mode: :public, repo: :private do
1019
describe 'GET /users' do
1120
it(:authenticated) { should auth status: 200, type: :json, empty: false }
1221
it(:invalid_token) { should auth status: 403 }
1322
it(:unauthenticated) { should auth status: 401 }
1423
end
15-
1624
describe 'GET /users/permissions' do
1725
it(:with_permission) { should auth status: 200, type: :json, empty: false }
1826
it(:without_permission) { should auth status: 200, type: :json, empty: true }
1927
it(:invalid_token) { should auth status: 403 }
2028
it(:unauthenticated) { should auth status: 401 }
2129
end
22-
2330
describe 'GET /users/%{user.id}' do
2431
it(:authenticated) { should auth status: 200, type: :json, empty: false }
2532
it(:invalid_token) { should auth status: 403 }
2633
it(:unauthenticated) { should auth status: 401 }
2734
end
28-
2935
describe 'GET /users/0' do
3036
it(:authenticated) { should auth status: 404 }
3137
it(:invalid_token) { should auth status: 403 }
3238
it(:unauthenticated) { should auth status: 401 }
3339
end
3440
end
35-
3641
describe 'in public mode, with a public repo', mode: :public, repo: :public do
3742
describe 'GET /users' do
3843
it(:authenticated) { should auth status: 200, type: :json, empty: false }
3944
it(:invalid_token) { should auth status: 403 }
4045
it(:unauthenticated) { should auth status: 401 }
4146
end
42-
4347
describe 'GET /users/permissions' do
4448
it(:with_permission) { should auth status: 200, type: :json, empty: false }
4549
it(:without_permission) { should auth status: 200, type: :json, empty: true }
4650
it(:invalid_token) { should auth status: 403 }
4751
it(:unauthenticated) { should auth status: 401 }
4852
end
49-
5053
describe 'GET /users/%{user.id}' do
5154
it(:authenticated) { should auth status: 200, type: :json, empty: false }
5255
it(:invalid_token) { should auth status: 403 }
5356
it(:unauthenticated) { should auth status: 401 }
5457
end
55-
5658
describe 'GET /users/0' do
5759
it(:authenticated) { should auth status: 404 }
5860
it(:invalid_token) { should auth status: 403 }
5961
it(:unauthenticated) { should auth status: 401 }
6062
end
6163
end
62-
6364
describe 'in private, with a public repo', mode: :private, repo: :public do
6465
describe 'GET /users' do
6566
it(:authenticated) { should auth status: 200, type: :json, empty: false }
6667
it(:invalid_token) { should auth status: 403 }
6768
it(:unauthenticated) { should auth status: 401 }
6869
end
69-
7070
describe 'GET /users/permissions' do
7171
it(:with_permission) { should auth status: 200, type: :json, empty: false }
7272
it(:without_permission) { should auth status: 200, type: :json, empty: true }
7373
it(:invalid_token) { should auth status: 403 }
7474
it(:unauthenticated) { should auth status: 401 }
7575
end
76-
7776
describe 'GET /users/%{user.id}' do
7877
it(:authenticated) { should auth status: 200, type: :json, empty: false }
7978
it(:invalid_token) { should auth status: 403 }
8079
it(:unauthenticated) { should auth status: 401 }
8180
end
82-
8381
describe 'GET /users/0' do
8482
it(:authenticated) { should auth status: 404 }
8583
it(:invalid_token) { should auth status: 403 }
8684
it(:unauthenticated) { should auth status: 401 }
8785
end
8886
end
89-
9087
# +----------------------------------------------------+
9188
# | |
9289
# | !!! THE ORIGINAL BEHAVIOUR ... DON'T TOUCH !!! |
9390
# | |
9491
# +----------------------------------------------------+
95-
9692
describe 'in private, with a private repo', mode: :private, repo: :private do
9793
describe 'GET /users' do
9894
it(:authenticated) { should auth status: 200, type: :json, empty: false }
9995
it(:invalid_token) { should auth status: 403 }
10096
it(:unauthenticated) { should auth status: 401 }
10197
end
102-
10398
describe 'GET /users/permissions' do
10499
it(:with_permission) { should auth status: 200, type: :json, empty: false }
105100
it(:without_permission) { should auth status: 200, type: :json, empty: true }
106101
it(:invalid_token) { should auth status: 403 }
107102
it(:unauthenticated) { should auth status: 401 }
108103
end
109-
110104
describe 'GET /users/%{user.id}' do
111105
it(:authenticated) { should auth status: 200, type: :json, empty: false }
112106
it(:invalid_token) { should auth status: 403 }
113107
it(:unauthenticated) { should auth status: 401 }
114108
end
115-
116109
describe 'GET /users/0' do
117110
it(:authenticated) { should auth status: 404 }
118111
it(:invalid_token) { should auth status: 403 }
119112
it(:unauthenticated) { should auth status: 401 }
120113
end
121114
end
122-
123115
describe 'in org mode, with a public repo', mode: :org, repo: :public do
124116
describe 'GET /users' do
125117
it(:authenticated) { should auth status: 200, type: :json, empty: false }
126118
it(:invalid_token) { should auth status: 403 }
127119
it(:unauthenticated) { should auth status: 401 }
128120
end
129-
130121
describe 'GET /users/permissions' do
131122
it(:with_permission) { should auth status: 200, type: :json, empty: false }
132123
it(:without_permission) { should auth status: 200, type: :json, empty: true }
133124
it(:invalid_token) { should auth status: 403 }
134125
it(:unauthenticated) { should auth status: 401 }
135126
end
136-
137127
describe 'GET /users/%{user.id}' do
138128
it(:authenticated) { should auth status: 200, type: :json, empty: false }
139129
it(:invalid_token) { should auth status: 403 }
140130
it(:unauthenticated) { should auth status: 401 }
141131
end
142-
143132
describe 'GET /users/0' do
144133
it(:authenticated) { should auth status: 404 }
145134
it(:invalid_token) { should auth status: 403 }

spec/auth/v2/users_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
let(:user) { User.first }
33
let(:repo) { Repository.by_slug('svenfuchs/minimal').first }
44

5+
before { allow_any_instance_of(Travis::RemoteVCS::User).to receive(:check_scopes) }
56
# TODO put /users/
67
# TODO put /users/:id ?
78
# TODO post /users/sync

spec/integration/v2/hooks_spec.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@
3030

3131
before(:each) do
3232
Travis.config.service_hook_url = 'notify.travis-ci.org'
33-
stub_request(:get, "https://api.github.com/repositories/#{repo.github_id}/hooks?per_page=100").to_return(status: 200, body: '[]')
34-
stub_request(:post, "https://api.github.com/repositories/#{repo.github_id}/hooks")
33+
allow_any_instance_of(Travis::RemoteVCS::Repository).to receive(:set_hook)
3534
end
3635

3736
it 'sets the hook' do

spec/integration/v2/users_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
before do
1212
user.permissions.create!(repository: repo1)
1313
user.permissions.create!(repository: repo2)
14+
allow_any_instance_of(Travis::RemoteVCS::User).to receive(:check_scopes)
1415
end
1516

1617
it 'fetches a list of channels for a user' do

0 commit comments

Comments
 (0)