gitlab-grack 2.0.0.rc1 → 2.0.0.rc2

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.
@@ -0,0 +1,3 @@
1
+ module Grack
2
+ VERSION = "2.0.0.rc2"
3
+ end
@@ -0,0 +1,255 @@
1
+ require 'rack'
2
+ require 'rack/test'
3
+ require 'test/unit'
4
+ require 'mocha'
5
+ require 'digest/sha1'
6
+
7
+ require_relative '../lib/grack/server.rb'
8
+ require 'pp'
9
+
10
+ class GitHttpTest < Test::Unit::TestCase
11
+ include Rack::Test::Methods
12
+
13
+ def example
14
+ File.expand_path(File.dirname(__FILE__))
15
+ end
16
+
17
+ def app
18
+ config = {
19
+ :project_root => example,
20
+ :upload_pack => true,
21
+ :receive_pack => true,
22
+ }
23
+ Grack::Server.new(config)
24
+ end
25
+
26
+ def test_upload_pack_advertisement
27
+ get "/example/info/refs?service=git-upload-pack"
28
+ assert_equal 200, r.status
29
+ assert_equal "application/x-git-upload-pack-advertisement", r.headers["Content-Type"]
30
+ assert_equal "001e# service=git-upload-pack", r.body.split("\n").first
31
+ assert_match 'multi_ack_detailed', r.body
32
+ end
33
+
34
+ def test_no_access_wrong_content_type_up
35
+ post "/example/git-upload-pack"
36
+ assert_equal 403, r.status
37
+ end
38
+
39
+ def test_no_access_wrong_content_type_rp
40
+ post "/example/git-receive-pack"
41
+ assert_equal 403, r.status
42
+ end
43
+
44
+ def test_no_access_wrong_method_rcp
45
+ get "/example/git-upload-pack"
46
+ assert_equal 400, r.status
47
+ end
48
+
49
+ def test_no_access_wrong_command_rcp
50
+ post "/example/git-upload-packfile"
51
+ assert_equal 404, r.status
52
+ end
53
+
54
+ def test_no_access_wrong_path_rcp
55
+ post "/example-wrong/git-upload-pack"
56
+ assert_equal 404, r.status
57
+ end
58
+
59
+ def test_upload_pack_rpc
60
+ IO.stubs(:popen).returns(MockProcess.new)
61
+ post "/example/git-upload-pack", {}, {"CONTENT_TYPE" => "application/x-git-upload-pack-request"}
62
+ assert_equal 200, r.status
63
+ assert_equal "application/x-git-upload-pack-result", r.headers["Content-Type"]
64
+ end
65
+
66
+ def test_receive_pack_advertisement
67
+ get "/example/info/refs?service=git-receive-pack"
68
+ assert_equal 200, r.status
69
+ assert_equal "application/x-git-receive-pack-advertisement", r.headers["Content-Type"]
70
+ assert_equal "001f# service=git-receive-pack", r.body.split("\n").first
71
+ assert_match 'report-status', r.body
72
+ assert_match 'delete-refs', r.body
73
+ assert_match 'ofs-delta', r.body
74
+ end
75
+
76
+ def test_recieve_pack_rpc
77
+ IO.stubs(:popen).yields(MockProcess.new)
78
+ post "/example/git-receive-pack", {}, {"CONTENT_TYPE" => "application/x-git-receive-pack-request"}
79
+ assert_equal 200, r.status
80
+ assert_equal "application/x-git-receive-pack-result", r.headers["Content-Type"]
81
+ end
82
+
83
+ def test_info_refs_dumb
84
+ get "/example/.git/info/refs"
85
+ assert_equal 200, r.status
86
+ end
87
+
88
+ def test_info_packs
89
+ get "/example/.git/objects/info/packs"
90
+ assert_equal 200, r.status
91
+ assert_match /P pack-(.*?).pack/, r.body
92
+ end
93
+
94
+ def test_loose_objects
95
+ path, content = write_test_objects
96
+ get "/example/.git/objects/#{path}"
97
+ assert_equal 200, r.status
98
+ assert_equal content, r.body
99
+ remove_test_objects
100
+ end
101
+
102
+ def test_pack_file
103
+ path, content = write_test_objects
104
+ get "/example/.git/objects/pack/pack-#{content}.pack"
105
+ assert_equal 200, r.status
106
+ assert_equal content, r.body
107
+ remove_test_objects
108
+ end
109
+
110
+ def test_index_file
111
+ path, content = write_test_objects
112
+ get "/example/.git/objects/pack/pack-#{content}.idx"
113
+ assert_equal 200, r.status
114
+ assert_equal content, r.body
115
+ remove_test_objects
116
+ end
117
+
118
+ def test_text_file
119
+ get "/example/.git/HEAD"
120
+ assert_equal 200, r.status
121
+ assert_equal 41, r.body.size # submodules have detached head
122
+ end
123
+
124
+ def test_no_size_avail
125
+ File.stubs('size?').returns(false)
126
+ get "/example/.git/HEAD"
127
+ assert_equal 200, r.status
128
+ assert_equal 46, r.body.size # submodules have detached head
129
+ end
130
+
131
+ def test_config_upload_pack_off
132
+ a1 = app
133
+ a1.set_config_setting(:upload_pack, false)
134
+ session = Rack::Test::Session.new(a1)
135
+ session.get "/example/info/refs?service=git-upload-pack"
136
+ assert_equal 404, session.last_response.status
137
+ end
138
+
139
+ def test_config_receive_pack_off
140
+ a1 = app
141
+ a1.set_config_setting(:receive_pack, false)
142
+ session = Rack::Test::Session.new(a1)
143
+ session.get "/example/info/refs?service=git-receive-pack"
144
+ assert_equal 404, session.last_response.status
145
+ end
146
+
147
+ def test_config_bad_service
148
+ get "/example/info/refs?service=git-receive-packfile"
149
+ assert_equal 404, r.status
150
+ end
151
+
152
+ def test_git_config_receive_pack
153
+ app1 = Grack::Server.new({:project_root => example})
154
+ session = Rack::Test::Session.new(app1)
155
+
156
+ app1.stubs(:get_git_config).with('http.receivepack').returns('')
157
+ session.get "/example/info/refs?service=git-receive-pack"
158
+ assert_equal 404, session.last_response.status
159
+
160
+ app1.stubs(:get_git_config).with('http.receivepack').returns('true')
161
+ session.get "/example/info/refs?service=git-receive-pack"
162
+ assert_equal 200, session.last_response.status
163
+
164
+ app1.stubs(:get_git_config).with('http.receivepack').returns('false')
165
+ session.get "/example/info/refs?service=git-receive-pack"
166
+ assert_equal 404, session.last_response.status
167
+ end
168
+
169
+ def test_git_config_upload_pack
170
+ app1 = Grack::Server.new({:project_root => example})
171
+ session = Rack::Test::Session.new(app1)
172
+
173
+ app1.stubs(:get_git_config).with('http.uploadpack').returns('')
174
+ session.get "/example/info/refs?service=git-upload-pack"
175
+ assert_equal 200, session.last_response.status
176
+
177
+ app1.stubs(:get_git_config).with('http.uploadpack').returns('true')
178
+ session.get "/example/info/refs?service=git-upload-pack"
179
+ assert_equal 200, session.last_response.status
180
+
181
+ app1.stubs(:get_git_config).with('http.uploadpack').returns('false')
182
+ session.get "/example/info/refs?service=git-upload-pack"
183
+ assert_equal 404, session.last_response.status
184
+ end
185
+
186
+ def test_send_file
187
+ app1 = app
188
+ app1.instance_variable_set(:@dir, Dir.pwd)
189
+ # Reject path traversal
190
+ assert_equal 404, app1.send_file('tests/../tests', 'text/plain').first
191
+ # Reject paths starting with '|', avoid File.read('|touch /tmp/pawned; ls /tmp')
192
+ assert_equal 404, app1.send_file('|tests', 'text/plain').first
193
+ end
194
+
195
+ def test_get_git_dir
196
+ # Guard against non-existent directories
197
+ assert_equal false, app.get_git_dir('foobar')
198
+ # Guard against path traversal
199
+ assert_equal false, app.get_git_dir('/../tests')
200
+ end
201
+
202
+ private
203
+
204
+ def r
205
+ last_response
206
+ end
207
+
208
+ def write_test_objects
209
+ content = Digest::SHA1.hexdigest('gitrocks')
210
+ base = File.join(File.expand_path(File.dirname(__FILE__)), 'example', '.git', 'objects')
211
+ obj = File.join(base, '20')
212
+ Dir.mkdir(obj) rescue nil
213
+ file = File.join(obj, content[0, 38])
214
+ File.open(file, 'w') { |f| f.write(content) }
215
+ pack = File.join(base, 'pack', "pack-#{content}.pack")
216
+ File.open(pack, 'w') { |f| f.write(content) }
217
+ idx = File.join(base, 'pack', "pack-#{content}.idx")
218
+ File.open(idx, 'w') { |f| f.write(content) }
219
+ ["20/#{content[0,38]}", content]
220
+ end
221
+
222
+ def remove_test_objects
223
+ content = Digest::SHA1.hexdigest('gitrocks')
224
+ base = File.join(File.expand_path(File.dirname(__FILE__)), 'example', '.git', 'objects')
225
+ obj = File.join(base, '20')
226
+ file = File.join(obj, content[0, 38])
227
+ pack = File.join(base, 'pack', "pack-#{content}.pack")
228
+ idx = File.join(base, 'pack', "pack-#{content}.idx")
229
+ File.unlink(file)
230
+ File.unlink(pack)
231
+ File.unlink(idx)
232
+ end
233
+
234
+ end
235
+
236
+ class MockProcess
237
+ def initialize
238
+ @counter = 0
239
+ end
240
+
241
+ def write(data)
242
+ end
243
+
244
+ def read(data)
245
+ end
246
+
247
+ def eof?
248
+ @counter += 1
249
+ @counter > 1 ? true : false
250
+ end
251
+
252
+ def close_write
253
+ true
254
+ end
255
+ end
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.0.rc1
4
+ version: 2.0.0.rc2
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-01-22 00:00:00.000000000 Z
11
+ date: 2015-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -46,27 +46,22 @@ extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
48
  - ".gitignore"
49
- - ".ssh/.gitkeep"
49
+ - ".gitmodules"
50
+ - ".travis.yml"
51
+ - CHANGELOG
50
52
  - Gemfile
51
53
  - Gemfile.lock
52
- - Makefile
53
- - Procfile.example
54
54
  - README.md
55
- - Vagrantfile
56
- - database.yml.example
57
- - gitlab-openldap/.gitignore
58
- - gitlab-openldap/Makefile
59
- - gitlab-openldap/README.md
60
- - gitlab-openldap/bootstrap.ldif
61
- - gitlab-openldap/frontend.alt.example.com.ldif
62
- - gitlab-openldap/frontend.example.com.ldif
63
- - gitlab-openldap/run-slapd
64
- - gitlab-openldap/run-slapd-alt
65
- - gitlab-satellites/.gitkeep
66
- - redis/redis.conf.example
67
- - redis/resque.yml.example
68
- - repositories/.gitkeep
69
- - support/edit-gitlab.yml
55
+ - Rakefile
56
+ - examples/dispatch.fcgi
57
+ - grack.gemspec
58
+ - install.txt
59
+ - lib/grack.rb
60
+ - lib/grack/auth.rb
61
+ - lib/grack/bundle.rb
62
+ - lib/grack/server.rb
63
+ - lib/grack/version.rb
64
+ - tests/main_test.rb
70
65
  homepage: https://github.com/gitlabhq/grack
71
66
  licenses: []
72
67
  metadata: {}
@@ -86,8 +81,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
81
  version: 1.3.1
87
82
  requirements: []
88
83
  rubyforge_project:
89
- rubygems_version: 2.4.3
84
+ rubygems_version: 2.2.2
90
85
  signing_key:
91
86
  specification_version: 4
92
87
  summary: Ruby/Rack Git Smart-HTTP Server Handler
93
- test_files: []
88
+ test_files:
89
+ - tests/main_test.rb
data/Makefile DELETED
@@ -1,153 +0,0 @@
1
- gitlab_repo = https://gitlab.com/gitlab-org/gitlab-ce.git
2
- gitlab_shell_repo = https://gitlab.com/gitlab-org/gitlab-shell.git
3
- gitlab_ci_repo = https://gitlab.com/gitlab-org/gitlab-ci.git
4
- gitlab_runner_repo = https://gitlab.com/gitlab-org/gitlab-ci-runner.git
5
- gitlab_development_root = $(shell pwd)
6
- postgres_bin_dir = $(shell pg_config --bindir)
7
-
8
- all: gitlab-setup gitlab-shell-setup gitlab-ci-setup gitlab-runner-setup support-setup
9
-
10
- # Set up the GitLab Rails app
11
-
12
- gitlab-setup: gitlab/.git gitlab-config gitlab/.bundle
13
-
14
- gitlab/.git:
15
- git clone ${gitlab_repo} gitlab
16
-
17
- gitlab-config: gitlab/config/gitlab.yml gitlab/config/database.yml gitlab/config/unicorn.rb gitlab/config/resque.yml
18
-
19
- gitlab/config/gitlab.yml:
20
- sed -e "s|/home/git|${gitlab_development_root}|"\
21
- gitlab/config/gitlab.yml.example > gitlab/config/gitlab.yml
22
- support/edit-gitlab.yml gitlab/config/gitlab.yml
23
-
24
- gitlab/config/database.yml:
25
- sed "s|/home/git|${gitlab_development_root}|" database.yml.example > gitlab/config/database.yml
26
-
27
- gitlab/config/unicorn.rb:
28
- cp gitlab/config/unicorn.rb.example.development gitlab/config/unicorn.rb
29
-
30
- gitlab/config/resque.yml:
31
- sed "s|/home/git|${gitlab_development_root}|" redis/resque.yml.example > $@
32
-
33
- gitlab/.bundle:
34
- cd ${gitlab_development_root}/gitlab && bundle install --without mysql production --jobs 4
35
-
36
- # Set up gitlab-shell
37
-
38
- gitlab-shell-setup: gitlab-shell/.git gitlab-shell/config.yml gitlab-shell/.bundle
39
-
40
- gitlab-shell/.git:
41
- git clone ${gitlab_shell_repo} gitlab-shell
42
-
43
- gitlab-shell/config.yml:
44
- sed -e "s|/home/git|${gitlab_development_root}|"\
45
- -e "s|:8080/|:3000|"\
46
- -e "s|/usr/bin/redis-cli|$(shell which redis-cli)|"\
47
- -e "s|^ socket: .*| socket: ${gitlab_development_root}/redis/redis.socket|"\
48
- gitlab-shell/config.yml.example > gitlab-shell/config.yml
49
-
50
- gitlab-shell/.bundle:
51
- cd ${gitlab_development_root}/gitlab-shell && bundle install --without production --jobs 4
52
-
53
- # Set up gitlab-ci
54
- gitlab-ci-setup: gitlab-ci/.git gitlab-ci-config gitlab-ci/.bundle
55
-
56
- gitlab-ci/.git:
57
- git clone ${gitlab_ci_repo} gitlab-ci
58
-
59
- gitlab-ci-config: gitlab-ci/config/application.yml gitlab-ci/config/database.yml gitlab-ci/config/resque.yml gitlab-ci/config/unicorn.rb
60
-
61
- gitlab-ci/config/application.yml:
62
- cp gitlab-ci/config/application.yml.example.development $@
63
-
64
- gitlab-ci/config/database.yml:
65
- sed -e "s|gitlabhq|gitlabci|"\
66
- -e "s|/home/git|${gitlab_development_root}|"\
67
- database.yml.example > $@
68
-
69
- gitlab-ci/config/resque.yml:
70
- sed "s|/home/git|${gitlab_development_root}|" redis/resque.yml.example > $@
71
-
72
- gitlab-ci/config/unicorn.rb:
73
- cp gitlab-ci/config/unicorn.rb.example.development $@
74
-
75
- gitlab-ci/.bundle:
76
- cd ${gitlab_development_root}/gitlab-ci && bundle install --without mysql production --jobs 4
77
-
78
- gitlab-ci-clean:
79
- rm -rf gitlab-ci
80
-
81
- # Set up gitlab-runner
82
- gitlab-runner-setup: gitlab-runner/.git gitlab-runner/.bundle
83
-
84
- gitlab-runner/.git:
85
- git clone ${gitlab_runner_repo} gitlab-runner
86
-
87
- gitlab-runner/.bundle:
88
- cd ${gitlab_development_root}/gitlab-runner && bundle install --jobs 4
89
-
90
- gitlab-runner-clean:
91
- rm -rf gitlab-runner
92
-
93
- # Update gitlab, gitlab-shell, gitlab-ci and gitlab-runner
94
-
95
- update: gitlab-update gitlab-shell-update gitlab-ci-update gitlab-runner-update
96
-
97
- gitlab-update: gitlab/.git/pull
98
- cd ${gitlab_development_root}/gitlab && \
99
- bundle install --without mysql production --jobs 4 && \
100
- bundle exec rake db:migrate
101
-
102
- gitlab-shell-update: gitlab-shell/.git/pull
103
- cd ${gitlab_development_root}/gitlab-shell && \
104
- bundle install --without production --jobs 4
105
-
106
- gitlab-ci-update: gitlab-ci/.git/pull
107
- cd ${gitlab_development_root}/gitlab-ci && \
108
- bundle install --without mysql production --jobs 4 && \
109
- bundle exec rake db:migrate
110
-
111
- gitlab-runner-update: gitlab-runner/.git/pull
112
- cd ${gitlab_development_root}/gitlab-runner && \
113
- bundle install
114
-
115
- gitlab/.git/pull:
116
- cd ${gitlab_development_root}/gitlab && git pull --ff-only
117
-
118
- gitlab-shell/.git/pull:
119
- cd ${gitlab_development_root}/gitlab-shell && git pull --ff-only
120
-
121
- gitlab-ci/.git/pull:
122
- cd ${gitlab_development_root}/gitlab-ci && git pull --ff-only
123
-
124
- gitlab-runner/.git/pull:
125
- cd ${gitlab_development_root}/gitlab-runner && git pull --ff-only
126
-
127
- # Set up supporting services
128
-
129
- support-setup: Procfile redis postgresql .bundle
130
- @echo ""
131
- @echo "*********************************************"
132
- @echo "************** Setup finished! **************"
133
- @echo "*********************************************"
134
- sed -n '/^### Post-installation/,/^END Post-installation/p' README.md
135
- @echo "*********************************************"
136
-
137
- Procfile:
138
- sed -e "s|/home/git|${gitlab_development_root}|g"\
139
- -e "s|postgres |${postgres_bin_dir}/postgres |"\
140
- $@.example > $@
141
-
142
- redis: redis/redis.conf
143
-
144
- redis/redis.conf:
145
- sed "s|/home/git|${gitlab_development_root}|" $@.example > $@
146
-
147
- postgresql: postgresql/data/PG_VERSION
148
-
149
- postgresql/data/PG_VERSION:
150
- ${postgres_bin_dir}/initdb -E utf-8 postgresql/data
151
-
152
- .bundle:
153
- bundle install --jobs 4