Bump to 1.14.1
[platform/upstream/augeas.git] / lenses / tests / test_access.aug
1 (*
2 Module: Test_Access
3   Provides unit tests and examples for the <Access> lens.
4 *)
5
6 module Test_access =
7
8 (* Variable: conf
9     A full configuration *)
10 let conf = "+ : ALL : LOCAL
11 + : root : localhost.localdomain
12 - : root : 127.0.0.1 .localdomain
13 + : root alice@server1 @admins (wheel) : cron crond :0 tty1 tty2 tty3 tty4 tty5 tty6
14 # IP v6 support
15 + : john foo : 2001:4ca0:0:101::1 2001:4ca0:0:101::/64
16 # Except
17 + : ALL EXCEPT john @wheel : ALL EXCEPT LOCAL .win.tue.nl
18 # No spaces
19 +:root:.example.com
20 "
21
22 (* Test: Access.lns
23      Test the full <conf> *)
24 test Access.lns get conf =
25     { "access" = "+"
26         { "user" = "ALL" }
27         { "origin" = "LOCAL" } }
28     { "access" = "+"
29         { "user" = "root" }
30         { "origin" = "localhost.localdomain" } }
31     { "access" = "-"
32         { "user" = "root" }
33         { "origin" = "127.0.0.1" }
34         { "origin" = ".localdomain" } }
35     { "access" = "+"
36         { "user" = "root" }
37         { "user" = "alice"
38            { "host" = "server1" } }
39         { "netgroup" = "admins" }
40         { "group" = "wheel" }
41         { "origin" = "cron" }
42         { "origin" = "crond" }
43         { "origin" = ":0" }
44         { "origin" = "tty1" }
45         { "origin" = "tty2" }
46         { "origin" = "tty3" }
47         { "origin" = "tty4" }
48         { "origin" = "tty5" }
49         { "origin" = "tty6" } }
50     { "#comment" = "IP v6 support" }
51     { "access" = "+"
52         { "user" = "john" }
53         { "user" = "foo" }
54         { "origin" = "2001:4ca0:0:101::1" }
55         { "origin" = "2001:4ca0:0:101::/64" } }
56     { "#comment" = "Except" }
57     { "access" = "+"
58         { "user" = "ALL" }
59         { "except"
60            { "user" = "john" }
61            { "netgroup" = "wheel" } }
62         { "origin" = "ALL" }
63         { "except"
64            { "origin" = "LOCAL" }
65            { "origin" = ".win.tue.nl" } } }
66     { "#comment" = "No spaces" }
67     { "access" = "+"
68         { "user" = "root" }
69         { "origin" = ".example.com" } }
70
71 test Access.lns put conf after
72     insa "access" "access[last()]" ;
73     set "access[last()]" "-" ;
74     set "access[last()]/user" "ALL" ;
75     set "access[last()]/origin" "ALL"
76  = "+ : ALL : LOCAL
77 + : root : localhost.localdomain
78 - : root : 127.0.0.1 .localdomain
79 + : root alice@server1 @admins (wheel) : cron crond :0 tty1 tty2 tty3 tty4 tty5 tty6
80 # IP v6 support
81 + : john foo : 2001:4ca0:0:101::1 2001:4ca0:0:101::/64
82 # Except
83 + : ALL EXCEPT john @wheel : ALL EXCEPT LOCAL .win.tue.nl
84 # No spaces
85 +:root:.example.com
86 - : ALL : ALL
87 "
88
89 (* Test: Access.lns
90      - netgroups (starting with '@') are mapped as "netgroup" nodes;
91      - nisdomains (starting with '@@') are mapped as "nisdomain" nodes.
92
93  This closes <ticket #190 at https://fedorahosted.org/augeas/ticket/190>.
94  *)
95 test Access.lns get "+ : @group@@domain : ALL \n" =
96   { "access" = "+"
97     { "netgroup" = "group"
98       { "nisdomain" = "domain" } }
99     { "origin" = "ALL" } }
100
101 (* Test Access.lns
102    Put test for netgroup and nisdomain *)
103 test Access.lns put "+ : @group : ALL \n" after
104   set "/access/netgroup[. = 'group']/nisdomain" "domain" =
105 "+ : @group@@domain : ALL \n"
106
107 (* Check DOMAIN\user style entry *)
108 test Access.lns get "+ : root : foo1.bar.org foo3.bar.org
109 + : (DOMAIN\linux_users) : ALL
110 + : DOMAIN\linux_user : ALL\n" =
111   { "access" = "+"
112     { "user" = "root" }
113     { "origin" = "foo1.bar.org" }
114     { "origin" = "foo3.bar.org" } }
115   { "access" = "+"
116     { "group" = "DOMAIN\linux_users" }
117     { "origin" = "ALL" } }
118   { "access" = "+"
119     { "user" = "DOMAIN\linux_user" }
120     { "origin" = "ALL" } }