1 | #!/bin/bash |
---|
2 | #------------------------------------------------------------------------------- |
---|
3 | # (C) British Crown Copyright 2006-17 Met Office. |
---|
4 | # |
---|
5 | # This file is part of FCM, tools for managing and building source code. |
---|
6 | # |
---|
7 | # FCM is free software: you can redistribute it and/or modify |
---|
8 | # it under the terms of the GNU General Public License as published by |
---|
9 | # the Free Software Foundation, either version 3 of the License, or |
---|
10 | # (at your option) any later version. |
---|
11 | # |
---|
12 | # FCM is distributed in the hope that it will be useful, |
---|
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
15 | # GNU General Public License for more details. |
---|
16 | # |
---|
17 | # You should have received a copy of the GNU General Public License |
---|
18 | # along with FCM. If not, see <http://www.gnu.org/licenses/>. |
---|
19 | #------------------------------------------------------------------------------- |
---|
20 | # Basic tests for "pre-commit". |
---|
21 | #------------------------------------------------------------------------------- |
---|
22 | . $(dirname $0)/test_header |
---|
23 | FCM_SVN_HOOK_ADMIN_EMAIL='your.admin.team' |
---|
24 | . $TEST_SOURCE_DIR/test_header_more |
---|
25 | |
---|
26 | svn mkdir --parents $REPOS_URL/foo/trunk -m "create foo trunk" |
---|
27 | svn mkdir --parents $REPOS_URL/foo/branches -m "create foo branches" |
---|
28 | svn mkdir --parents $REPOS_URL/bar/trunk -m "create bar trunk" |
---|
29 | svn mkdir --parents $REPOS_URL/bar/branches -m "create bar branches" |
---|
30 | |
---|
31 | test_tidy() { |
---|
32 | rm -f \ |
---|
33 | "$REPOS_PATH/hooks/pre-commit-custom" \ |
---|
34 | "$REPOS_PATH/hooks/pre-commit-size-threshold.conf" \ |
---|
35 | "$REPOS_PATH/hooks/commit.conf" \ |
---|
36 | "$REPOS_PATH/hooks/svnperms.conf" \ |
---|
37 | "$REPOS_PATH/log/pre-commit.log" \ |
---|
38 | README \ |
---|
39 | bin/svnperms.py \ |
---|
40 | file1 \ |
---|
41 | file2 \ |
---|
42 | file3 \ |
---|
43 | file4 \ |
---|
44 | mail.out \ |
---|
45 | pre-commit-custom.out \ |
---|
46 | svnperms.py.out |
---|
47 | } |
---|
48 | #------------------------------------------------------------------------------- |
---|
49 | tests 9 |
---|
50 | #------------------------------------------------------------------------------- |
---|
51 | cp -p "$FCM_HOME/etc/svn-hooks/pre-commit" "$REPOS_PATH/hooks/" |
---|
52 | sed -i "/set -eu/a\ |
---|
53 | echo \$2 >$PWD/txn" "$REPOS_PATH/hooks/pre-commit" |
---|
54 | #------------------------------------------------------------------------------- |
---|
55 | cp "$FCM_HOME/sbin/svnperms.py" "$REPOS_PATH/hooks/" |
---|
56 | REPOS_SHORTNAME=$(basename $REPOS_PATH) |
---|
57 | cat >"$REPOS_PATH/hooks/svnperms.conf" <<__CONF__ |
---|
58 | [$REPOS_SHORTNAME groups] |
---|
59 | admin = barry bazzy quxxy xyzzy wibbley |
---|
60 | users = wibbley wobbley wubbley $LOGNAME |
---|
61 | |
---|
62 | [$REPOS_SHORTNAME] |
---|
63 | .* = @admin(add,remove,update) |
---|
64 | |
---|
65 | foo/trunk/.* = @admin(add,remove,update) |
---|
66 | foo/branches/[^/]+/.* = *(add,remove,update) |
---|
67 | foo/tags/[^/]+/.* = @admin(add,remove,update) |
---|
68 | |
---|
69 | bar/trunk/.* = @users(add,remove,update) |
---|
70 | bar/branches/[^/]+/.* = @users(add,remove,update) |
---|
71 | bar/tags/[^/]+/.* = @admin(add,remove,update) |
---|
72 | |
---|
73 | [something_else_svn groups] |
---|
74 | admin = $LOGNAME whoever |
---|
75 | somepeople = bla blubb blabla |
---|
76 | |
---|
77 | [something_else_svn] |
---|
78 | foo/trunk/.* = @admin(add,remove,update) |
---|
79 | foo/branches/[^/]+/.* = @somepeople(add,remove,update) |
---|
80 | foo/tags/[^/]+/.* = @admin(add,remove,update) |
---|
81 | __CONF__ |
---|
82 | touch file1 |
---|
83 | #------------------------------------------------------------------------------- |
---|
84 | TEST_KEY="$TEST_KEY_BASE-trunk-fail" |
---|
85 | run_fail "$TEST_KEY" \ |
---|
86 | svn import --no-auth-cache -q -m'test' file1 "$REPOS_URL/foo/trunk/file1" |
---|
87 | file_grep "$TEST_KEY.foo-trunk.err" \ |
---|
88 | "error: you don't have enough permissions for this transaction:" \ |
---|
89 | "$TEST_KEY.err" |
---|
90 | #------------------------------------------------------------------------------- |
---|
91 | TEST_KEY="$TEST_KEY_BASE-trunk-fail-custom-err-message" |
---|
92 | echo " |
---|
93 | [message] |
---|
94 | permerrors_prefix = Bad User!" >>"$REPOS_PATH/hooks/svnperms.conf" |
---|
95 | run_fail "$TEST_KEY" \ |
---|
96 | svn import --no-auth-cache -q -m'test' file1 "$REPOS_URL/foo/trunk/file1" |
---|
97 | file_grep "$TEST_KEY.foo-trunk.err" "Bad User!" "$TEST_KEY.err" |
---|
98 | #------------------------------------------------------------------------------- |
---|
99 | TEST_KEY="$TEST_KEY_BASE-trunk-fail-custom-err-message-repos" |
---|
100 | echo " |
---|
101 | [$REPOS_SHORTNAME message] |
---|
102 | permerrors_prefix = FCM police notified" >>"$REPOS_PATH/hooks/svnperms.conf" |
---|
103 | run_fail "$TEST_KEY" \ |
---|
104 | svn import --no-auth-cache -q -m'test' file1 "$REPOS_URL/foo/trunk/file1" |
---|
105 | file_grep "$TEST_KEY.foo-trunk.err" "FCM police notified" "$TEST_KEY.err" |
---|
106 | #------------------------------------------------------------------------------- |
---|
107 | TEST_KEY="$TEST_KEY_BASE-branch-pass-all" |
---|
108 | run_pass "$TEST_KEY" \ |
---|
109 | svn mkdir --parents --no-auth-cache -q -m 'test' \ |
---|
110 | "$REPOS_URL/foo/branches/dev/$LOGNAME/"$(date +%s.%N) |
---|
111 | #------------------------------------------------------------------------------- |
---|
112 | TEST_KEY="$TEST_KEY_BASE-trunk-pass" |
---|
113 | run_pass "$TEST_KEY" \ |
---|
114 | svn import --no-auth-cache -q -m'test' file1 "$REPOS_URL/bar/trunk/file1" |
---|
115 | #------------------------------------------------------------------------------- |
---|
116 | TEST_KEY="$TEST_KEY_BASE-branch-pass-group" |
---|
117 | run_pass "$TEST_KEY" \ |
---|
118 | svn mkdir --parents --no-auth-cache -q -m 'test' \ |
---|
119 | "$REPOS_URL/bar/branches/dev/$LOGNAME/"$(date +%s.%N) |
---|
120 | #------------------------------------------------------------------------------- |
---|
121 | exit |
---|