git-lighttp 0.3.0

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.
Files changed (64) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +11 -0
  3. data/Makefile +41 -0
  4. data/README.pt-BR.rdoc +81 -0
  5. data/README.rdoc +75 -0
  6. data/Rakefile +50 -0
  7. data/doc/releases/v0.1.0.rdoc +11 -0
  8. data/doc/releases/v0.2.0.rdoc +24 -0
  9. data/doc/releases/v0.3.0.rdoc +13 -0
  10. data/git-lighttp.gemspec +25 -0
  11. data/lib/git/lighttp.rb +365 -0
  12. data/lib/git/lighttp/extensions.rb +73 -0
  13. data/lib/git/lighttp/http_backend.rb +178 -0
  14. data/lib/git/lighttp/treeish.rb +28 -0
  15. data/lib/git/lighttp/version.rb +26 -0
  16. data/test/all.rb +12 -0
  17. data/test/config_test.rb +43 -0
  18. data/test/fixtures/config.yml +13 -0
  19. data/test/fixtures/htgroup +3 -0
  20. data/test/fixtures/htpasswd +4 -0
  21. data/test/fixtures/mycode.git/HEAD +1 -0
  22. data/test/fixtures/mycode.git/config +4 -0
  23. data/test/fixtures/mycode.git/description +1 -0
  24. data/test/fixtures/mycode.git/hooks/applypatch-msg.sample +15 -0
  25. data/test/fixtures/mycode.git/hooks/commit-msg.sample +24 -0
  26. data/test/fixtures/mycode.git/hooks/post-commit.sample +8 -0
  27. data/test/fixtures/mycode.git/hooks/post-receive.sample +15 -0
  28. data/test/fixtures/mycode.git/hooks/post-update.sample +8 -0
  29. data/test/fixtures/mycode.git/hooks/pre-applypatch.sample +14 -0
  30. data/test/fixtures/mycode.git/hooks/pre-commit.sample +46 -0
  31. data/test/fixtures/mycode.git/hooks/pre-rebase.sample +169 -0
  32. data/test/fixtures/mycode.git/hooks/prepare-commit-msg.sample +36 -0
  33. data/test/fixtures/mycode.git/hooks/update.sample +128 -0
  34. data/test/fixtures/mycode.git/info/exclude +6 -0
  35. data/test/fixtures/mycode.git/info/refs +3 -0
  36. data/test/fixtures/mycode.git/objects/02/83eb96425444e17b97182e1ba9f216cc67c132 +0 -0
  37. data/test/fixtures/mycode.git/objects/03/9927042df267a1bc606fc4485b7a79b6a9e3cd +1 -0
  38. data/test/fixtures/mycode.git/objects/0d/eed0a56fa8f5f2a788d58b3ea235afd547b828 +2 -0
  39. data/test/fixtures/mycode.git/objects/4b/825dc642cb6eb9a060e54bf8d69288fbee4904 +0 -0
  40. data/test/fixtures/mycode.git/objects/5e/54a0767e0c380f3baab17938d68c7f464cf171 +1 -0
  41. data/test/fixtures/mycode.git/objects/63/9b96262e7e19ca2169575e797b234098b8a72e +0 -0
  42. data/test/fixtures/mycode.git/objects/71/6e9568eed27d5ee4378b3ecf6dd095a547bde9 +1 -0
  43. data/test/fixtures/mycode.git/objects/b6/f3f0fabeaaaaf2db22b8ef98f59115baec7ef9 +0 -0
  44. data/test/fixtures/mycode.git/objects/be/118435b9d908fd4a689cd8b0cc98059911a31a +0 -0
  45. data/test/fixtures/mycode.git/objects/db/aefcb5bde664671c73b99515c386dcbc7f22b6 +0 -0
  46. data/test/fixtures/mycode.git/objects/eb/669b878d2013ac70aa5dee75e6357ea81d16ea +0 -0
  47. data/test/fixtures/mycode.git/objects/ed/10cfcf72862e140c97fe899cba2a55f4cb4c20 +0 -0
  48. data/test/fixtures/mycode.git/objects/ed/1c3a255ab3fce056dc31cd82df9f61a4d9fa22 +0 -0
  49. data/test/fixtures/mycode.git/objects/info/alternates +0 -0
  50. data/test/fixtures/mycode.git/objects/info/http-alternates +0 -0
  51. data/test/fixtures/mycode.git/objects/info/packs +2 -0
  52. data/test/fixtures/mycode.git/objects/pack/pack-40a8636b62258fffd78ec1e8d254116e72d385a9.idx +0 -0
  53. data/test/fixtures/mycode.git/objects/pack/pack-40a8636b62258fffd78ec1e8d254116e72d385a9.pack +0 -0
  54. data/test/fixtures/mycode.git/packed-refs +4 -0
  55. data/test/fixtures/mycode.git/refs/heads/master +1 -0
  56. data/test/fixtures/mycode.git/refs/tags/v0.1.0 +1 -0
  57. data/test/helpers.rb +53 -0
  58. data/test/htgroup_test.rb +29 -0
  59. data/test/htpasswd_test.rb +63 -0
  60. data/test/http_backend_authentication_test.rb +61 -0
  61. data/test/http_backend_test.rb +123 -0
  62. data/test/project_handler_test.rb +45 -0
  63. data/test/treeish_test.rb +33 -0
  64. metadata +121 -0
@@ -0,0 +1 @@
1
+ x��MN�0 @a�9�/��i~K+����LP��:��T���O����%��y�BVk�w!��M<�DER�R(a ���es�C���F���,�U�֔��-� ~͢d�{������1:|���r��K���k�_�h�`!�B��ќz�N�wȼ��~����_Z&Ծ������X'
@@ -0,0 +1,2 @@
1
+ x��M� F]s���
2
+ �][npp֪֝�z���!5���$ʘ���jR�
@@ -0,0 +1 @@
1
+ x��Aj�0@Ѭu��@�4�G�t�c$��-[��
@@ -0,0 +1 @@
1
+ x��A� @Qלb.`3��0�1ƅ�@��$���6�7p���ZJ�8��1� N�K�F�`9�G�<���Œvn
File without changes
@@ -0,0 +1,2 @@
1
+ P pack-40a8636b62258fffd78ec1e8d254116e72d385a9.pack
2
+
@@ -0,0 +1,4 @@
1
+ # pack-refs with: peeled
2
+ 039927042df267a1bc606fc4485b7a79b6a9e3cd refs/heads/master
3
+ dbaefcb5bde664671c73b99515c386dcbc7f22b6 refs/tags/v0.1.0
4
+ ^039927042df267a1bc606fc4485b7a79b6a9e3cd
@@ -0,0 +1 @@
1
+ 0deed0a56fa8f5f2a788d58b3ea235afd547b828
@@ -0,0 +1 @@
1
+ dbaefcb5bde664671c73b99515c386dcbc7f22b6
data/test/helpers.rb ADDED
@@ -0,0 +1,53 @@
1
+ FIXTURES = File.expand_path(File.join(File.dirname(__FILE__), 'fixtures')) unless defined? FIXTURES
2
+
3
+ module Minitest
4
+ class Test
5
+ def fixtures(*args)
6
+ File.join(FIXTURES, *(args.map(&:to_s)))
7
+ end
8
+
9
+ def debugger
10
+ end unless defined? debugger
11
+
12
+ end
13
+
14
+ module Assertions
15
+
16
+ def assert_hash_equal(expected, actual, message = nil)
17
+ messages = {}
18
+ expected.keys.each do |key|
19
+ equal = actual[key] == expected[key]
20
+ messages[key] = build_message(message, "#{expected[key]} expected but was <?>", actual[key])
21
+ assert_block(messages[key]) { expected[key] == actual[key] }
22
+ end
23
+ end
24
+ end
25
+
26
+ end
27
+
28
+ class MockProcess
29
+
30
+ def initialize
31
+ @counter = 0
32
+ end
33
+
34
+ def write(data)
35
+ $stdout.puts data
36
+ end
37
+
38
+ def read(data)
39
+ $sdtout.puts data
40
+ end
41
+
42
+ def eof?
43
+ @counter += 1
44
+ @counter > 10 ? true : false
45
+ end
46
+
47
+ end
48
+
49
+ class IO
50
+ def self.popen(*args)
51
+ MockProcess.new
52
+ end
53
+ end
@@ -0,0 +1,29 @@
1
+ describe 'HTTP group handler' do
2
+ before do
3
+ @groups = {
4
+ 'writers' => %w[mark matthew luke john],
5
+ 'disciples' => %w[john peter],
6
+ 'prophets' => %w[malachi jeremiah]
7
+ }
8
+
9
+ @htgroup = Git::Lighttp::Htgroup.new(fixtures('htgroup'))
10
+ end
11
+
12
+ it 'find member' do
13
+ @groups.each do |group, members|
14
+ members.each do |username|
15
+ found = @htgroup.members(group).include? username
16
+ assert found
17
+ end
18
+ end
19
+ end
20
+
21
+ it 'find member' do
22
+ @groups.each do |group, members|
23
+ members.each do |username|
24
+ found = @htgroup.groups(username).include? group
25
+ assert found
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,63 @@
1
+ describe 'HTTP password handler' do
2
+ before do
3
+ @passwords = {
4
+ 'matthew' => 'zKOzsdCzE.mEE',
5
+ 'mark' => 'V5.e7XhcXHmQc',
6
+ 'luke' => '1y687odVzuFJs',
7
+ 'john' => 'BInD5.JEyr5Ng'
8
+ }
9
+ @htpasswd = Git::Lighttp::Htpasswd.new(fixtures('htpasswd'))
10
+ end
11
+
12
+ after do
13
+ File.delete fixtures('htpasswd.tmp') if File.exist? fixtures('htpasswd.tmp')
14
+ end
15
+
16
+ it 'find user' do
17
+ @passwords.each do |username, password|
18
+ assert_equal password, @htpasswd.find(username)
19
+ @htpasswd.find username do |pass, salt|
20
+ assert_equal password, pass
21
+ assert_equal password[0,2], salt
22
+ end
23
+ end
24
+ end
25
+
26
+ it 'check authentication of the user' do
27
+ @passwords.keys.each do |user|
28
+ assert !@htpasswd.authenticated?(user, 'invalid')
29
+ assert @htpasswd.authenticated?(user, 's3kr3t')
30
+ end
31
+ end
32
+
33
+ it 'create or update user' do
34
+ Git::Lighttp::Htpasswd.new fixtures('htpasswd.tmp') do |htpasswd|
35
+ htpasswd.create 'judas', 'hanged'
36
+ assert htpasswd.include?('judas')
37
+ assert htpasswd.authenticated?('judas', 'hanged')
38
+ end
39
+ end
40
+
41
+ it 'list users' do
42
+ assert_equal 4, @htpasswd.size
43
+ @passwords.keys.each do |user|
44
+ assert @htpasswd.include?(user)
45
+ end
46
+ end
47
+
48
+ it 'destroy user' do
49
+ Git::Lighttp::Htpasswd.new fixtures('htpasswd.tmp') do |htpasswd|
50
+ htpasswd.create 'judas', 'hanged'
51
+ assert htpasswd.include?('judas')
52
+
53
+ htpasswd.destroy 'judas'
54
+
55
+ assert !htpasswd.include?('judas')
56
+ end
57
+ end
58
+
59
+ it 'check invalid user' do
60
+ assert !@htpasswd.authenticated?('nobody', 'empty')
61
+ end
62
+
63
+ end
@@ -0,0 +1,61 @@
1
+ include Rack::Test::Methods
2
+
3
+ alias request last_request
4
+
5
+ alias response last_response
6
+
7
+ describe 'HTTP Backend server authentication' do
8
+ def app
9
+ Git::Lighttp::HttpBackend.configure do |server|
10
+ server.project_root = fixtures
11
+ server.git_path = '/usr/bin/git'
12
+ server.authenticate = true
13
+ end
14
+ Git::Lighttp::HttpBackend
15
+ end
16
+
17
+ before do
18
+ # return 500 objects/info/http-alternates
19
+ # objects/info/alternates
20
+ @paths = [
21
+ [ :get, 'HEAD' ],
22
+ [ :get, 'info/refs' ],
23
+ [ :get, 'objects/info/packs' ],
24
+ [ :get, 'objects/02/83eb96425444e17b97182e1ba9f216cc67c132' ],
25
+ [ :get, 'objects/03/9927042df267a1bc606fc4485b7a79b6a9e3cd' ],
26
+ [ :get, 'objects/4b/825dc642cb6eb9a060e54bf8d69288fbee4904' ],
27
+ [ :get, 'objects/5e/54a0767e0c380f3baab17938d68c7f464cf171' ],
28
+ [ :get, 'objects/71/6e9568eed27d5ee4378b3ecf6dd095a547bde9' ],
29
+ [ :get, 'objects/be/118435b9d908fd4a689cd8b0cc98059911a31a' ],
30
+ [ :get, 'objects/db/aefcb5bde664671c73b99515c386dcbc7f22b6' ],
31
+ [ :get, 'objects/eb/669b878d2013ac70aa5dee75e6357ea81d16ea' ],
32
+ [ :get, 'objects/ed/10cfcf72862e140c97fe899cba2a55f4cb4c20' ],
33
+ [ :get, 'objects/pack/pack-40a8636b62258fffd78ec1e8d254116e72d385a9.idx' ],
34
+ [ :get, 'objects/pack/pack-40a8636b62258fffd78ec1e8d254116e72d385a9.pack' ],
35
+ [ :get, 'info/refs', { :service => 'git-upload-pack' } ],
36
+ [ :get, 'info/refs', { :service => 'git-receive-pack' } ],
37
+ [ :post, 'git-upload-pack', {}, { 'CONTENT_TYPE' => 'application/x-git-upload-pack-request' } ],
38
+ [ :post, 'git-receive-pack', {}, { 'CONTENT_TYPE' => 'application/x-git-receive-pack-request' } ]
39
+ ]
40
+ end
41
+
42
+ it 'unauthorize repository paths' do
43
+ @paths.each do |params|
44
+ verb = params.shift
45
+ path = params.shift
46
+ send verb, "/mycode.git/#{path}", *params
47
+ assert_equal 401, response.status
48
+ end
49
+ end
50
+
51
+ it 'authorize repository paths' do
52
+ authorize('john', 's3kr3t')
53
+ @paths.each do |params|
54
+ verb = params.shift
55
+ path = params.shift
56
+ send verb, "/mycode.git/#{path}", *params
57
+ assert_equal 200, response.status, request.env['sinatra.error']
58
+ end
59
+ end
60
+
61
+ end
@@ -0,0 +1,123 @@
1
+ include Rack::Test::Methods
2
+
3
+ alias response last_response
4
+
5
+ describe 'HTTP Backend server' do
6
+ def app
7
+ Git::Lighttp::HttpBackend.configure do |server|
8
+ server.project_root = fixtures
9
+ server.git_path = '/usr/bin/git'
10
+ server.get_any_file = true
11
+ server.upload_pack = true
12
+ server.receive_pack = true
13
+ server.authenticate = false
14
+ end
15
+ Git::Lighttp::HttpBackend
16
+ end
17
+
18
+ before do
19
+ @objects = [
20
+ '02/83eb96425444e17b97182e1ba9f216cc67c132',
21
+ '03/9927042df267a1bc606fc4485b7a79b6a9e3cd',
22
+ '4b/825dc642cb6eb9a060e54bf8d69288fbee4904',
23
+ '5e/54a0767e0c380f3baab17938d68c7f464cf171',
24
+ '71/6e9568eed27d5ee4378b3ecf6dd095a547bde9',
25
+ 'be/118435b9d908fd4a689cd8b0cc98059911a31a',
26
+ 'db/aefcb5bde664671c73b99515c386dcbc7f22b6',
27
+ 'eb/669b878d2013ac70aa5dee75e6357ea81d16ea',
28
+ 'ed/10cfcf72862e140c97fe899cba2a55f4cb4c20'
29
+ ]
30
+ end
31
+
32
+ it 'get head file content' do
33
+ get '/mycode.git/HEAD' do
34
+ assert_equal 200, response.status
35
+ assert_equal "ref: refs/heads/master\n", response.body
36
+ end
37
+ end
38
+
39
+ it 'get info refs' do
40
+ get '/mycode.git/info/refs' do
41
+ assert_equal 200, response.status
42
+ assert_match 'refs/heads/master', response.body
43
+ assert_match 'refs/tags/v0.1.0', response.body
44
+ end
45
+ end
46
+
47
+ it 'get info alternates' do
48
+ get '/mycode.git/objects/info/alternates' do
49
+ assert_equal 200, response.status
50
+ end
51
+ end
52
+
53
+ it 'get info http alternates' do
54
+ get '/mycode.git/objects/info/http-alternates' do
55
+ assert_equal 200, response.status
56
+ end
57
+ end
58
+
59
+ it 'get object info packs' do
60
+ get '/mycode.git/objects/info/packs' do
61
+ assert_equal 200, response.status
62
+ assert_equal 'P pack-40a8636b62258fffd78ec1e8d254116e72d385a9.pack',
63
+ response.body.split("\n").first
64
+ end
65
+ end
66
+
67
+ it 'get loose objects' do
68
+ @objects.each do |object|
69
+ get "/mycode.git/objects/#{object}" do
70
+ assert_equal 200, response.status
71
+ assert_equal 'application/x-git-loose-object', response.content_type
72
+ end
73
+ end
74
+ end
75
+
76
+ it 'get pack file' do
77
+ get '/mycode.git/objects/pack/pack-40a8636b62258fffd78ec1e8d254116e72d385a9.idx' do
78
+ assert_equal 200, response.status
79
+ assert_equal 'application/x-git-packed-objects-toc', response.content_type
80
+ end
81
+ end
82
+
83
+ it 'get index file' do
84
+ get '/mycode.git/objects/pack/pack-40a8636b62258fffd78ec1e8d254116e72d385a9.pack' do
85
+ assert_equal 200, response.status
86
+ assert_equal 'application/x-git-packed-objects', response.content_type
87
+ end
88
+ end
89
+
90
+ it 'upload advertisement' do
91
+ get '/mycode.git/info/refs', :service => 'git-upload-pack' do
92
+ assert_equal 200, response.status
93
+ assert_equal 'application/x-git-upload-pack-advertisement', response.content_type
94
+ assert_equal '001e# service=git-upload-pack', response.body.split("\n").first
95
+ assert_match 'multi_ack_detailed', response.body
96
+ end
97
+ end
98
+
99
+ it 'receive advertisement' do
100
+ get '/mycode.git/info/refs', :service => 'git-receive-pack' do
101
+ assert_equal 200, response.status
102
+ assert_equal 'application/x-git-receive-pack-advertisement', response.content_type
103
+ assert_equal '001f# service=git-receive-pack', response.body.split("\n").first
104
+ assert_match 'report-status', response.body
105
+ assert_match 'delete-refs', response.body
106
+ assert_match 'ofs-delta', response.body
107
+ end
108
+ end
109
+
110
+ # this test use mock in IO.popen. See in test/helpers.rb.
111
+ it 'RPC for upload packets' do
112
+ post '/mycode.git/git-upload-pack', {}, {'CONTENT_TYPE' => 'application/x-git-upload-pack-request'}
113
+ assert_equal 200, response.status
114
+ assert_equal 'application/x-git-upload-pack-result', response.content_type
115
+ end
116
+
117
+ # this test use mock in IO.popen. See in test/helpers.rb.
118
+ it 'RPC for receive packets' do
119
+ post '/mycode.git/git-receive-pack', {}, {'CONTENT_TYPE' => 'application/x-git-receive-pack-request'}
120
+ assert_equal 200, response.status
121
+ assert_equal 'application/x-git-receive-pack-result', response.content_type
122
+ end
123
+ end
@@ -0,0 +1,45 @@
1
+ describe 'Project handler' do
2
+ before do
3
+ @git = Git::Lighttp::ProjectHandler.new(fixtures, '/usr/bin/git')
4
+ @objects = [
5
+ 'HEAD',
6
+ 'info/refs',
7
+ 'objects/info/packs',
8
+ 'objects/02/83eb96425444e17b97182e1ba9f216cc67c132',
9
+ 'objects/03/9927042df267a1bc606fc4485b7a79b6a9e3cd',
10
+ 'objects/4b/825dc642cb6eb9a060e54bf8d69288fbee4904',
11
+ 'objects/5e/54a0767e0c380f3baab17938d68c7f464cf171',
12
+ 'objects/71/6e9568eed27d5ee4378b3ecf6dd095a547bde9',
13
+ 'objects/be/118435b9d908fd4a689cd8b0cc98059911a31a',
14
+ 'objects/db/aefcb5bde664671c73b99515c386dcbc7f22b6',
15
+ 'objects/eb/669b878d2013ac70aa5dee75e6357ea81d16ea',
16
+ 'objects/ed/10cfcf72862e140c97fe899cba2a55f4cb4c20',
17
+ 'objects/pack/pack-40a8636b62258fffd78ec1e8d254116e72d385a9.idx',
18
+ 'objects/pack/pack-40a8636b62258fffd78ec1e8d254116e72d385a9.pack'
19
+ ]
20
+ @git.repository = 'mycode.git'
21
+ end
22
+
23
+ it 'check basic attributes' do
24
+ assert_equal fixtures, @git.project_root
25
+ assert_equal '/usr/bin/git', @git.path
26
+ end
27
+
28
+ it 'config repository path' do
29
+ assert_equal fixtures('mycode.git'), @git.repository
30
+ end
31
+
32
+ it 'find repository objects' do
33
+ @objects.each do |object|
34
+ assert_equal fixtures('mycode.git', object), @git.path_to(object)
35
+ assert File.exist?(@git.path_to(object))
36
+ end
37
+ end
38
+
39
+ it 'list tree files' do
40
+ assert_equal 3, @git.tree.size
41
+ assert_equal 'README.txt', @git.tree[1][:fname]
42
+ assert_equal 'lib', @git.tree.last[:fname]
43
+ assert_equal 'mycode.rb', @git.tree('HEAD', 'lib').first[:fname]
44
+ end
45
+ end
@@ -0,0 +1,33 @@
1
+ include Rack::Test::Methods
2
+
3
+ alias request last_request
4
+
5
+ alias response last_response
6
+
7
+ describe 'Project tree' do
8
+ def app
9
+ Git::Lighttp::Treeish.configure do |server|
10
+ server.project_root = fixtures
11
+ end
12
+ Git::Lighttp::Treeish
13
+ end
14
+
15
+ it 'get tree of project from reference' do
16
+ get '/mycode.git/HEAD' do
17
+ assert_equal 200, response.status, request.env['sinatra.error']
18
+ assert_match 'application/json', response.content_type
19
+ assert_match 'README.txt', response.body
20
+ assert_equal 3, JSON.parse(response.body).size
21
+ end
22
+ end
23
+
24
+ it 'get tree of project from reference and path' do
25
+ get '/mycode.git/HEAD/lib' do
26
+ assert_equal 200, response.status, request.env['sinatra.error']
27
+ assert_match 'application/json', response.content_type
28
+ assert_match 'mycode.rb', response.body
29
+ assert_equal 'mycode.rb', JSON.parse(response.body).first['fname']
30
+ assert_equal 1, JSON.parse(response.body).size
31
+ end
32
+ end
33
+ end