fix 'C' and 'M' tests in 'gitolite access'...
[gitolite.git] / t / ssh-authkeys.t
blob46b941348f791744a43b27c566dddeca5b356fdb
1 #!/usr/bin/perl
2 use strict;
3 use warnings;
5 # this is hardcoded; change it if needed
6 use lib "src/lib";
7 use Gitolite::Test;
9 # testing the (separate) authkeys handler
10 # ----------------------------------------------------------------------
12 $ENV{GL_BINDIR} = "$ENV{PWD}/src";
14 my $ak = "$ENV{HOME}/.ssh/authorized_keys";
15 mkdir("$ENV{HOME}/.ssh", 0700) if not -d "$ENV{HOME}/.ssh";
16 my $kd = `gitolite query-rc -n GL_ADMIN_BASE` . "/keydir";
18 try "plan 49";
20 my $pgm = "gitolite ../triggers/post-compile/ssh-authkeys";
22 try "
23 # prep
24 rm -rf $ak; ok
26 $pgm; ok
27 mkdir $kd; ok
28 cd $kd; ok
29 $pgm; ok; /authorized_keys missing/
30 /creating/
31 wc < $ak; ok; /2 *6 *32/
32 # some gl keys
33 ssh-keygen -N '' -q -f alice -C alice
34 ssh-keygen -N '' -q -f bob -C bob
35 ssh-keygen -N '' -q -f carol -C carol
36 ssh-keygen -N '' -q -f dave -C dave
37 ssh-keygen -N '' -q -f eve -C eve
38 rm alice bob carol dave eve
39 ls -a; ok; /alice.pub/; /bob.pub/; /carol.pub/; /dave.pub/; /eve.pub/
40 $pgm; ok;
41 wc < $ak; ok; /^ *7 .*/;
42 grep gitolite $ak; ok; /start/
43 /end/
45 # some normal keys
46 mv alice.pub $ak; ok
47 cat carol.pub >> $ak; ok
48 $pgm; ok; /carol.pub duplicates.*non-gitolite key/
49 wc < $ak; ok; /^ *8 .*/;
51 # moving normal keys up
52 mv dave.pub dave
53 $pgm; ok
54 cat dave >> $ak; ok
55 grep -n dave $ak; ok; /8:ssh-rsa/
56 mv dave dave.pub
57 $pgm; ok; /carol.pub duplicates.*non-gitolite key/
58 /dave.pub duplicates.*non-gitolite key/
59 grep -n dave $ak; ok; /3:ssh-rsa/
61 # a bad key
62 ls -al > bad.pub
63 $pgm; !ok; /fingerprinting failed for \\'keydir/bad.pub\\'/
64 wc < $ak; ok; /^ *9 .*/;
65 # a good key doesn't get added
66 ssh-keygen -N '' -q -f good
67 $pgm; !ok; /fingerprinting failed for \\'keydir/bad.pub\\'/
68 wc < $ak; ok; /^ *9 .*/;
69 # till the bad key is removed
70 rm bad.pub
71 $pgm; ok;
72 wc < $ak; ok; /^ *10 .*/;
74 # duplicate gl key
75 cp bob.pub robert.pub
76 $pgm; ok; /robert.pub duplicates.*bob.pub/