File: test_alias.tcl

package info (click to toggle)
tkrat 1%3A2.2cvs20100105-true-dfsg-6.1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 10,340 kB
  • ctags: 9,259
  • sloc: ansic: 96,057; tcl: 25,667; makefile: 1,638; sh: 282
file content (263 lines) | stat: -rw-r--r-- 7,445 bytes parent folder | download | duplicates (4)
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
puts "$HEAD Test alias"

namespace eval test_alias {
}

proc test_alias::do_test {case} {
    global option

    set r [lindex $case 0]
    set a [lindex $case 1]
    StartTest "Expanding $a"

    set e [RatAlias expand display $a $r]
    set o [lindex $case 2]
    if {$e != $o} {
	ReportError "expand display '$a' gave '$e' expected '$o'"
    }
    set display $e

    set e [RatAlias expand sending $a $r]
    set o [lindex $case 3]
    if {$e != $o} {
	ReportError "expand sending '$a' gave '$e' expected '$o'"
    }

    set e [RatAlias expand sending $display $r]
    set o [lindex $case 3]
    if {$e != $o} {
	ReportError "expand sending (via display) '$a' gave '$e' expected '$o'"
    }

    set e [RatAlias expand pgp $a $r]
    set o [lindex $case 4]
    if {$e != $o} {
	ReportError "expand pgp '$a' gave '$e' expected '$o'"
    }

    set e [RatAlias expand pgp $display $r]
    set o [lindex $case 4]
    if {$e != $o} {
	ReportError "expand pgp (via display) '$a' gave '$e' expected '$o'"
    }

    set e [RatAlias expand pgpactions $a $r]
    set o [lindex $case 5]
    if {$e != $o} {
	ReportError "expand pgpactions '$a' gave '$e' expected '$o'"
    }

    set e [RatAlias expand pgpactions $display $r]
    set o [lindex $case 5]
    if {$e != $o} {
	ReportError "expand pgpactions (via display) '$a' gave '$e' expected '$o'"
    }
}

proc test_alias::test_alias {} {
    global option env

    # Setup role and aliases to test with
    set option(tr42,from) role@from.adr
    set option(tr43,from) "Full Name <$env(USER)@domain.org>"
    RatAlias add Personal key_simple {Key Name} al_simple@exp.org {} {}
    RatAlias add Personal key_nogecos {} al_nogecos@exp.org {} {}
    RatAlias add Personal key_nofull \
        {Full Name} {al_nofull@exp.org} {} {} {nofullname}
    RatAlias add Personal key_list {List} {e1, e2} {} {}
    RatAlias add Personal key_req {Recurs} {al_req@exp.org, key_nogecos} {} {}
    RatAlias add Personal key_pgp1 \
        {PGP1} al_pgp1@exp.org {} {p1 pgp1} {pgp_sign}
    RatAlias add Personal key_pgp2 \
        {PGP2} {al_pgp1@exp.org, al_pgp2} {} {p2 pg2} {pgp_encrypt}
    RatAlias add Personal key_loop {Key Loop} key_loop@from.adr {} {}
    RatAlias add Personal primary {First Level} second@from.adr {} {}
    RatAlias add Personal second {Second Level} third@from.adr {} {}

    # List of tests. Each test consists of:
    #   Role
    #   Input string
    #   Result of expand level 1
    #   Result of expand level 2
    #   Result of pgp expansion
    #   Expected pgp actions
    set tests \
        [list \
             [list tr43 \
                  "" \
                  "" \
                  "" \
                  "" \
                  "0 0" ] \
             [list tr43 \
                  "foo (foo,,,)" \
	          "\"foo,,,\" <foo>" \
	          "\"foo,,,\" <foo@domain.org>" \
		  "foo@domain.org" \
                  "0 0" ] \
             [list tr43 \
	          "Full Name <$env(USER)@domain.org>" \
	          "Full Name <$env(USER)@domain.org>" \
		  "Full Name <$env(USER)@domain.org>" \
		  "$env(USER)@domain.org" \
                  "0 0" ] \
             [list tr42 \
	          "should, not, change" \
	          "should, not, change" \
	          "should@from.adr, not@from.adr, change@from.adr" \
		  "should@from.adr not@from.adr change@from.adr" \
                  "0 0" ] \
             [list tr42 \
		  "key_simple" \
	          "Key Name <key_simple>" \
	          "Key Name <al_simple@exp.org>" \
		  "al_simple@exp.org" \
                  "0 0" ] \
             [list tr42 \
		  "key_loop" \
	          "Key Loop <key_loop>" \
	          "Key Loop <key_loop@from.adr>" \
		  "key_loop@from.adr" \
                  "0 0" ] \
             [list tr42 \
		  "$env(USER)" \
	          "$env(GECOS) <$env(USER)>" \
		  "$env(GECOS) <$env(USER)@from.adr>" \
		  "$env(USER)@from.adr" \
                  "0 0" ] \
             [list tr42 \
		  "foo, key_simple ,bar" \
	          "foo, Key Name <key_simple>, bar" \
	          "foo@from.adr, Key Name <al_simple@exp.org>, bar@from.adr" \
		  "foo@from.adr al_simple@exp.org bar@from.adr" \
                  "0 0" ] \
             [list tr42 \
		  "(foo)(foo2) (foo3) key_simple (bar)(bar2) (bar3)" \
	          "Key Name <key_simple>" \
	          "Key Name <al_simple@exp.org>" \
		  "al_simple@exp.org" \
                  "0 0" ] \
             [list tr42 \
		  "key_nogecos" \
		  "key_nogecos" \
		  "al_nogecos@exp.org" \
		  "al_nogecos@exp.org" \
                  "0 0" ] \
             [list tr42 \
		  "key_nofull" \
		  "Full Name <key_nofull>" \
		  "al_nofull@exp.org" \
                  "al_nofull@exp.org" \
                  "0 0" ] \
             [list tr42 \
		  "key_list" \
	          "List <key_list>" \
		  "e1, e2" \
		  "e1@from.adr e2@from.adr" \
                  "0 0" ] \
             [list tr42 \
		  "key_req" \
	          "Recurs <key_req>" \
		  "al_req@exp.org, al_nogecos@exp.org" \
		  "al_req@exp.org al_nogecos@exp.org" \
                  "0 0" ] \
             [list tr42 \
	          "m" \
	          "m" \
	          "m@from.adr" \
		  "m@from.adr" \
                  "0 0" ] \
             [list tr42 \
	          "a, b, c" \
	          "a, b, c" \
	          "a@from.adr, b@from.adr, c@from.adr" \
		  "a@from.adr b@from.adr c@from.adr" \
                  "0 0" ] \
             [list  tr42 \
		  "key_pgp1" \
		  "PGP1 <key_pgp1>" \
		  "PGP1 <al_pgp1@exp.org>" \
                  "{p1 pgp1}" \
                  "1 0" ] \
             [list  tr42 \
		  "al_pgp1@exp.org" \
		  "al_pgp1@exp.org" \
		  "al_pgp1@exp.org" \
                  "{p1 pgp1}" \
                  "1 0" ] \
             [list  tr42 \
		  "key_pgp2" \
		  "PGP2 <key_pgp2>" \
		  "al_pgp1@exp.org, al_pgp2" \
                  "{p2 pg2}" \
                  "1 1" ] \
             [list  tr42 \
		  "al_pgp2@exp.org" \
		  "al_pgp2@exp.org" \
		  "al_pgp2@exp.org" \
		  "al_pgp2@exp.org" \
                  "0 0" ] \
             [list tr42 \
		  "primary" \
	          "First Level <primary>" \
	          "First Level <second@from.adr>" \
	          "second@from.adr" \
                  "0 0" ] \
            ]

    # Do tests
    foreach case $tests {
	do_test $case
    }

    # Test alias which collides with a local user
    RatAlias add Personal $env(USER) {Collision} {coll@coll.org} {} {}

    # List of tests. Each test consists of:
    #   Role
    #   Input string
    #   Result of expand level 1
    #   Result of expand level 2
    #   Result of expand level 3
    set tests [list \
                   [list tr42 \
                        "$env(USER)" \
                        "Collision <$env(USER)>" \
                        "Collision <coll@coll.org>" \
                        "coll@coll.org" \
                        "0 0" ]]

    # Do tests
    foreach case $tests {
	do_test $case
    }
}

# Test the RatSplitAdr function
proc test_alias::test_split {} {
    global verbose option env

    # List of tests
    #  Alist to split
    #  Expected output
    set tests {
	{ "foo" "foo"}
	{ "foo,bar" "foo bar"}
	{ " foo , bar " "foo bar"}
	{ "foo,,bar" "foo {} bar"}
	{ " foo , , bar " "foo {} bar"}
    }

    foreach case $tests {
	set i [lindex $case 0]
	set e [lindex $case 1]
	StartTest "Splitting '$i'"
	set r [RatSplitAdr $i]
	if {"$r" != "$e"} {
	    ReportError "Gave '$r' expected '$e'"
	}
    }
}

test_alias::test_alias
test_alias::test_split