gitlab-grack 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +2 -3
- data/CHANGELOG +3 -0
- data/Gemfile.lock +1 -1
- data/Rakefile +4 -0
- data/lib/grack/git.rb +4 -1
- data/lib/grack/server.rb +10 -5
- data/lib/grack/version.rb +1 -1
- data/tests/main_test.rb +34 -34
- metadata +2 -4
- data/.gitmodules +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 25c3243797c8eb47ef7a3b23c51b158302e1a678
|
4
|
+
data.tar.gz: 7f61020402644b75ccd37b71b8685b2ffe2bb098
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 111327afddbdd3c21e878264390031f3a8eec351402c044759dcaefe2403a2d17324e4d2351535dd116e9fa30a6039621f8ac19782c82e2ba2a802394725f3a9
|
7
|
+
data.tar.gz: dc300d7e110cef0d994943c309a3ad92ba91ee6e43432a11d8ba0df55685e5087c401b0edd38d7de951a3e615bbf4650dd34fafe9775cfe408eb5091a8ecbcf7
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -5,10 +5,9 @@ branches:
|
|
5
5
|
only:
|
6
6
|
- 'master'
|
7
7
|
rvm:
|
8
|
-
- 1.9.3-p327
|
9
8
|
- 2.0.0
|
10
9
|
before_script:
|
11
10
|
- "bundle install"
|
12
|
-
- "git
|
13
|
-
- "git
|
11
|
+
- "git clone --bare git://github.com/schacon/simplegit.git tests/example.git"
|
12
|
+
- "cd tests/example.git && git repack && cd ../.."
|
14
13
|
script: "bundle exec rake"
|
data/CHANGELOG
CHANGED
data/Gemfile.lock
CHANGED
data/Rakefile
CHANGED
@@ -5,9 +5,13 @@ task :default => :test
|
|
5
5
|
|
6
6
|
desc "Run the tests."
|
7
7
|
task :test do
|
8
|
+
system "git clone --bare git://github.com/schacon/simplegit.git tests/example.git"
|
9
|
+
# We could put this in a chdir block but we should keep it consistent with Travis
|
10
|
+
system "cd tests/example.git && git repack && cd ../.."
|
8
11
|
Dir.glob("tests/*_test.rb").each do |f|
|
9
12
|
system "ruby #{f}"
|
10
13
|
end
|
14
|
+
system "rm -rf tests/example.git"
|
11
15
|
end
|
12
16
|
|
13
17
|
desc "Run test coverage."
|
data/lib/grack/git.rb
CHANGED
@@ -16,7 +16,10 @@ module Grack
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def capture(cmd)
|
19
|
-
IO.popen(
|
19
|
+
# _Not_ the same as `IO.popen(...).read`
|
20
|
+
# By using a block we tell IO.popen to close (wait for) the child process
|
21
|
+
# after we are done reading its output.
|
22
|
+
IO.popen(popen_env, cmd, popen_options) { |p| p.read }
|
20
23
|
end
|
21
24
|
|
22
25
|
def execute(cmd)
|
data/lib/grack/server.rb
CHANGED
@@ -82,7 +82,8 @@ module Grack
|
|
82
82
|
pipe.write(input)
|
83
83
|
pipe.close_write
|
84
84
|
|
85
|
-
while
|
85
|
+
while !pipe.eof?
|
86
|
+
block = pipe.read(8192) # 8KB at a time
|
86
87
|
@res.write encode_chunk(block) # stream it to the client
|
87
88
|
end
|
88
89
|
|
@@ -102,13 +103,14 @@ module Grack
|
|
102
103
|
|
103
104
|
def get_info_refs
|
104
105
|
service_name = get_service_type
|
105
|
-
return dumb_info_refs unless
|
106
|
+
return dumb_info_refs unless smart_http?(service_name)
|
107
|
+
return render_no_access unless has_access?(service_name)
|
106
108
|
|
107
109
|
refs = git.execute([service_name, '--stateless-rpc', '--advertise-refs', git.repo])
|
108
110
|
|
109
111
|
@res = Rack::Response.new
|
110
112
|
@res.status = 200
|
111
|
-
@res["Content-Type"] = "application/x-git
|
113
|
+
@res["Content-Type"] = "application/x-git-#{service_name}-advertisement"
|
112
114
|
hdr_nocache
|
113
115
|
|
114
116
|
@res.write(pkt_write("# service=git-#{service_name}\n"))
|
@@ -226,10 +228,13 @@ module Grack
|
|
226
228
|
nil
|
227
229
|
end
|
228
230
|
|
231
|
+
def smart_http?(rpc = @rpc)
|
232
|
+
@req.content_type == "application/x-git-#{rpc}-request"
|
233
|
+
end
|
234
|
+
|
229
235
|
def has_access?(rpc, check_content_type = false)
|
230
236
|
if check_content_type
|
231
|
-
|
232
|
-
return false unless @req.content_type == conten_type
|
237
|
+
return false unless smart_http?(rpc)
|
233
238
|
end
|
234
239
|
|
235
240
|
return false unless ['upload-pack', 'receive-pack'].include?(rpc)
|
data/lib/grack/version.rb
CHANGED
data/tests/main_test.rb
CHANGED
@@ -25,7 +25,7 @@ class GitHttpTest < Test::Unit::TestCase
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def test_upload_pack_advertisement
|
28
|
-
get "/example/info/refs?service=git-upload-pack"
|
28
|
+
get "/example.git/info/refs?service=git-upload-pack", {}, {"CONTENT_TYPE" => "application/x-git-upload-pack-request"}
|
29
29
|
assert_equal 200, r.status
|
30
30
|
assert_equal "application/x-git-upload-pack-advertisement", r.headers["Content-Type"]
|
31
31
|
assert_equal "001e# service=git-upload-pack", r.body.split("\n").first
|
@@ -33,22 +33,22 @@ class GitHttpTest < Test::Unit::TestCase
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def test_no_access_wrong_content_type_up
|
36
|
-
post "/example/git-upload-pack"
|
36
|
+
post "/example.git/git-upload-pack"
|
37
37
|
assert_equal 403, r.status
|
38
38
|
end
|
39
39
|
|
40
40
|
def test_no_access_wrong_content_type_rp
|
41
|
-
post "/example/git-receive-pack"
|
41
|
+
post "/example.git/git-receive-pack"
|
42
42
|
assert_equal 403, r.status
|
43
43
|
end
|
44
44
|
|
45
45
|
def test_no_access_wrong_method_rcp
|
46
|
-
get "/example/git-upload-pack"
|
46
|
+
get "/example.git/git-upload-pack"
|
47
47
|
assert_equal 400, r.status
|
48
48
|
end
|
49
49
|
|
50
50
|
def test_no_access_wrong_command_rcp
|
51
|
-
post "/example/git-upload-packfile"
|
51
|
+
post "/example.git/git-upload-packfile"
|
52
52
|
assert_equal 404, r.status
|
53
53
|
end
|
54
54
|
|
@@ -61,13 +61,13 @@ class GitHttpTest < Test::Unit::TestCase
|
|
61
61
|
def test_upload_pack_rpc
|
62
62
|
Grack::Git.any_instance.stubs(:valid_repo?).returns(true)
|
63
63
|
IO.stubs(:popen).returns(MockProcess.new)
|
64
|
-
post "/example/git-upload-pack", {}, {"CONTENT_TYPE" => "application/x-git-upload-pack-request"}
|
64
|
+
post "/example.git/git-upload-pack", {}, {"CONTENT_TYPE" => "application/x-git-upload-pack-request"}
|
65
65
|
assert_equal 200, r.status
|
66
66
|
assert_equal "application/x-git-upload-pack-result", r.headers["Content-Type"]
|
67
67
|
end
|
68
68
|
|
69
69
|
def test_receive_pack_advertisement
|
70
|
-
get "/example/info/refs?service=git-receive-pack"
|
70
|
+
get "/example.git/info/refs?service=git-receive-pack", {}, {"CONTENT_TYPE" => "application/x-git-receive-pack-request"}
|
71
71
|
assert_equal 200, r.status
|
72
72
|
assert_equal "application/x-git-receive-pack-advertisement", r.headers["Content-Type"]
|
73
73
|
assert_equal "001f# service=git-receive-pack", r.body.split("\n").first
|
@@ -79,25 +79,25 @@ class GitHttpTest < Test::Unit::TestCase
|
|
79
79
|
def test_recieve_pack_rpc
|
80
80
|
Grack::Git.any_instance.stubs(:valid_repo?).returns(true)
|
81
81
|
IO.stubs(:popen).yields(MockProcess.new)
|
82
|
-
post "/example/git-receive-pack", {}, {"CONTENT_TYPE" => "application/x-git-receive-pack-request"}
|
82
|
+
post "/example.git/git-receive-pack", {}, {"CONTENT_TYPE" => "application/x-git-receive-pack-request"}
|
83
83
|
assert_equal 200, r.status
|
84
84
|
assert_equal "application/x-git-receive-pack-result", r.headers["Content-Type"]
|
85
85
|
end
|
86
86
|
|
87
87
|
def test_info_refs_dumb
|
88
|
-
get "/example
|
88
|
+
get "/example.git/info/refs"
|
89
89
|
assert_equal 200, r.status
|
90
90
|
end
|
91
91
|
|
92
92
|
def test_info_packs
|
93
|
-
get "/example
|
93
|
+
get "/example.git/objects/info/packs"
|
94
94
|
assert_equal 200, r.status
|
95
95
|
assert_match /P pack-(.*?).pack/, r.body
|
96
96
|
end
|
97
97
|
|
98
98
|
def test_loose_objects
|
99
99
|
path, content = write_test_objects
|
100
|
-
get "/example
|
100
|
+
get "/example.git/objects/#{path}"
|
101
101
|
assert_equal 200, r.status
|
102
102
|
assert_equal content, r.body
|
103
103
|
remove_test_objects
|
@@ -105,7 +105,7 @@ class GitHttpTest < Test::Unit::TestCase
|
|
105
105
|
|
106
106
|
def test_pack_file
|
107
107
|
path, content = write_test_objects
|
108
|
-
get "/example
|
108
|
+
get "/example.git/objects/pack/pack-#{content}.pack"
|
109
109
|
assert_equal 200, r.status
|
110
110
|
assert_equal content, r.body
|
111
111
|
remove_test_objects
|
@@ -113,44 +113,44 @@ class GitHttpTest < Test::Unit::TestCase
|
|
113
113
|
|
114
114
|
def test_index_file
|
115
115
|
path, content = write_test_objects
|
116
|
-
get "/example
|
116
|
+
get "/example.git/objects/pack/pack-#{content}.idx"
|
117
117
|
assert_equal 200, r.status
|
118
118
|
assert_equal content, r.body
|
119
119
|
remove_test_objects
|
120
120
|
end
|
121
121
|
|
122
122
|
def test_text_file
|
123
|
-
get "/example
|
123
|
+
get "/example.git/HEAD"
|
124
124
|
assert_equal 200, r.status
|
125
|
-
assert_equal
|
125
|
+
assert_equal 23, r.body.size # submodules have detached head
|
126
126
|
end
|
127
127
|
|
128
128
|
def test_no_size_avail
|
129
129
|
File.stubs('size?').returns(false)
|
130
|
-
get "/example
|
130
|
+
get "/example.git/HEAD"
|
131
131
|
assert_equal 200, r.status
|
132
|
-
assert_equal
|
132
|
+
assert_equal 28, r.body.size # submodules have detached head
|
133
133
|
end
|
134
134
|
|
135
135
|
def test_config_upload_pack_off
|
136
136
|
a1 = app
|
137
137
|
a1.set_config_setting(:upload_pack, false)
|
138
138
|
session = Rack::Test::Session.new(a1)
|
139
|
-
session.get "/example/info/refs?service=git-upload-pack"
|
140
|
-
assert_equal
|
139
|
+
session.get "/example.git/info/refs?service=git-upload-pack", {}, {"CONTENT_TYPE" => "application/x-git-upload-pack-request"}
|
140
|
+
assert_equal 403, session.last_response.status
|
141
141
|
end
|
142
142
|
|
143
143
|
def test_config_receive_pack_off
|
144
144
|
a1 = app
|
145
145
|
a1.set_config_setting(:receive_pack, false)
|
146
146
|
session = Rack::Test::Session.new(a1)
|
147
|
-
session.get "/example/info/refs?service=git-receive-pack"
|
148
|
-
assert_equal
|
147
|
+
session.get "/example.git/info/refs?service=git-receive-pack", {}, {"CONTENT_TYPE" => "application/x-git-receive-pack-request"}
|
148
|
+
assert_equal 403, session.last_response.status
|
149
149
|
end
|
150
150
|
|
151
151
|
def test_config_bad_service
|
152
|
-
get "/example/info/refs?service=git-receive-packfile"
|
153
|
-
assert_equal
|
152
|
+
get "/example.git/info/refs?service=git-receive-packfile", {}, {"CONTENT_TYPE" => "application/x-git-receive-packfile-request"}
|
153
|
+
assert_equal 403, r.status
|
154
154
|
end
|
155
155
|
|
156
156
|
def test_git_config_receive_pack
|
@@ -159,16 +159,16 @@ class GitHttpTest < Test::Unit::TestCase
|
|
159
159
|
session = Rack::Test::Session.new(app1)
|
160
160
|
git = Grack::Git
|
161
161
|
git.any_instance.stubs(:config).with('http.receivepack').returns('')
|
162
|
-
session.get "/example/info/refs?service=git-receive-pack"
|
163
|
-
assert_equal
|
162
|
+
session.get "/example.git/info/refs?service=git-receive-pack", {}, {"CONTENT_TYPE" => "application/x-git-receive-pack-request"}
|
163
|
+
assert_equal 403, session.last_response.status
|
164
164
|
|
165
165
|
git.any_instance.stubs(:config).with('http.receivepack').returns('true')
|
166
|
-
session.get "/example/info/refs?service=git-receive-pack"
|
166
|
+
session.get "/example.git/info/refs?service=git-receive-pack", {}, {"CONTENT_TYPE" => "application/x-git-receive-pack-request"}
|
167
167
|
assert_equal 200, session.last_response.status
|
168
168
|
|
169
169
|
git.any_instance.stubs(:config).with('http.receivepack').returns('false')
|
170
|
-
session.get "/example/info/refs?service=git-receive-pack"
|
171
|
-
assert_equal
|
170
|
+
session.get "/example.git/info/refs?service=git-receive-pack", {}, {"CONTENT_TYPE" => "application/x-git-receive-pack-request"}
|
171
|
+
assert_equal 403, session.last_response.status
|
172
172
|
end
|
173
173
|
|
174
174
|
def test_git_config_upload_pack
|
@@ -177,16 +177,16 @@ class GitHttpTest < Test::Unit::TestCase
|
|
177
177
|
session = Rack::Test::Session.new(app1)
|
178
178
|
git = Grack::Git
|
179
179
|
git.any_instance.stubs(:config).with('http.uploadpack').returns('')
|
180
|
-
session.get "/example/info/refs?service=git-upload-pack"
|
180
|
+
session.get "/example.git/info/refs?service=git-upload-pack", {}, {"CONTENT_TYPE" => "application/x-git-upload-pack-request"}
|
181
181
|
assert_equal 200, session.last_response.status
|
182
182
|
|
183
183
|
git.any_instance.stubs(:config).with('http.uploadpack').returns('true')
|
184
|
-
session.get "/example/info/refs?service=git-upload-pack"
|
184
|
+
session.get "/example.git/info/refs?service=git-upload-pack", {}, {"CONTENT_TYPE" => "application/x-git-upload-pack-request"}
|
185
185
|
assert_equal 200, session.last_response.status
|
186
186
|
|
187
187
|
git.any_instance.stubs(:config).with('http.uploadpack').returns('false')
|
188
|
-
session.get "/example/info/refs?service=git-upload-pack"
|
189
|
-
assert_equal
|
188
|
+
session.get "/example.git/info/refs?service=git-upload-pack", {}, {"CONTENT_TYPE" => "application/x-git-upload-pack-request"}
|
189
|
+
assert_equal 403, session.last_response.status
|
190
190
|
end
|
191
191
|
|
192
192
|
def test_send_file
|
@@ -215,7 +215,7 @@ class GitHttpTest < Test::Unit::TestCase
|
|
215
215
|
|
216
216
|
def write_test_objects
|
217
217
|
content = Digest::SHA1.hexdigest('gitrocks')
|
218
|
-
base = File.join(File.expand_path(File.dirname(__FILE__)), 'example
|
218
|
+
base = File.join(File.expand_path(File.dirname(__FILE__)), 'example.git', 'objects')
|
219
219
|
obj = File.join(base, '20')
|
220
220
|
Dir.mkdir(obj) rescue nil
|
221
221
|
file = File.join(obj, content[0, 38])
|
@@ -229,7 +229,7 @@ class GitHttpTest < Test::Unit::TestCase
|
|
229
229
|
|
230
230
|
def remove_test_objects
|
231
231
|
content = Digest::SHA1.hexdigest('gitrocks')
|
232
|
-
base = File.join(File.expand_path(File.dirname(__FILE__)), 'example
|
232
|
+
base = File.join(File.expand_path(File.dirname(__FILE__)), 'example.git', 'objects')
|
233
233
|
obj = File.join(base, '20')
|
234
234
|
file = File.join(obj, content[0, 38])
|
235
235
|
pack = File.join(base, 'pack', "pack-#{content}.pack")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gitlab-grack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott Chacon
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-04-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -48,7 +48,6 @@ extensions: []
|
|
48
48
|
extra_rdoc_files: []
|
49
49
|
files:
|
50
50
|
- ".gitignore"
|
51
|
-
- ".gitmodules"
|
52
51
|
- ".travis.yml"
|
53
52
|
- CHANGELOG
|
54
53
|
- Gemfile
|
@@ -92,4 +91,3 @@ specification_version: 4
|
|
92
91
|
summary: Ruby/Rack Git Smart-HTTP Server Handler
|
93
92
|
test_files:
|
94
93
|
- tests/main_test.rb
|
95
|
-
has_rdoc:
|
data/.gitmodules
DELETED