summaryrefslogtreecommitdiffstats
path: root/t/info-json.t
blob: 74fbdf4381d9fbc8aa3a5a9660872af80eea52b1 (plain)
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
#!/usr/bin/perl
use strict;
use warnings;

# this is hardcoded; change it if needed
use lib "src/lib";
use Gitolite::Test;
use JSON;

# the info command
# ----------------------------------------------------------------------

try 'plan 162';

try "## info";

confreset;confadd '
    @t1 = t1
    repo    @t1
        RW              =   u1
        R               =   u2
    repo    t2
        RW  =               u2
        R   =               u1
    repo    t3
        RW  =   u3
        R   =   u4

    repo foo/..*
        C   =   u1
        RW  =   CREATOR u3
';

try "ADMIN_PUSH info; !/FATAL/" or die text();
try "
                                        /Initialized.*empty.*t1.git/
                                        /Initialized.*empty.*t2.git/
                                        /Initialized.*empty.*t3.git/
";

my $href;   # semi-global (or at least file scoped lexical!)

# testing for info -json is a bit unusual.  The actual tests are done within
# this test script itself, and we send Tsh just enough for it to decide if
# it's 'ok' or 'not ok' and print that.

try "glt info u1 -json; ok";
$href = from_json(text());
try "## u1 test_gs";
test_gs('u1');
try "## u1";
perm('foo/..*', 'r w C');
perm('testing', 'R W c');
perm('t1', 'R W c');
perm('t2', 'R w c');
perm('t3', 'r w c');

try "## u2";
try "glt info u2 -json; ok";
$href = from_json(text());
perm('foo/..*', 'r w c');
perm('testing', 'R W c');
perm('t1', 'R w c');
perm('t2', 'R W c');
perm('t3', 'r w c');

try "## u3";
try "glt info u3 -json; ok";
$href = from_json(text());
perm('foo/..*', 'R W c');
perm('testing', 'R W c');
perm('t1', 'r w c');
perm('t2', 'r w c');
perm('t3', 'R W c');

try "## u4";
try "glt info u4 -json; ok";
$href = from_json(text());
perm('foo/..*', 'r w c');
perm('testing', 'R W c');
perm('t1', 'r w c');
perm('t2', 'r w c');
perm('t3', 'R w c');

try "## u5";
try "glt info u5 -json; ok";
$href = from_json(text());
perm('foo/..*', 'r w c');
perm('testing', 'R W c');
perm('t1', 'r w c');
perm('t2', 'r w c');
perm('t3', 'r w c');

try "## u6";
try "glt info u6 -json; ok";
$href = from_json(text());
perm('foo/..*', 'r w c');
perm('testing', 'R W c');
perm('t1', 'r w c');
perm('t2', 'r w c');
perm('t3', 'r w c');

try "## ls-remote foo/one";
try "glt ls-remote u1 file:///foo/one;   ok";

try "## u1";
try "glt info u1 -json; ok; !/creator..:/";
$href = from_json(text());
perm('foo/..*', 'r w C');
perm('foo/one', 'R W c');
test_creator('foo/one', 'u1', 'undef');

try "## u2";
try "glt info u2 -json; ok; !/creator..:/";
$href = from_json(text());
perm('foo/..*', 'r w c');
perm('foo/one', 'r w c');
test_creator('foo/one', 'u1', 'undef');

try "## u3";
try "glt info u3 -json; ok; !/creator..:/";
$href = from_json(text());
perm('foo/..*', 'R W c');
perm('foo/one', 'R W c');
test_creator('foo/one', 'u1', 'undef');

try("## with -lc now");

try "## u1";
try "glt info u1 -lc -json; ok";
$href = from_json(text());
perm('foo/..*', 'r w C');
perm('foo/one', 'R W c');
test_creator('foo/one', 'u1', 1);

try "## u2";
try "glt info u2 -lc -json; ok";
$href = from_json(text());
perm('foo/..*', 'r w c');
perm('foo/one', 'r w c');
test_creator('foo/one', 'u1', 'undef');

try "## u3";
try "glt info u3 -lc -json; ok";
$href = from_json(text());
perm('foo/..*', 'R W c');
perm('foo/one', 'R W c');
test_creator('foo/one', 'u1', 1);

# ----------------------------------------------------------------------

# test perms given repo and expected perms.  (lowercase r/w/c means NOT
# expected, uppercase means expected)
sub perm {
    my ($repo, $aa) = @_;
    for my $aa1 (split ' ', $aa) {
        my $exp = 1;
        if ($aa1 =~ /[a-z]/) {
            $exp = 'undef';     # we can't use 0, though I'd like to
            $aa1 = uc($aa1);
        }
        my $perm = $href->{repos}{$repo}{perms}{$aa1} || 'undef';
        try 'perl $_ = "' . $perm  . '"; /' . $exp . '/';
    }
}

# test versions in greeting string
sub test_gs {
    my $glu = shift;
    my $res = ( $href->{GL_USER} eq $glu ? 1 : 'undef' );
    try 'perl $_ = "' . $res  . '"; /1/';
    $res = ( $href->{gitolite_version} =~ /^v3.[5-9]/ ? 1 : 'undef' );
    try 'perl $_ = "' . $res  . '"; /1/';
    $res = ( $href->{git_version} =~ /^1.[6-9]|^2./ ? 1 : 'undef' );
    try 'perl $_ = "' . $res  . '"; /1/';
}

# test creator
sub test_creator {
    my ($r, $c, $exp) = @_;
    my $res = ( ($href->{repos}{$r}{creator} || '') eq $c ? 1 : 'undef' );
    try 'perl $_ = "' . $res  . '"; /' . $exp . '/';
}