forked from yuki-kimoto/gitprep
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmart_http.t
212 lines (173 loc) · 6.45 KB
/
smart_http.t
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
209
210
211
212
use Test::More 'no_plan';
use strict;
use warnings;
use FindBin;
use utf8;
use lib "$FindBin::Bin/../lib";
use lib "$FindBin::Bin/../extlib/lib/perl5";
use File::Path 'rmtree';
use Encode qw/encode decode/;
use MIME::Base64 'encode_base64';
use Test::Mojo;
# Data directory
my $data_dir = $ENV{GITPREP_DATA_DIR} = "$FindBin::Bin/smart_http";
# Test DB
my $db_file = "$data_dir/gitprep.db";
# Test Repository home
my $rep_home = "$data_dir/rep";
$ENV{GITPREP_NO_MYCONFIG} = 1;
use Gitprep;
note 'Smart HTTP';
{
unlink $db_file;
rmtree $rep_home;
system("$FindBin::Bin/../setup_database", $db_file) == 0
or die "Can't setup $db_file";
my $app = Mojo::Server->new->load_app("$FindBin::Bin/../script/gitprep");
my $t = Test::Mojo->new($app);
$t->ua->max_redirects(3);
# Create admin user
$t->post_ok('/_start?op=create', form => {password => 'a', password2 => 'a'});
$t->content_like(qr/Login page/);
# Login success
$t->post_ok('/_login?op=login', form => {id => 'admin', password => 'a'});
$t->content_like(qr/Admin/);
# Create user
$t->post_ok('/_admin/user/create?op=create', form => {id => 'kimoto', email => '[email protected]', password => 'a', password2 => 'a'});
$t->content_like(qr/Success.*created/);
# Login as kimoto
$t->post_ok('/_login?op=login', form => {id => 'kimoto', password => 'a'});
$t->get_ok('/')->content_like(qr/kimoto/);
# Create repository
$t->post_ok('/_new?op=create', form => {project => 't1', description => 'Hello', readme => 1});
$t->content_like(qr/README/);
# info/refs
$t->get_ok("/kimoto/t1.git/info/refs");
$t->status_is(200);
$t->content_type_is('text/plain; charset=UTF-8');
my $object_id1 = substr($t->tx->res->body, 0, 2);
my $object_id2 = substr($t->tx->res->body, 2, 38);
# Loose object
$t->get_ok("/kimoto/t1.git/objects/$object_id1/$object_id2");
$t->status_is(200);
$t->content_type_is('application/x-git-loose-object');
# /info/pack
$t->get_ok('/kimoto/t1.git/objects/info/packs');
$t->status_is(200);
$t->content_type_is('text/plain; charset=UTF-8');
# /HEAD
$t->get_ok('/kimoto/t1.git/HEAD');
$t->status_is(200);
$t->content_type_is('text/plain');
$t->content_like(qr#ref: refs/heads/master#);
# /info/refs upload-pack request
$t->get_ok('/kimoto/t1.git/info/refs?service=git-upload-pack');
$t->status_is(200);
$t->header_is('Content-Type', 'application/x-git-upload-pack-advertisement');
$t->content_like(qr/^001e# service=git-upload-pack/);
$t->content_like(qr/multi_ack_detailed/);
# /info/refs recieve-pack request(Basic authentication)
$t->get_ok('/kimoto/t1.git/info/refs?service=git-receive-pack');
$t->status_is(401);
# /info/refs recieve-pack request
$t->get_ok(
'/kimoto/t1.git/info/refs?service=git-receive-pack',
{
Authorization => 'Basic ' . encode_base64('kimoto:a')
}
);
$t->header_is("Content-Type", "application/x-git-receive-pack-advertisement");
$t->content_like(qr/^001f# service=git-receive-pack/);
$t->content_like(qr/report-status/);
$t->content_like(qr/delete-refs/);
$t->content_like(qr/ofs-delta/);
# /git-receive-pack
$t->post_ok(
'/kimoto/t1.git/git-receive-pack',
{
'Content-Type' => 'application/x-git-receive-pack-request',
Content => '00810000000000000000000000000000000000000000 6410316f2ed260666a8a6b9a223ad3c95d7abaed refs/tags/v1.0. report-status side-band-64k0000'
}
);
$t->status_is(200);
$t->content_type_is('application/x-git-receive-pack-result');
# /git-upload-pack
{
my $content = <<EOS;
006fwant 6410316f2ed260666a8a6b9a223ad3c95d7abaed multi_ack_detailed no-done side-band-64k thin-pack ofs-delta
0032want 6410316f2ed260666a8a6b9a223ad3c95d7abaed
00000009done
EOS
$t->post_ok(
'/kimoto/t1.git/git-upload-pack',
{
'Content-Type' => 'application/x-git-upload-pack-request',
'Content-Length' => 174,
'Content' => $content
}
);
$t->status_is(200);
$t->content_type_is('application/x-git-upload-pack-result');
}
}
note 'Private repository and collaborator';
{
unlink $db_file;
rmtree $rep_home;
system("$FindBin::Bin/../setup_database", $db_file) == 0
or die "Can't setup $db_file";
my $app = Mojo::Server->new->load_app("$FindBin::Bin/../script/gitprep");
my $t = Test::Mojo->new($app);
$t->ua->max_redirects(3);
# Create admin user
$t->post_ok('/_start?op=create', form => {password => 'a', password2 => 'a'});
$t->content_like(qr/Login page/);
# Login success
$t->post_ok('/_login?op=login', form => {id => 'admin', password => 'a'});
$t->content_like(qr/Admin/);
# Create user
$t->post_ok('/_admin/user/create?op=create', form => {id => 'kimoto', email => '[email protected]', password => 'a', password2 => 'a'});
$t->content_like(qr/Success.*created/);
$t->post_ok('/_admin/user/create?op=create', form => {id => 'kimoto2', email => '[email protected]', password => 'a', password2 => 'a'});
$t->content_like(qr/Success.*created/);
# Login as kimoto
$t->post_ok('/_login?op=login', form => {id => 'kimoto', password => 'a'});
$t->get_ok('/')->content_like(qr/kimoto/);
# Create repository
$t->post_ok('/_new?op=create', form => {project => 't1', description => 'Hello', readme => 1});
$t->content_like(qr/README/);
# Check private repository
$t->post_ok("/kimoto/t1/settings?op=save-settings", form => {private => 1});
$t->content_like(qr/Settings is saved/);
# Can access private repository from myself
$t->get_ok(
'/kimoto/t1.git/info/refs?service=git-receive-pack',
{
Authorization => 'Basic ' . encode_base64('kimoto:a')
}
);
$t->header_is("Content-Type", "application/x-git-receive-pack-advertisement");
$t->content_like(qr/^001f# service=git-receive-pack/);
# Can't access private repository from others
$t->get_ok(
'/kimoto/t1.git/info/refs?service=git-receive-pack',
{
Authorization => 'Basic ' . encode_base64('kimoto2:a')
}
);
$t->status_is(401);
# Add collaborator
$t->post_ok("/kimoto/t1/settings/collaboration?op=add", form => {collaborator => 'kimoto2'});
$t->content_like(qr/Collaborator kimoto2 is added/);
# Can access private repository from collaborator
$t->get_ok(
'/kimoto/t1.git/info/refs?service=git-receive-pack',
{
Authorization => 'Basic ' . encode_base64('kimoto2:a')
}
);
$t->header_is("Content-Type", "application/x-git-receive-pack-advertisement");
$t->content_like(qr/^001f# service=git-receive-pack/);
}
# Fix test error(why?)
__END__