gitprep / xt / smart_http.t /
Newer Older
212 lines | 6.606kb
add smart http test file
Yuki Kimoto authored on 2013-10-07
1
use Test::More 'no_plan';
2
use strict;
3
use warnings;
4

            
5
use FindBin;
6
use utf8;
7
use lib "$FindBin::Bin/../lib";
8
use lib "$FindBin::Bin/../extlib/lib/perl5";
9
use File::Path 'rmtree';
10
use Encode qw/encode decode/;
add receive pack test
Yuki Kimoto authored on 2013-10-08
11
use MIME::Base64 'encode_base64';
add smart http test file
Yuki Kimoto authored on 2013-10-07
12

            
13
use Test::Mojo;
14

            
cleanup tests
Yuki Kimoto authored on 2016-04-14
15
# Data directory
fix tests
Yuki Kimoto authored on 2016-04-14
16
my $data_dir =  $ENV{GITPREP_DATA_DIR} = "$FindBin::Bin/smart_http";
cleanup tests
Yuki Kimoto authored on 2016-04-14
17

            
add smart http test file
Yuki Kimoto authored on 2013-10-07
18
# Test DB
cleanup tests
Yuki Kimoto authored on 2016-04-16
19
my $db_file = "$data_dir/gitprep.db";
add smart http test file
Yuki Kimoto authored on 2013-10-07
20

            
21
# Test Repository home
cleanup tests
Yuki Kimoto authored on 2016-04-16
22
my $rep_home = "$data_dir/rep";
add smart http test file
Yuki Kimoto authored on 2013-10-07
23

            
24
$ENV{GITPREP_NO_MYCONFIG} = 1;
25

            
26
use Gitprep;
27

            
28
note 'Smart HTTP';
29
{
30
  unlink $db_file;
add dump http info/refs test
Yuki Kimoto authored on 2013-10-07
31
  rmtree $rep_home;
add smart http test file
Yuki Kimoto authored on 2013-10-07
32

            
fix some tests
Yuki Kimoto authored on 2016-04-21
33
  system("$FindBin::Bin/../setup_database", $db_file) == 0
34
    or die "Can't setup $db_file";
35
  my $app = Mojo::Server->new->load_app("$FindBin::Bin/../script/gitprep");
cleanup tests
Yuki Kimoto authored on 2016-04-14
36

            
add smart http test file
Yuki Kimoto authored on 2013-10-07
37
  my $t = Test::Mojo->new($app);
38
  $t->ua->max_redirects(3);
39

            
40
  # Create admin user
41
  $t->post_ok('/_start?op=create', form => {password => 'a', password2 => 'a'});
42
  $t->content_like(qr/Login page/);
43

            
44
  # Login success
45
  $t->post_ok('/_login?op=login', form => {id => 'admin', password => 'a'});
46
  $t->content_like(qr/Admin/);
47
  
48
  # Create user
fix user create and update b...
Yuki Kimoto authored on 2016-04-21
49
  $t->post_ok('/_admin/user/create?op=create', form => {id => 'kimoto', email => 'kimoto@foo.com', password => 'a', password2 => 'a'});
add smart http test file
Yuki Kimoto authored on 2013-10-07
50
  $t->content_like(qr/Success.*created/);
add dump http info/refs test
Yuki Kimoto authored on 2013-10-07
51

            
52
  # Login as kimoto
53
  $t->post_ok('/_login?op=login', form => {id => 'kimoto', password => 'a'});
54
  $t->get_ok('/')->content_like(qr/kimoto/);
55

            
56
  # Create repository
57
  $t->post_ok('/_new?op=create', form => {project => 't1', description => 'Hello', readme => 1});
58
  $t->content_like(qr/README/);
59
  
60
  # info/refs
61
  $t->get_ok("/kimoto/t1.git/info/refs");
62
  $t->status_is(200);
63
  $t->content_type_is('text/plain; charset=UTF-8');
fix and add loose object tes...
Yuki Kimoto authored on 2013-10-08
64
  
65
  my $object_id1 = substr($t->tx->res->body, 0, 2);
66
  my $object_id2 = substr($t->tx->res->body, 2, 38);
67
  
add dump http info/refs test
Yuki Kimoto authored on 2013-10-07
68
  # Loose object
fix and add loose object tes...
Yuki Kimoto authored on 2013-10-08
69
  $t->get_ok("/kimoto/t1.git/objects/$object_id1/$object_id2");
add dump http info/refs test
Yuki Kimoto authored on 2013-10-07
70
  $t->status_is(200);
71
  $t->content_type_is('application/x-git-loose-object');
72

            
add test HEAD
Yuki Kimoto authored on 2013-10-08
73
  # /info/pack
add receive pack test
Yuki Kimoto authored on 2013-10-08
74
  $t->get_ok('/kimoto/t1.git/objects/info/packs');
add test HEAD
Yuki Kimoto authored on 2013-10-08
75
  $t->status_is(200);
76
  $t->content_type_is('text/plain; charset=UTF-8');
fix and add loose object tes...
Yuki Kimoto authored on 2013-10-08
77

            
add test HEAD
Yuki Kimoto authored on 2013-10-08
78
  # /HEAD
add receive pack test
Yuki Kimoto authored on 2013-10-08
79
  $t->get_ok('/kimoto/t1.git/HEAD');
add test HEAD
Yuki Kimoto authored on 2013-10-08
80
  $t->status_is(200);
81
  $t->content_type_is('text/plain');
82
  $t->content_like(qr#ref: refs/heads/master#);
83
  
add receive pack test
Yuki Kimoto authored on 2013-10-08
84
  # /info/refs upload-pack request
85
  $t->get_ok('/kimoto/t1.git/info/refs?service=git-upload-pack');
86
  $t->status_is(200);
87
  $t->header_is('Content-Type', 'application/x-git-upload-pack-advertisement');
88
  $t->content_like(qr/^001e# service=git-upload-pack/);
89
  $t->content_like(qr/multi_ack_detailed/);
90
  
91
  # /info/refs recieve-pack request(Basic authentication)
92
  $t->get_ok('/kimoto/t1.git/info/refs?service=git-receive-pack');
93
  $t->status_is(401);
add test HEAD
Yuki Kimoto authored on 2013-10-08
94
  
add receive pack test
Yuki Kimoto authored on 2013-10-08
95
  # /info/refs recieve-pack request
96
  $t->get_ok(
97
    '/kimoto/t1.git/info/refs?service=git-receive-pack',
98
    {
99
      Authorization => 'Basic ' . encode_base64('kimoto:a')
100
    }
101
  );
102
  $t->header_is("Content-Type", "application/x-git-receive-pack-advertisement");
103
  $t->content_like(qr/^001f# service=git-receive-pack/);
104
  $t->content_like(qr/report-status/);
105
  $t->content_like(qr/delete-refs/);
106
  $t->content_like(qr/ofs-delta/);
add test /git-recieve-pack
Yuki Kimoto authored on 2013-10-08
107
  
108
  # /git-receive-pack
109
  $t->post_ok(
110
    '/kimoto/t1.git/git-receive-pack',
111
    {
112
      'Content-Type' => 'application/x-git-receive-pack-request',
113
      Content => '00810000000000000000000000000000000000000000 6410316f2ed260666a8a6b9a223ad3c95d7abaed refs/tags/v1.0. report-status side-band-64k0000'
114
    }
115
  );
116
  $t->status_is(200);
117
  $t->content_type_is('application/x-git-receive-pack-result');
fix smart_http bug
Yuki Kimoto authored on 2016-03-28
118

            
119
  # /git-upload-pack
120
  {
121
    my $content = <<EOS;
122
006fwant 6410316f2ed260666a8a6b9a223ad3c95d7abaed multi_ack_detailed no-done side-band-64k thin-pack ofs-delta
123
0032want 6410316f2ed260666a8a6b9a223ad3c95d7abaed
124
00000009done
125
EOS
126
    $t->post_ok(
127
      '/kimoto/t1.git/git-upload-pack',
128
      {
129
        'Content-Type' => 'application/x-git-upload-pack-request',
130
        'Content-Length' => 174,
131
        'Content'        => $content
132
      }
133
    );
134
    $t->status_is(200);
135
    $t->content_type_is('application/x-git-upload-pack-result');
136
  }
add test /git-recieve-pack
Yuki Kimoto authored on 2013-10-08
137
}
add smart http private and c...
Yuki Kimoto authored on 2013-11-18
138

            
139
note 'Private repository and collaborator';
140
{
141
  unlink $db_file;
142
  rmtree $rep_home;
143

            
fix some tests
Yuki Kimoto authored on 2016-04-21
144
  system("$FindBin::Bin/../setup_database", $db_file) == 0
145
    or die "Can't setup $db_file";
146
  my $app = Mojo::Server->new->load_app("$FindBin::Bin/../script/gitprep");
cleanup tests
Yuki Kimoto authored on 2016-04-14
147

            
add smart http private and c...
Yuki Kimoto authored on 2013-11-18
148
  my $t = Test::Mojo->new($app);
149
  $t->ua->max_redirects(3);
150

            
151
  # Create admin user
152
  $t->post_ok('/_start?op=create', form => {password => 'a', password2 => 'a'});
153
  $t->content_like(qr/Login page/);
154

            
155
  # Login success
156
  $t->post_ok('/_login?op=login', form => {id => 'admin', password => 'a'});
157
  $t->content_like(qr/Admin/);
158
  
159
  # Create user
fix user create and update b...
Yuki Kimoto authored on 2016-04-21
160
  $t->post_ok('/_admin/user/create?op=create', form => {id => 'kimoto', email => 'kimoto@foo.com', password => 'a', password2 => 'a'});
add smart http private and c...
Yuki Kimoto authored on 2013-11-18
161
  $t->content_like(qr/Success.*created/);
fix user create and update b...
Yuki Kimoto authored on 2016-04-21
162
  $t->post_ok('/_admin/user/create?op=create', form => {id => 'kimoto2', email => 'kimoto2@foo.com', password => 'a', password2 => 'a'});
add smart http private and c...
Yuki Kimoto authored on 2013-11-18
163
  $t->content_like(qr/Success.*created/);
164

            
165
  # Login as kimoto
166
  $t->post_ok('/_login?op=login', form => {id => 'kimoto', password => 'a'});
167
  $t->get_ok('/')->content_like(qr/kimoto/);
168

            
169
  # Create repository
170
  $t->post_ok('/_new?op=create', form => {project => 't1', description => 'Hello', readme => 1});
171
  $t->content_like(qr/README/);
172
  
173
  # Check private repository
cleanup settings page logic
Yuki Kimoto authored on 2016-03-31
174
  $t->post_ok("/kimoto/t1/settings?op=save-settings", form => {private => 1});
175
  $t->content_like(qr/Settings is saved/);
add smart http private and c...
Yuki Kimoto authored on 2013-11-18
176
  
177
  # Can access private repository from myself
178
  $t->get_ok(
179
    '/kimoto/t1.git/info/refs?service=git-receive-pack',
180
    {
181
      Authorization => 'Basic ' . encode_base64('kimoto:a')
182
    }
183
  );
184
  $t->header_is("Content-Type", "application/x-git-receive-pack-advertisement");
185
  $t->content_like(qr/^001f# service=git-receive-pack/);
186
  
187
  # Can't access private repository from others
188
  $t->get_ok(
189
    '/kimoto/t1.git/info/refs?service=git-receive-pack',
190
    {
191
      Authorization => 'Basic ' . encode_base64('kimoto2:a')
192
    }
193
  );
194
  $t->status_is(401);
fix smart_http bug
Yuki Kimoto authored on 2016-03-28
195

            
add smart http private and c...
Yuki Kimoto authored on 2013-11-18
196
  # Add collaborator
197
  $t->post_ok("/kimoto/t1/settings/collaboration?op=add", form => {collaborator => 'kimoto2'});
198
  $t->content_like(qr/Collaborator kimoto2 is added/);
199
  
200
  # Can access private repository from collaborator
201
  $t->get_ok(
202
    '/kimoto/t1.git/info/refs?service=git-receive-pack',
203
    {
204
      Authorization => 'Basic ' . encode_base64('kimoto2:a')
205
    }
206
  );
207
  $t->header_is("Content-Type", "application/x-git-receive-pack-advertisement");
208
  $t->content_like(qr/^001f# service=git-receive-pack/);
209
}
fix smart_http bug
Yuki Kimoto authored on 2016-03-28
210

            
211
# Fix test error(why?)
212
__END__