gitprep / xt / smart_http.t /
Newer Older
203 lines | 6.212kb
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

            
15
# Test DB
16
my $db_file = $ENV{GITPREP_DB_FILE} = "$FindBin::Bin/smart_http.db";
17

            
18
# Test Repository home
19
my $rep_home = $ENV{GITPREP_REP_HOME} = "$FindBin::Bin/smart_http";
20

            
21
$ENV{GITPREP_NO_MYCONFIG} = 1;
22

            
23
use Gitprep;
24

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

            
30
  my $app = Gitprep->new;
31
  my $t = Test::Mojo->new($app);
32
  $t->ua->max_redirects(3);
33

            
34
  # Create admin user
35
  $t->post_ok('/_start?op=create', form => {password => 'a', password2 => 'a'});
36
  $t->content_like(qr/Login page/);
37

            
38
  # Login success
39
  $t->post_ok('/_login?op=login', form => {id => 'admin', password => 'a'});
40
  $t->content_like(qr/Admin/);
41
  
42
  # Create user
43
  $t->post_ok('/_admin/user/create?op=create', form => {id => 'kimoto', password => 'a', password2 => 'a'});
44
  $t->content_like(qr/Success.*created/);
add dump http info/refs test
Yuki Kimoto authored on 2013-10-07
45

            
46
  # Login as kimoto
47
  $t->post_ok('/_login?op=login', form => {id => 'kimoto', password => 'a'});
48
  $t->get_ok('/')->content_like(qr/kimoto/);
49

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

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

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

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

            
133
note 'Private repository and collaborator';
134
{
135
  unlink $db_file;
136
  rmtree $rep_home;
137

            
138
  my $app = Gitprep->new;
139
  my $t = Test::Mojo->new($app);
140
  $t->ua->max_redirects(3);
141

            
142
  # Create admin user
143
  $t->post_ok('/_start?op=create', form => {password => 'a', password2 => 'a'});
144
  $t->content_like(qr/Login page/);
145

            
146
  # Login success
147
  $t->post_ok('/_login?op=login', form => {id => 'admin', password => 'a'});
148
  $t->content_like(qr/Admin/);
149
  
150
  # Create user
151
  $t->post_ok('/_admin/user/create?op=create', form => {id => 'kimoto', password => 'a', password2 => 'a'});
152
  $t->content_like(qr/Success.*created/);
153
  $t->post_ok('/_admin/user/create?op=create', form => {id => 'kimoto2', password => 'a', password2 => 'a'});
154
  $t->content_like(qr/Success.*created/);
155

            
156
  # Login as kimoto
157
  $t->post_ok('/_login?op=login', form => {id => 'kimoto', password => 'a'});
158
  $t->get_ok('/')->content_like(qr/kimoto/);
159

            
160
  # Create repository
161
  $t->post_ok('/_new?op=create', form => {project => 't1', description => 'Hello', readme => 1});
162
  $t->content_like(qr/README/);
163
  
164
  # Check private repository
165
  $t->post_ok("/kimoto/t1/settings?op=private", form => {private => 1});
166
  $t->content_like(qr/Repository is private/);
167
  
168
  # Can access private repository from myself
169
  $t->get_ok(
170
    '/kimoto/t1.git/info/refs?service=git-receive-pack',
171
    {
172
      Authorization => 'Basic ' . encode_base64('kimoto:a')
173
    }
174
  );
175
  $t->header_is("Content-Type", "application/x-git-receive-pack-advertisement");
176
  $t->content_like(qr/^001f# service=git-receive-pack/);
177
  
178
  # Can't access private repository from others
179
  $t->get_ok(
180
    '/kimoto/t1.git/info/refs?service=git-receive-pack',
181
    {
182
      Authorization => 'Basic ' . encode_base64('kimoto2:a')
183
    }
184
  );
185
  $t->status_is(401);
fix smart_http bug
Yuki Kimoto authored on 2016-03-28
186

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

            
202
# Fix test error(why?)
203
__END__