Repository navigation
Expand file tree
/
Copy pathdllsite.py
More file actions
110 lines (93 loc) · 2.87 KB
/
Copy pathdllsite.py
File metadata and controls
110 lines (93 loc) · 2.87 KB
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
# Licensed to the .NET Foundation under one or more agreements.
# The .NET Foundation licenses this file to you under the Apache 2.0 License.
# See the LICENSE file in the project root for more information.
##
## Test autoimport of assemblies found in DLLs directory
##
from sys import exit, argv
from iptest.assert_util import *
if argv.count("OKtoRun")==0 or is_cli==False:
print("Bailing")
exit(0)
def test_sanity():
'''
Sanity checks. All of these are fairly normal imports
and should work.
'''
#first check that our native modules are still present and accounted for...
import binascii
import _collections
import copyreg
import pickle
import io
import datetime
import errno
import exceptions
import gc
import imp
import itertools
import marshal
import math
import nt
import operator
import re
import socket
import _struct
import _thread
import time
#next run through our first set of "OK" modules
for i in range(50):
mod_name = "foo" + str(i)
exec("import " + mod_name)
exec("AreEqual(" + mod_name + ".Foo().BAR," + str(i) + ")")
def test_special_cases():
'''
Extraordinary cases that should still be supported
by IP.
'''
#ensure that assemblies reopening the same module and overriding
#a class work. by "work", this means that the last (alphabetically) DLL
#should be the one that's imported
import foo
AreEqual(foo.Foo().BAR, 4)
#test some unusual DLL filenames
for partial_ns in ["ZERO", "ONE", "a", "UNDERSCORE", "WHITESPACE", "BIGFILENAME"]:
mod_name = "foo" + partial_ns
exec("import " + mod_name)
exec("AreEqual(" + mod_name + ".Foo().BAR, 1)")
def test_bad_stuff():
'''
Cases where IP should not load an assembly for one
reason or another.
'''
#ensure that users cannot override IP native modules
import sys
Assert(sys.winver != "HIJACKED")
import re
Assert(re.compile != "HIJACKED")
#ensure corrupted DLLs cannot be loaded
try:
import fooCORRUPT
raise Exception("Corrupted DLL was loaded")
except ImportError as e:
pass
#nothing to do for unmanaged DLLs...if the interpreter has made it
#this far, all is well:)
#ensure *.exe's cannot take precedence over *.dlls
import fooDLLEXE
AreEqual(fooDLLEXE.Foo().BAR, 1)
#ensure *.exe's are not autoloaded at all!
try:
import fooEXEONLY
raise Exception("*.exe's should not be autoloaded!")
except ImportError as e:
pass
except SystemError as e:
print("Work Item #189503")
#ensure *.txt's are not autoloaded at all
try:
import fooTXTDLL
raise Exception("*.txt's should not be autoloaded!")
except ImportError as e:
pass
run_test(__name__)