13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
package require Tcl 8.5-
if {[lsearch [namespace children] ::tcltest] == -1} {
package require tcltest 2
namespace import -force ::tcltest::*
}
foreach i [interp slaves] {
interp delete $i
}
set saveAutoPath $::auto_path
set ::auto_path [info library]
|
>
>
|
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
package require Tcl 8.5-
if {[lsearch [namespace children] ::tcltest] == -1} {
package require tcltest 2
namespace import -force ::tcltest::*
}
testConstraint AutoSyncDefined 1
foreach i [interp slaves] {
interp delete $i
}
set saveAutoPath $::auto_path
set ::auto_path [info library]
|
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
|
lsort $r
} {byteOrder engine pathSeparator platform pointerSize wordSize}
# More test should be added to check that hostname, nameofexecutable, aren't
# leaking infos, but they still do...
# high level general test
test safe-7.1 {tests that everything works at high level} -body {
set i [safe::interpCreate]
# no error shall occur:
# (because the default access_path shall include 1st level sub dirs so
# package require in a slave works like in the master)
set v [interp eval $i {package require http 2}]
# no error shall occur:
interp eval $i {http::config}
safe::interpDelete $i
set v
} -match glob -result 2.*
test safe-7.2 {tests specific path and interpFind/AddToAccessPath} -body {
set i [safe::interpCreate -nostat -nested 1 -accessPath [list [info library]]]
# should not add anything (p0)
set token1 [safe::interpAddToAccessPath $i [info library]]
# should add as p1
set token2 [safe::interpAddToAccessPath $i "/dummy/unixlike/test/path"]
# an error shall occur (http is not anymore in the secure 0-level
# provided deep path)
list $token1 $token2 \
[catch {interp eval $i {package require http 1}} msg] $msg \
[safe::interpConfigure $i]\
[safe::interpDelete $i]
} -match glob -result "{\$p(:0:)} {\$p(:*:)} 1 {can't find package http 1} {-accessPath {[list $tcl_library */dummy/unixlike/test/path]} -statics 0 -nested 1 -deleteHook {}} {}"
test safe-7.3 {check that safe subinterpreters work} {
set i [safe::interpCreate]
set j [safe::interpCreate [list $i x]]
list [interp eval $j {join {o k} ""}] [safe::interpDelete $i] [interp exists $j]
} {ok {} 0}
# test source control on file name
set i "a"
test safe-8.1 {safe source control on file} -setup {
catch {safe::interpDelete $i}
} -body {
safe::interpCreate $i
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
|
>
|
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
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
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
|
lsort $r
} {byteOrder engine pathSeparator platform pointerSize wordSize}
# More test should be added to check that hostname, nameofexecutable, aren't
# leaking infos, but they still do...
# high level general test
test safe-7.1 {tests that everything works at high level with conventional AutoPathSync} -setup {
# All ::safe commands are loaded at start of file.
set SyncExists [expr {[info commands ::safe::SetAutoPathSync] ne {}}]
if {$SyncExists} {
set SyncVal_TMP [safe::SetAutoPathSync]
safe::SetAutoPathSync 1
}
set i [safe::interpCreate]
} -body {
# no error shall occur:
# (because the default access_path shall include 1st level sub dirs so
# package require in a slave works like in the master)
set v [interp eval $i {package require http 2}]
# no error shall occur:
interp eval $i {http::config}
set v
} -cleanup {
safe::interpDelete $i
if {$SyncExists} {
safe::SetAutoPathSync $SyncVal_TMP
}
} -match glob -result 2.*
test safe-7.2 {tests specific path and interpFind/AddToAccessPath with conventional AutoPathSync} -setup {
# All ::safe commands are loaded at start of file.
set SyncExists [expr {[info commands ::safe::SetAutoPathSync] ne {}}]
if {$SyncExists} {
set SyncVal_TMP [safe::SetAutoPathSync]
safe::SetAutoPathSync 1
} else {
set SyncVal_TMP 1
}
} -body {
set i [safe::interpCreate -nostat -nested 1 -accessPath [list [info library]]]
# should not add anything (p0)
set token1 [safe::interpAddToAccessPath $i [info library]]
# should add as p* (not p1 if master has a module path)
set token2 [safe::interpAddToAccessPath $i "/dummy/unixlike/test/path"]
# an error shall occur (http is not anymore in the secure 0-level
# provided deep path)
list $token1 $token2 \
[catch {interp eval $i {package require http 1}} msg] $msg \
[safe::interpConfigure $i]\
[safe::interpDelete $i]
} -cleanup {
if {$SyncExists} {
safe::SetAutoPathSync $SyncVal_TMP
}
} -match glob -result "{\$p(:0:)} {\$p(:*:)} 1 {can't find package http 1} {-accessPath {[list $tcl_library */dummy/unixlike/test/path]} -statics 0 -nested 1 -deleteHook {}} {}"
test safe-7.3 {check that safe subinterpreters work} {
set i [safe::interpCreate]
set j [safe::interpCreate [list $i x]]
list [interp eval $j {join {o k} ""}] [safe::interpDelete $i] [interp exists $j]
} {ok {} 0}
test safe-7.4 {tests specific path and positive search with conventional AutoPathSync} -setup {
# All ::safe commands are loaded at start of file.
set SyncExists [expr {[info commands ::safe::SetAutoPathSync] ne {}}]
if {$SyncExists} {
set SyncVal_TMP [safe::SetAutoPathSync]
safe::SetAutoPathSync 1
} else {
set SyncVal_TMP 1
}
} -body {
set i [safe::interpCreate -nostat -nested 1 -accessPath [list [info library]]]
# should not add anything (p0)
set token1 [safe::interpAddToAccessPath $i [info library]]
# should add as p* (not p1 if master has a module path)
set token2 [safe::interpAddToAccessPath $i [file join [info library] http1.0]]
# this time, unlike test safe-7.2, http 1.0 should be found
list $token1 $token2 \
[catch {interp eval $i {package require http 1}} msg] $msg \
[safe::interpConfigure $i]\
[safe::interpDelete $i]
# Note that the glob match elides directories (those from the module path)
# other than the first and last in the access path.
} -cleanup {
if {$SyncExists} {
safe::SetAutoPathSync $SyncVal_TMP
}
} -match glob -result "{\$p(:0:)} {\$p(:*:)} 0 1.0 {-accessPath {[list $tcl_library *$tcl_library/http1.0]} -statics 0 -nested 1 -deleteHook {}} {}"
test safe-7.5 {tests positive and negative module loading with conventional AutoPathSync} -setup {
# All ::safe commands are loaded at start of file.
set SyncExists [expr {[info commands ::safe::SetAutoPathSync] ne {}}]
if {$SyncExists} {
set SyncVal_TMP [safe::SetAutoPathSync]
safe::SetAutoPathSync 1
}
set i [safe::interpCreate]
interp eval $i {
package forget platform::shell
package forget platform
catch {namespace delete ::platform}
}
} -body {
# Should raise an error (module ancestor directory issue)
set code1 [catch {interp eval $i {package require shell}} msg1]
# Should not raise an error
set code2 [catch {interp eval $i {package require platform::shell}} msg2]
return [list $code1 $msg1 $code2]
} -cleanup {
safe::interpDelete $i
if {$SyncExists} {
safe::SetAutoPathSync $SyncVal_TMP
}
} -result {1 {can't find package shell} 0}
# test source control on file name
set i "a"
test safe-8.1 {safe source control on file} -setup {
catch {safe::interpDelete $i}
} -body {
safe::interpCreate $i
|
399
400
401
402
403
404
405
406
407
408
409
410
411
412
|
[safe::interpConfigure $i -nested]\
[safe::interpConfigure $i -statics]\
[safe::interpConfigure $i -DEL]\
[safe::interpConfigure $i -accessPath /blah -statics 1
safe::interpConfigure $i]\
[safe::interpConfigure $i -deleteHook toto -nosta -nested 0
safe::interpConfigure $i]
} -match glob -result {{-accessPath * -statics 0 -nested 1 -deleteHook {foo bar}} {-accessPath *} {-nested 1} {-statics 0} {-deleteHook {foo bar}} {-accessPath * -statics 1 -nested 1 -deleteHook {foo bar}} {-accessPath * -statics 0 -nested 0 -deleteHook toto}}
catch {teststaticpkg Safepkg1 0 0}
test safe-10.1 {testing statics loading} -constraints TcltestPackage -setup {
set i [safe::interpCreate]
} -body {
interp eval $i {load {} Safepkg1}
|
>
>
|
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
|
[safe::interpConfigure $i -nested]\
[safe::interpConfigure $i -statics]\
[safe::interpConfigure $i -DEL]\
[safe::interpConfigure $i -accessPath /blah -statics 1
safe::interpConfigure $i]\
[safe::interpConfigure $i -deleteHook toto -nosta -nested 0
safe::interpConfigure $i]
} -cleanup {
safe::interpDelete $i
} -match glob -result {{-accessPath * -statics 0 -nested 1 -deleteHook {foo bar}} {-accessPath *} {-nested 1} {-statics 0} {-deleteHook {foo bar}} {-accessPath * -statics 1 -nested 1 -deleteHook {foo bar}} {-accessPath * -statics 0 -nested 0 -deleteHook toto}}
catch {teststaticpkg Safepkg1 0 0}
test safe-10.1 {testing statics loading} -constraints TcltestPackage -setup {
set i [safe::interpCreate]
} -body {
interp eval $i {load {} Safepkg1}
|
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
|
set i [safe::interpCreate]
} -body {
::safe::interpAddToAccessPath $i $~$tcl_platform(user)
$i eval [list glob -nocomplain ~$tcl_platform(user)/*]
} -cleanup {
safe::interpDelete $i
} -result {}
set ::auto_path $saveAutoPath
# cleanup
::tcltest::cleanupTests
return
# Local Variables:
# mode: tcl
# End:
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
|
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
|
set i [safe::interpCreate]
} -body {
::safe::interpAddToAccessPath $i $~$tcl_platform(user)
$i eval [list glob -nocomplain ~$tcl_platform(user)/*]
} -cleanup {
safe::interpDelete $i
} -result {}
### 17. The first element in a slave's ::auto_path and access path must be [info library].
test safe-17.1 {Check that first element of slave auto_path (and access path) is Tcl Library} -setup {
set lib1 [info library]
set lib2 [file dirname $lib1]
set ::auto_TMP $::auto_path
set ::auto_path [list $lib1 $lib2]
set i [safe::interpCreate]
} -body {
set autoList {}
set token [lindex [$i eval set ::auto_path] 0]
set auto0 [dict get [set ::safe::S${i}(access_path,map)] $token]
set accessList [lindex [safe::interpConfigure $i -accessPath] 1]
return [list [lindex $accessList 0] $auto0]
} -cleanup {
set ::auto_path $::auto_TMP
safe::interpDelete $i
} -result [list [info library] [info library]]
test safe-17.2 {Check that first element of slave auto_path (and access path) is Tcl Library, even if not true for master} -setup {
set lib1 [info library]
set lib2 [file dirname $lib1]
set ::auto_TMP $::auto_path
set ::auto_path [list $lib2 $lib1]
# Unexpected order, should be reversed in the slave
set i [safe::interpCreate]
} -body {
set autoList {}
set token [lindex [$i eval set ::auto_path] 0]
set auto0 [dict get [set ::safe::S${i}(access_path,map)] $token]
set accessList [lindex [safe::interpConfigure $i -accessPath] 1]
return [list [lindex $accessList 0] $auto0]
} -cleanup {
set ::auto_path $::auto_TMP
safe::interpDelete $i
} -result [list [info library] [info library]]
### 18. Tests for AutoSyncDefined without conventional AutoPathSync, i.e. with AutoPathSync off.
test safe-18.1 {cf. safe-7.1 - tests that everything works at high level without conventional AutoPathSync} -constraints AutoSyncDefined -setup {
# All ::safe commands are loaded at start of file.
set SyncExists [expr {[info commands ::safe::SetAutoPathSync] ne {}}]
if {$SyncExists} {
set SyncVal_TMP [safe::SetAutoPathSync]
safe::SetAutoPathSync 0
} else {
error {This test is meaningful only if the command ::safe::SetAutoPathSync is defined}
}
# Without AutoPathSync, we need a more complete auto_path, because the slave will use the same value.
set lib1 [info library]
set lib2 [file dirname $lib1]
set ::auto_TMP $::auto_path
set ::auto_path [list $lib1 $lib2]
set i [safe::interpCreate]
} -body {
# no error shall occur:
# (because the default access_path shall include 1st level sub dirs
# so package require in a slave works like in the master)
set v [interp eval $i {package require http 1}]
# no error shall occur:
interp eval $i {http_config}
set v
} -cleanup {
set ::auto_path $::auto_TMP
safe::interpDelete $i
if {$SyncExists} {
safe::SetAutoPathSync $SyncVal_TMP
}
} -result 1.0
test safe-18.2 {cf. safe-7.2 - tests specific path and interpFind/AddToAccessPath without conventional AutoPathSync} -constraints AutoSyncDefined -setup {
# All ::safe commands are loaded at start of file.
set SyncExists [expr {[info commands ::safe::SetAutoPathSync] ne {}}]
if {$SyncExists} {
set SyncVal_TMP [safe::SetAutoPathSync]
safe::SetAutoPathSync 0
} else {
error {This test is meaningful only if the command ::safe::SetAutoPathSync is defined}
}
} -body {
set i [safe::interpCreate -nostat -nested 1 -accessPath [list [info library]]]
set auto1 [interp eval $i {set ::auto_path}]
interp eval $i {set ::auto_path [list {$p(:0:)}]}
# should not add anything (p0)
set token1 [safe::interpAddToAccessPath $i [info library]]
# should add as p1
set token2 [safe::interpAddToAccessPath $i "/dummy/unixlike/test/path"]
# an error shall occur (http is not anymore in the secure 0-level
# provided deep path)
list $auto1 $token1 $token2 \
[catch {interp eval $i {package require http 1}} msg] $msg \
[safe::interpConfigure $i]\
[safe::interpDelete $i]
} -cleanup {
if {$SyncExists} {
safe::SetAutoPathSync $SyncVal_TMP
}
} -match glob -result "{} {\$p(:0:)} {\$p(:*:)} 1 {can't find package http 1} {-accessPath {[list $tcl_library */dummy/unixlike/test/path]} -statics 0 -nested 1 -deleteHook {}} {}"
test safe-18.3 {Check that default auto_path is the same as in the master interpreter without conventional AutoPathSync} -constraints AutoSyncDefined -setup {
# All ::safe commands are loaded at start of file.
set SyncExists [expr {[info commands ::safe::SetAutoPathSync] ne {}}]
if {$SyncExists} {
set SyncVal_TMP [safe::SetAutoPathSync]
safe::SetAutoPathSync 0
} else {
error {This test is meaningful only if the command ::safe::SetAutoPathSync is defined}
}
set i [safe::interpCreate]
} -body {
# This file's header sets auto_path to a single directory [info library],
# which is the one required by Safe Base to be present & first in the list.
set ap {}
foreach token [$i eval set ::auto_path] {
lappend ap [dict get [set ::safe::S${i}(access_path,map)] $token]
}
return $ap
} -cleanup {
safe::interpDelete $i
if {$SyncExists} {
safe::SetAutoPathSync $SyncVal_TMP
}
} -result [set ::auto_path]
test safe-18.4 {cf. safe-7.4 - tests specific path and positive search and auto_path without conventional AutoPathSync} -constraints AutoSyncDefined -setup {
# All ::safe commands are loaded at start of file.
set SyncExists [expr {[info commands ::safe::SetAutoPathSync] ne {}}]
if {$SyncExists} {
set SyncVal_TMP [safe::SetAutoPathSync]
safe::SetAutoPathSync 0
} else {
error {This test is meaningful only if the command ::safe::SetAutoPathSync is defined}
}
} -body {
set i [safe::interpCreate -nostat -nested 1 -accessPath [list [info library]]]
# should not have been set by Safe Base:
set auto1 [interp eval $i {set ::auto_path}]
interp eval $i {set ::auto_path [list {$p(:0:)}]}
# should not add anything (p0)
set token1 [safe::interpAddToAccessPath $i [info library]]
# should add as p* (not p1 if master has a module path)
set token2 [safe::interpAddToAccessPath $i [file join [info library] http1.0]]
# should not have been changed by Safe Base:
set auto2 [interp eval $i {set ::auto_path}]
# This time, unlike test safe-18.2 and the try above, http 1.0 should be found:
list $auto1 $auto2 $token1 $token2 \
[catch {interp eval $i {package require http 1}} msg] $msg \
[safe::interpConfigure $i]\
[safe::interpDelete $i]
} -cleanup {
if {$SyncExists} {
safe::SetAutoPathSync $SyncVal_TMP
}
} -match glob -result "{} {{\$p(:0:)}} {\$p(:0:)} {\$p(:*:)} 0 1.0 {-accessPath {[list $tcl_library *$tcl_library/http1.0]} -statics 0 -nested 1 -deleteHook {}} {}"
test safe-18.5 {cf. safe-7.5 - tests positive and negative module loading without conventional AutoPathSync} -setup {
# All ::safe commands are loaded at start of file.
set SyncExists [expr {[info commands ::safe::SetAutoPathSync] ne {}}]
if {$SyncExists} {
set SyncVal_TMP [safe::SetAutoPathSync]
safe::SetAutoPathSync 0
} else {
error {This test is meaningful only if the command ::safe::SetAutoPathSync is defined}
}
set i [safe::interpCreate]
interp eval $i {
package forget platform::shell
package forget platform
catch {namespace delete ::platform}
}
} -body {
# Should raise an error (tests module ancestor directory rule)
set code1 [catch {interp eval $i {package require shell}} msg1]
# Should not raise an error
set code2 [catch {interp eval $i {package require platform::shell}} msg2]
return [list $code1 $msg1 $code2]
} -cleanup {
safe::interpDelete $i
if {$SyncExists} {
safe::SetAutoPathSync $SyncVal_TMP
}
} -result {1 {can't find package shell} 0}
### 19. Test tokenization of directories available to a slave.
test safe-19.1 {Check that each directory of the default auto_path is a valid token} -setup {
set i [safe::interpCreate]
} -body {
set badTokens {}
foreach dir [$i eval {set ::auto_path}] {
if {[regexp {^\$p\(:[0-9]+:\)$} $dir]} {
# Match - OK - token has expected form
} else {
# No match - possibly an ordinary path has not been tokenized
lappend badTokens $dir
}
}
set badTokens
} -cleanup {
safe::interpDelete $i
} -result {}
test safe-19.2 {Check that each directory of the module path is a valid token} -setup {
set i [safe::interpCreate]
} -body {
set badTokens {}
foreach dir [$i eval {::tcl::tm::path list}] {
if {[regexp {^\$p\(:[0-9]+:\)$} $dir]} {
# Match - OK - token has expected form
} else {
# No match - possibly an ordinary path has not been tokenized
lappend badTokens $dir
}
}
set badTokens
} -cleanup {
safe::interpDelete $i
} -result {}
set ::auto_path $saveAutoPath
# cleanup
::tcltest::cleanupTests
return
# Local Variables:
# mode: tcl
# End:
|