1# This file is part of GNU Rush.
2# Copyright (C) 2016-2019 Sergey Poznyakoff
3#
4# GNU Rush is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation; either version 3, or (at your option)
7# any later version.
8#
9# GNU Rush is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with GNU Rush.  If not, see <http://www.gnu.org/licenses/>.
16
17AT_SETUP([map])
18AT_KEYWORDS([map])
19
20AT_CHECK([
21myvars
22
23cat > passwd.rush <<EOT
24x$MY_USER:x:$(($MY_UID + 1)):$(($MY_GID + 1))::/root:/bin/bash
25$MY_USER:x:$MY_UID:$MY_GID:Me:/:/rush_special_shell
26EOT
27
28WD=`pwd`
29cat > test.conf <<EOT
30rule
31    map[[0]] $WD/passwd.rush : \${user} 1 7 /nologin
32EOT
33
34set -e
35echo Matching map
36rush -C none -Dcmdline,argv,prog -c 'command arg' test.conf
37
38echo No match, return default
39> passwd.rush
40rush -C none -Dcmdline,argv,prog -c 'command arg' test.conf
41
42echo No match, no default
43cat > test.conf <<EOT
44rule
45    map[[0]] $WD/passwd.rush : \${user} 1 7
46EOT
47rush -C none -Dcmdline,argv,prog -c 'command arg' test.conf
48],
49[0],
50[Matching map
51{
52    "cmdline":"/rush_special_shell arg",
53    "argv":[[
54        "/rush_special_shell",
55        "arg"
56    ]],
57    "prog":null
58}
59No match, return default
60{
61    "cmdline":"/nologin arg",
62    "argv":[[
63        "/nologin",
64        "arg"
65    ]],
66    "prog":null
67}
68No match, no default
69{
70    "cmdline":"command arg",
71    "argv":[[
72        "command",
73        "arg"
74    ]],
75    "prog":null
76}
77],
78[rush: Notice: parsing legacy configuration file test.conf
79rush: Notice: parsing legacy configuration file test.conf
80rush: Notice: parsing legacy configuration file test.conf
81])
82
83AT_CLEANUP
84