-
Notifications
You must be signed in to change notification settings - Fork 0
/
gitpub_spec.rb
executable file
·208 lines (189 loc) · 7.42 KB
/
gitpub_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# -*- coding: utf-8 -*-
#!/usr/bin/env spec
require "gitpub"
require "rack"
require "tempfile"
describe GitPub, "with linux-2.6" do
before do
@git_dir = File.expand_path("linux-2.6/.git")
end
it "list all tags without PATH_INFO" do
gitpub = GitPub.new(@git_dir)
code, headers, res = gitpub.call({'PATH_INFO' => nil})
code.should == 200
headers["Content-Type"].should == "text/html; charset=utf-8"
headers["Content-Length"].should be_instance_of String
headers["Content-Length"].to_i.should > 0
body = res.body.to_s
/\.\./.should_not =~ body
/<pre>/.should_not =~ body
end
it "list all tags with PATH_INFO=/" do
gitpub = GitPub.new(@git_dir)
code, headers, res0 = gitpub.call({'PATH_INFO' => nil})
code, headers, res1 = gitpub.call({'PATH_INFO' => "/"})
code.should == 200
headers["Content-Type"].should == "text/html; charset=utf-8"
headers["Content-Length"].should be_instance_of String
headers["Content-Length"].to_i.should > 0
res0.body.should == res1.body
body = res1.body.to_s
/\.\./.should_not =~ body
/<pre>/.should_not =~ body
end
it "list all tags with PATH_INFO=/invalid-tag" do
gitpub = GitPub.new(@git_dir)
code, headers, res0 = gitpub.call({'PATH_INFO' => nil})
code, headers, res1 = gitpub.call({'PATH_INFO' => "/invalid-tag"})
code.should == 200
headers["Content-Type"].should == "text/html; charset=utf-8"
headers["Content-Length"].should be_instance_of String
headers["Content-Length"].to_i.should > 0
res0.body.should == res1.body
body = res1.body.to_s
/\.\./.should_not =~ body
/<pre>/.should_not =~ body
end
it "list no files with PATH_INFO=/invalid-tag/" do
gitpub = GitPub.new(@git_dir)
code, headers, res0 = gitpub.call({'PATH_INFO' => nil})
temp_stderr = Tempfile.new("stderr")
orig_stderr = STDERR.dup
STDERR.reopen(temp_stderr)
code, headers, res1 = gitpub.call({'PATH_INFO' => "/invalid-tag/"})
STDERR.reopen(orig_stderr)
temp_stderr.rewind
error = temp_stderr.read
temp_stderr.close
error.should == "fatal: Not a valid object name invalid-tag:\n"
code.should == 200
headers["Content-Type"].should == "text/html; charset=utf-8"
headers["Content-Length"].should be_instance_of String
headers["Content-Length"].to_i.should > 0
res0.body.should_not == res1.body
body = res1.body.to_s
/\.\./.should =~ body
/<pre>/.should_not =~ body
end
it "list pub tags only without PATH_INFO" do
gitpub = GitPub.new(@git_dir)
code, headers, res = gitpub.call({'PATH_INFO' => nil})
all_tags_length = headers["Content-Length"].to_i
gitpub = GitPub.new(@git_dir, /\Av2\.6\.\d+\z/)
code, headers, res = gitpub.call({'PATH_INFO' => nil})
code.should == 200
headers["Content-Type"].should == "text/html; charset=utf-8"
headers["Content-Length"].should be_instance_of String
headers["Content-Length"].to_i.should > 0
headers["Content-Length"].to_i.should < all_tags_length
body = res.body.to_s
/\.\./.should_not =~ body
/<pre>/.should_not =~ body
end
it "list pub tags only with PATH_INFO=/" do
gitpub = GitPub.new(@git_dir)
code, headers, res = gitpub.call({'PATH_INFO' => "/"})
all_tags_length = headers["Content-Length"].to_i
gitpub = GitPub.new(@git_dir, /\Av2\.6\.\d+\z/)
code, headers, res = gitpub.call({'PATH_INFO' => "/"})
code.should == 200
headers["Content-Type"].should == "text/html; charset=utf-8"
headers["Content-Length"].should be_instance_of String
headers["Content-Length"].to_i.should > 0
headers["Content-Length"].to_i.should < all_tags_length
body = res.body.to_s
/\.\./.should_not =~ body
/<pre>/.should_not =~ body
end
it "list pub tags with PATH_INFO=/invalid-tag/" do
gitpub = GitPub.new(@git_dir, /\Av2\.6\.\d+\z/)
code, headers, res0 = gitpub.call({'PATH_INFO' => nil})
code, headers, res1 = gitpub.call({'PATH_INFO' => "/invalid-tag/"})
code.should == 200
headers["Content-Type"].should == "text/html; charset=utf-8"
headers["Content-Length"].should be_instance_of String
headers["Content-Length"].to_i.should > 0
res0.body.should == res1.body
body = res1.body.to_s
/\.\./.should_not =~ body
/<pre>/.should_not =~ body
end
it "list no files with PATH_INFO=/v2.6.10/" do
gitpub = GitPub.new(@git_dir, /\Av2\.6\.\d+\z/)
temp_stderr = Tempfile.new("stderr")
orig_stderr = STDERR.dup
STDERR.reopen(temp_stderr)
code, headers, res = gitpub.call({'PATH_INFO' => "/v2.6.10/"})
STDERR.reopen(orig_stderr)
temp_stderr.rewind
error = temp_stderr.read
temp_stderr.close
error.should == "fatal: Not a valid object name v2.6.10:\n"
code.should == 200
headers["Content-Type"].should == "text/html; charset=utf-8"
headers["Content-Length"].should be_instance_of String
headers["Content-Length"].to_i.should > 0
res.body.to_s.scan(/<li>/).size.should == 1
body = res.body.to_s
/\.\./.should =~ body
/<pre>/.should_not =~ body
end
it "list files with PATH_INFO=/v2.6.11/" do
gitpub = GitPub.new(@git_dir, /\Av2\.6\.\d+\z/)
code, headers, res = gitpub.call({'PATH_INFO' => "/v2.6.11/"})
code.should == 200
headers["Content-Type"].should == "text/html; charset=utf-8"
headers["Content-Length"].should be_instance_of String
headers["Content-Length"].to_i.should > 0
body = res.body.to_s
body.scan(/<li>/).size.should > 1
/\.\./.should =~ body
/<pre>/.should_not =~ body
end
it "list files with PATH_INFO=/v2.6.11/" do
gitpub = GitPub.new(@git_dir, /\Av2\.6\.\d+\z/)
code, headers, res = gitpub.call({'PATH_INFO' => "/v2.6.11/"})
code.should == 200
headers["Content-Type"].should == "text/html; charset=utf-8"
headers["Content-Length"].should be_instance_of String
headers["Content-Length"].to_i.should > 0
body = res.body.to_s
body.scan(/<li>/).size.should > 1
/\.\./.should =~ body
/<pre>/.should_not =~ body
end
it "show file with PATH_INFO=/v2.6.11/COPYING" do
gitpub = GitPub.new(@git_dir, /\Av2\.6\.\d+\z/)
code, headers, res = gitpub.call({'PATH_INFO' => "/v2.6.11/COPYING"})
code.should == 200
headers["Content-Type"].should == "text/html; charset=utf-8"
headers["Content-Length"].should be_instance_of String
headers["Content-Length"].to_i.should > 0
body = res.body.to_s
/<pre>/.should =~ body
/GNU GENERAL PUBLIC LICENSE/.should =~ body
end
it "list files with PATH_INFO=/v2.6.11/Documentation/" do
gitpub = GitPub.new(@git_dir, /\Av2\.6\.\d+\z/)
code, headers, res = gitpub.call({'PATH_INFO' => "/v2.6.11/Documentation/"})
code.should == 200
headers["Content-Type"].should == "text/html; charset=utf-8"
headers["Content-Length"].should be_instance_of String
headers["Content-Length"].to_i.should > 0
body = res.body.to_s
body.scan(/<li>/).size.should > 1
/\.\./.should =~ body
/<pre>/.should_not =~ body
end
it "show file with PATH_INFO=/v2.6.11/Documentation/CodingStyle" do
gitpub = GitPub.new(@git_dir, /\Av2\.6\.\d+\z/)
code, headers, res = gitpub.call({'PATH_INFO' => "/v2.6.11/Documentation/CodingStyle"})
code.should == 200
headers["Content-Type"].should == "text/html; charset=utf-8"
headers["Content-Length"].should be_instance_of String
headers["Content-Length"].to_i.should > 0
body = res.body.to_s
/<pre>/.should =~ body
/Linux kernel coding style/.should =~ body
end
end