Showing 1 changed files with 69 additions and 0 deletions
+69
xt/smart_http.t
... ...
@@ -136,3 +136,72 @@ EOS
136 136
   $t->status_is(200);
137 137
   $t->content_type_is('application/x-git-receive-pack-result');
138 138
 }
139
+
140
+note 'Private repository and collaborator';
141
+{
142
+  unlink $db_file;
143
+  rmtree $rep_home;
144
+
145
+  my $app = Gitprep->new;
146
+  my $t = Test::Mojo->new($app);
147
+  $t->ua->max_redirects(3);
148
+
149
+  # Create admin user
150
+  $t->post_ok('/_start?op=create', form => {password => 'a', password2 => 'a'});
151
+  $t->content_like(qr/Login page/);
152
+
153
+  # Login success
154
+  $t->post_ok('/_login?op=login', form => {id => 'admin', password => 'a'});
155
+  $t->content_like(qr/Admin/);
156
+  
157
+  # Create user
158
+  $t->post_ok('/_admin/user/create?op=create', form => {id => 'kimoto', password => 'a', password2 => 'a'});
159
+  $t->content_like(qr/Success.*created/);
160
+  $t->post_ok('/_admin/user/create?op=create', form => {id => 'kimoto2', password => 'a', password2 => 'a'});
161
+  $t->content_like(qr/Success.*created/);
162
+
163
+  # Login as kimoto
164
+  $t->post_ok('/_login?op=login', form => {id => 'kimoto', password => 'a'});
165
+  $t->get_ok('/')->content_like(qr/kimoto/);
166
+
167
+  # Create repository
168
+  $t->post_ok('/_new?op=create', form => {project => 't1', description => 'Hello', readme => 1});
169
+  $t->content_like(qr/README/);
170
+  
171
+  # Check private repository
172
+  $t->post_ok("/kimoto/t1/settings?op=private", form => {private => 1});
173
+  $t->content_like(qr/Repository is private/);
174
+  
175
+  # Can access private repository from myself
176
+  $t->get_ok(
177
+    '/kimoto/t1.git/info/refs?service=git-receive-pack',
178
+    {
179
+      Authorization => 'Basic ' . encode_base64('kimoto:a')
180
+    }
181
+  );
182
+  $t->header_is("Content-Type", "application/x-git-receive-pack-advertisement");
183
+  $t->content_like(qr/^001f# service=git-receive-pack/);
184
+  
185
+  # Can't access private repository from others
186
+  $t->get_ok(
187
+    '/kimoto/t1.git/info/refs?service=git-receive-pack',
188
+    {
189
+      Authorization => 'Basic ' . encode_base64('kimoto2:a')
190
+    }
191
+  );
192
+  $t->status_is(401);
193
+  
194
+  # Add collaborator
195
+  $t->post_ok("/kimoto/t1/settings/collaboration?op=add", form => {collaborator => 'kimoto2'});
196
+  $t->content_like(qr/Collaborator kimoto2 is added/);
197
+  
198
+  # Can access private repository from collaborator
199
+  $t->get_ok(
200
+    '/kimoto/t1.git/info/refs?service=git-receive-pack',
201
+    {
202
+      Authorization => 'Basic ' . encode_base64('kimoto2:a')
203
+    }
204
+  );
205
+  $t->header_is("Content-Type", "application/x-git-receive-pack-advertisement");
206
+  $t->content_like(qr/^001f# service=git-receive-pack/);
207
+}