File Coverage: t/app.t

# File Coverage

File: | t/app.t
Coverage: | 100.0%

line | stmt | bran | cond | sub | pod | time | code
--- | --- | --- | --- | --- | --- | --- | ---
1 |  |  |  |  |  |  | #!/usr/bin/env perl
2 | 1 1 |  |  | 1 |  | 2445 3 | use v5.24;
3 |
4 | 1 1 1 |  |  | 1 |  | 474 106948 8 | use Test2::V0;
5 | 1 1 1 |  |  | 1 |  | 3203 12940 2 | use Test::Exception;
6 |
7 | 1 |  |  | 1 |  | 127 | BEGIN { plan 59; }
8 |
9 | 1 1 1 |  |  | 1 |  | 1942 6710 50 | use Path::Tiny;
10 |
11 | 1 1 1 1 1 1 1 |  |  | 1 1 |  | 431 4877 5 349 3 1 10 | use ok('Yukki');
12 | 1 1 1 1 1 1 1 |  |  | 1 1 |  | 308 1 5 559 2 2 11 | use ok('Yukki::User');
13 |
14 | 1 |  |  |  |  | 100830 | my $app = Yukki->new;
15 | 1 |  |  |  |  | 1437 | isa_ok($app, 'Yukki');
16 | 1 |  |  |  |  | 198 | DOES_ok($app, 'Yukki::Role::App');
17 |
18 | 1 1 |  |  | 1 |  | 135 46 | throws_ok { $app->config_file } qr/make YUKKI_CONFIG point/, 'missing config location complains';
19 |
20 | 1 |  |  |  |  | 272 | $ENV{YUKKI_CONFIG} = 't/test-site/etc/bad-yukki.conf';
21 |
22 | 1 1 |  |  | 1 |  | 6 34 | throws_ok { $app->config_file } qr/no configuration found/i, 'missing config file complains';
23 |
24 | 1 |  |  |  |  | 262 | delete $ENV{YUKKI_CONFIG};
25 | 1 |  |  |  |  | 16 | chdir 't/test-site';
26 |
27 | 1 |  |  |  |  | 16 | is($app->config_file, path('.', 'etc', 'yukki.conf'), 'config set by CWD works');
28 |
29 | 1 |  |  |  |  | 1384 | delete $app->{config_file};
30 | 1 |  |  |  |  | 5 | chdir '../..';
31 | 1 |  |  |  |  | 4 | $ENV{YUKKI_CONFIG} = 't/test-site/etc/yukki.conf';
32 |
33 | 1 |  |  |  |  | 16 | is($app->config_file, path('.', 't', 'test-site', 'etc', 'yukki.conf'), 'config set by env works');
34 |
35 | 1 1 |  |  | 1 |  | 602 22 | throws_ok { $app->view } qr/unimplemented/i, 'view is not implemented';
36 | 1 1 |  |  | 1 |  | 238 21 | throws_ok { $app->controller } qr/unimplemented/i, 'controller is not implemented';
37 |
38 | 1 |  |  |  |  | 239 | my $model = $app->model('User');
39 | 1 |  |  |  |  | 2268 | isa_ok($model, 'Yukki::Model::User');
40 |
41 | 1 |  |  |  |  | 178 | my $dir = $app->locate_dir('repository_path', 'main.git');
42 | 1 |  |  |  |  | 5 | isa_ok($dir, 'Path::Tiny');
43 | 1 |  |  |  |  | 192 | is("$dir", "/tmp/repositories/main.git", 'locate_dir makes the right dir');
44 |
45 | 1 |  |  |  |  | 319 | my $file = $app->locate('user_path', 'demo');
46 | 1 |  |  |  |  | 4 | isa_ok($file, 'Path::Tiny');
47 | 1 |  |  |  |  | 140 | is("$file", "/tmp/var/db/users/demo", 'locate makes the right file');
48 |
49 | 1 |  |  |  |  | 277 | my $group1_user = Yukki::User->new(login_name => 'abc', password => 'a', name => 'a', email => 'a@example.com', groups => [ 'group1' ]);
50 | 1 |  |  |  |  | 83 | my $group4_user = Yukki::User->new(login_name => 'bbc', password => 'a', name => 'b', email => 'b@example.com', groups => [ 'group4' ]);
51 |
52 | 1 |  |  |  |  | 41 | is($app->check_access( user => undef, repository => 'noaccess', needs => 'none' ), 1);
53 | 1 |  |  |  |  | 551 | is($app->check_access( user => undef, repository => 'noaccess', needs => 'read' ), '');
54 | 1 |  |  |  |  | 305 | is($app->check_access( user => undef, repository => 'noaccess', needs => 'write' ), '');
55 | 1 |  |  |  |  | 307 | is($app->check_access( user => $group1_user, repository => 'noaccess', needs => 'none' ), 1);
56 | 1 |  |  |  |  | 292 | is($app->check_access( user => $group1_user, repository => 'noaccess', needs => 'read' ), '');
57 | 1 |  |  |  |  | 318 | is($app->check_access( user => $group1_user, repository => 'noaccess', needs => 'write' ), '');
58 |
59 | 1 |  |  |  |  | 277 | is($app->check_access( user => undef, repository => 'anonymousread', needs => 'none' ), 1);
60 | 1 |  |  |  |  | 288 | is($app->check_access( user => undef, repository => 'anonymousread', needs => 'read' ), 1);
61 | 1 |  |  |  |  | 354 | is($app->check_access( user => undef, repository => 'anonymousread', needs => 'write' ), '');
62 | 1 |  |  |  |  | 310 | is($app->check_access( user => $group1_user, repository => 'anonymousread', needs => 'none' ), 1);
63 | 1 |  |  |  |  | 298 | is($app->check_access( user => $group1_user, repository => 'anonymousread', needs => 'read' ), 1);
64 | 1 |  |  |  |  | 280 | is($app->check_access( user => $group1_user, repository => 'anonymousread', needs => 'write' ), '');
65 |
66 | 1 |  |  |  |  | 335 | is($app->check_access( user => undef, repository => 'anonymouswrite', needs => 'none' ), 1);
67 | 1 |  |  |  |  | 304 | is($app->check_access( user => undef, repository => 'anonymouswrite', needs => 'read' ), 1);
68 | 1 |  |  |  |  | 279 | is($app->check_access( user => undef, repository => 'anonymouswrite', needs => 'write' ), 1);
69 | 1 |  |  |  |  | 280 | is($app->check_access( user => $group1_user, repository => 'anonymouswrite', needs => 'none' ), 1);
70 | 1 |  |  |  |  | 311 | is($app->check_access( user => $group1_user, repository => 'anonymouswrite', needs => 'read' ), 1);
71 | 1 |  |  |  |  | 397 | is($app->check_access( user => $group1_user, repository => 'anonymouswrite', needs => 'write' ), 1);
72 |
73 | 1 |  |  |  |  | 279 | is($app->check_access( user => undef, repository => 'loggedread', needs => 'none' ), 1);
74 | 1 |  |  |  |  | 366 | is($app->check_access( user => undef, repository => 'loggedread', needs => 'read' ), '');
75 | 1 |  |  |  |  | 299 | is($app->check_access( user => undef, repository => 'loggedread', needs => 'write' ), '');
76 | 1 |  |  |  |  | 303 | is($app->check_access( user => $group1_user, repository => 'loggedread', needs => 'none' ), 1);
77 | 1 |  |  |  |  | 271 | is($app->check_access( user => $group1_user, repository => 'loggedread', needs => 'read' ), 1);
78 | 1 |  |  |  |  | 523 | is($app->check_access( user => $group1_user, repository => 'loggedread', needs => 'write' ), '');
79 |
80 | 1 |  |  |  |  | 297 | is($app->check_access( user => undef, repository => 'loggedwrite', needs => 'none' ), 1);
81 | 1 |  |  |  |  | 278 | is($app->check_access( user => undef, repository => 'loggedwrite', needs => 'read' ), '');
82 | 1 |  |  |  |  | 319 | is($app->check_access( user => undef, repository => 'loggedwrite', needs => 'write' ), '');
83 | 1 |  |  |  |  | 308 | is($app->check_access( user => $group1_user, repository => 'loggedwrite', needs => 'none' ), 1);
84 | 1 |  |  |  |  | 283 | is($app->check_access( user => $group1_user, repository => 'loggedwrite', needs => 'read' ), 1);
85 | 1 |  |  |  |  | 285 | is($app->check_access( user => $group1_user, repository => 'loggedwrite', needs => 'write' ), 1);
86 |
87 | 1 |  |  |  |  | 381 | is($app->check_access( user => undef, repository => 'groupaccess', needs => 'none' ), 1);
88 | 1 |  |  |  |  | 306 | is($app->check_access( user => undef, repository => 'groupaccess', needs => 'read' ), '');
89 | 1 |  |  |  |  | 283 | is($app->check_access( user => undef, repository => 'groupaccess', needs => 'write' ), '');
90 | 1 |  |  |  |  | 240 | is($app->check_access( user => $group1_user, repository => 'groupaccess', needs => 'none' ), 1);
91 | 1 |  |  |  |  | 357 | is($app->check_access( user => $group1_user, repository => 'groupaccess', needs => 'read' ), 1);
92 | 1 |  |  |  |  | 303 | is($app->check_access( user => $group1_user, repository => 'groupaccess', needs => 'write' ), '');
93 |
94 | 1 |  |  |  |  | 290 | is($app->check_access( user => undef, repository => 'groupaccess', needs => 'none' ), 1);
95 | 1 |  |  |  |  | 334 | is($app->check_access( user => undef, repository => 'groupaccess', needs => 'read' ), '');
96 | 1 |  |  |  |  | 322 | is($app->check_access( user => undef, repository => 'groupaccess', needs => 'write' ), '');
97 | 1 |  |  |  |  | 425 | is($app->check_access( user => $group4_user, repository => 'groupaccess', needs => 'none' ), 1);
98 | 1 |  |  |  |  | 280 | is($app->check_access( user => $group4_user, repository => 'groupaccess', needs => 'read' ), 1);
99 | 1 |  |  |  |  | 302 | is($app->check_access( user => $group4_user, repository => 'groupaccess', needs => 'write' ), 1);
100 |
101 | 1 |  |  |  |  | 278 | isa_ok($app->hasher, 'Crypt::SaltedHash');
102 | 1 |  |  |  |  | 158 | is($app->hasher->{algorithm}, $app->settings->digest, 'hasher is using the proper algorithm');