Commit 4e5164338a77894c68816bc1e7eec018aea8301c
1 parent
2c5e4955
Exists in
master
and in
4 other branches
specs for api/internal
Showing
2 changed files
with
109 additions
and
0 deletions
Show diff stats
lib/api/internal.rb
... | ... | @@ -5,6 +5,12 @@ module Gitlab |
5 | 5 | # |
6 | 6 | # Check if ssh key has access to project code |
7 | 7 | # |
8 | + # Params: | |
9 | + # key_id - SSH Key id | |
10 | + # project - project path with namespace | |
11 | + # action - git action (git-upload-pack or git-receive-pack) | |
12 | + # ref - branch name | |
13 | + # | |
8 | 14 | get "/allowed" do |
9 | 15 | key = Key.find(params[:key_id]) |
10 | 16 | project = Project.find_with_namespace(params[:project]) | ... | ... |
... | ... | @@ -0,0 +1,103 @@ |
1 | +require 'spec_helper' | |
2 | + | |
3 | +describe Gitlab::API do | |
4 | + include ApiHelpers | |
5 | + | |
6 | + let(:user) { create(:user) } | |
7 | + let(:key) { create(:key, user: user) } | |
8 | + let(:project) { create(:project) } | |
9 | + | |
10 | + describe "GET /internal/check", no_db: true do | |
11 | + it do | |
12 | + get api("/internal/check") | |
13 | + | |
14 | + response.status.should == 200 | |
15 | + json_response['api_version'].should == Gitlab::API.version | |
16 | + end | |
17 | + end | |
18 | + | |
19 | + describe "GET /internal/discover" do | |
20 | + it do | |
21 | + get(api("/internal/discover"), key_id: key.id) | |
22 | + | |
23 | + response.status.should == 200 | |
24 | + | |
25 | + json_response['email'].should == user.email | |
26 | + end | |
27 | + end | |
28 | + | |
29 | + describe "GET /internal/allowed" do | |
30 | + context "access granted" do | |
31 | + before do | |
32 | + project.team << [user, :developer] | |
33 | + end | |
34 | + | |
35 | + context "git pull" do | |
36 | + it do | |
37 | + get( | |
38 | + api("/internal/allowed"), | |
39 | + ref: 'master', | |
40 | + key_id: key.id, | |
41 | + project: project.path_with_namespace, | |
42 | + action: 'git-upload-pack' | |
43 | + ) | |
44 | + | |
45 | + response.status.should == 200 | |
46 | + response.body.should == 'true' | |
47 | + end | |
48 | + end | |
49 | + | |
50 | + context "git push" do | |
51 | + it do | |
52 | + get( | |
53 | + api("/internal/allowed"), | |
54 | + ref: 'master', | |
55 | + key_id: key.id, | |
56 | + project: project.path_with_namespace, | |
57 | + action: 'git-receive-pack' | |
58 | + ) | |
59 | + | |
60 | + response.status.should == 200 | |
61 | + response.body.should == 'true' | |
62 | + end | |
63 | + end | |
64 | + end | |
65 | + | |
66 | + context "access denied" do | |
67 | + before do | |
68 | + project.team << [user, :guest] | |
69 | + end | |
70 | + | |
71 | + context "git pull" do | |
72 | + it do | |
73 | + get( | |
74 | + api("/internal/allowed"), | |
75 | + ref: 'master', | |
76 | + key_id: key.id, | |
77 | + project: project.path_with_namespace, | |
78 | + action: 'git-upload-pack' | |
79 | + ) | |
80 | + | |
81 | + response.status.should == 200 | |
82 | + response.body.should == 'false' | |
83 | + end | |
84 | + end | |
85 | + | |
86 | + context "git push" do | |
87 | + it do | |
88 | + get( | |
89 | + api("/internal/allowed"), | |
90 | + ref: 'master', | |
91 | + key_id: key.id, | |
92 | + project: project.path_with_namespace, | |
93 | + action: 'git-receive-pack' | |
94 | + ) | |
95 | + | |
96 | + response.status.should == 200 | |
97 | + response.body.should == 'false' | |
98 | + end | |
99 | + end | |
100 | + end | |
101 | + | |
102 | + end | |
103 | +end | ... | ... |