Skip to content

Commit 2e013fe

Browse files
committed
fixup - make a user db available to the code under test
1 parent 032cba9 commit 2e013fe

File tree

3 files changed

+212
-4
lines changed

3 files changed

+212
-4
lines changed
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
(dp0
2+
V/C=DK/ST=NA/L=NA/O=Test Org/OU=NA/CN=b'Test User'/emailAddress=dummy-user
3+
p1
4+
(dp2
5+
Vfull_name
6+
p3
7+
Vb'Test User'
8+
p4
9+
sVorganization
10+
p5
11+
VTest Org
12+
p6
13+
sVstate
14+
p7
15+
VNA
16+
p8
17+
sVcountry
18+
p9
19+
VDK
20+
p10
21+
sVemail
22+
p11
23+
Vdummy-user
24+
p12
25+
sVcomment
26+
p13
27+
VThis is the create comment
28+
p14
29+
sVpassword
30+
p15
31+
V
32+
p16
33+
sVpassword_hash
34+
p17
35+
VPBKDF2$sha256$10000$b't0JM/JjkQ347th0Q'$b'QupJt53hA5KhESEeqDhTQTCPOrCBvZ6H'
36+
p18
37+
sVdistinguished_name
38+
p19
39+
V/C=DK/ST=NA/L=NA/O=Test Org/OU=NA/CN=b'Test User'/emailAddress=dummy-user
40+
p20
41+
sVlocality
42+
p21
43+
g16
44+
sVorganizational_unit
45+
p22
46+
g16
47+
sVexpire
48+
p23
49+
I1757925298
50+
sVcreated
51+
p24
52+
F1726233828.2676349
53+
sVunique_id
54+
p25
55+
VktyCKIRg9HvsVzXMQ22EaKS67t9atchv9JKTiJqrtBiGN3qksKrbTTYIH8mitY2K
56+
p26
57+
sVopenid_names
58+
p27
59+
(lp28
60+
sVold_password_hash
61+
p29
62+
VPBKDF2$sha256$10000$b'GL7Qq92iLe/hZXBo'$b'ZwB/5IZqgU7onP+ZqZk9zcHVZOx7jmWz'
63+
p30
64+
sVrenewed
65+
p31
66+
F1726389298.7801197
67+
ssV/C=DK/ST=NA/L=NA/O=Test Org/OU=NA/CN=Test User/emailAddress=dummy-user
68+
p32
69+
(dp33
70+
Vfull_name
71+
p34
72+
VTest User
73+
p35
74+
sVorganization
75+
p36
76+
VTest Org
77+
p37
78+
sVstate
79+
p38
80+
VNA
81+
p39
82+
sVcountry
83+
p40
84+
VDK
85+
p41
86+
sVemail
87+
p42
88+
Vdummy-user
89+
p43
90+
sVcomment
91+
p44
92+
VThis is the create comment
93+
p45
94+
sVpassword
95+
p46
96+
g16
97+
sVpassword_hash
98+
p47
99+
VPBKDF2$sha256$10000$b'kZ8WgLNH+wg3X11d'$b't1d08MV4g215WYW7S7EbkjHqDF+MCjMa'
100+
p48
101+
sVdistinguished_name
102+
p49
103+
V/C=DK/ST=NA/L=NA/O=Test Org/OU=NA/CN=Test User/emailAddress=dummy-user
104+
p50
105+
sVlocality
106+
p51
107+
g16
108+
sVorganizational_unit
109+
p52
110+
g16
111+
sVexpire
112+
p53
113+
I1759243332
114+
sVcreated
115+
p54
116+
F1726602273.7987707
117+
sVunique_id
118+
p55
119+
VKdYHJ21t37jAoHUmBq6t8Xnsnih6JWR5i0QepHoVXfDpQxz9fQGnEmegoDNrPzbe
120+
p56
121+
sVopenid_names
122+
p57
123+
(lp58
124+
sVold_password_hash
125+
p59
126+
VPBKDF2$sha256$10000$b'yObizsUepZvvJ0/r'$b'uKIt7n6Lf/7WXD6pKDGyvT30L2uowBnV'
127+
p60
128+
sVrenewed
129+
p61
130+
F1727707333.0969944
131+
ssV/C=DK/ST=NA/L=NA/O=Test Org/OU=NA/CN=Test User/emailAddress=test@example.com
132+
p62
133+
(dp63
134+
Vfull_name
135+
p64
136+
VTest User
137+
p65
138+
sVorganization
139+
p66
140+
VTest Org
141+
p67
142+
sVstate
143+
p68
144+
VNA
145+
p69
146+
sVcountry
147+
p70
148+
VDK
149+
p71
150+
sVemail
151+
p72
152+
Vtest@example.com
153+
p73
154+
sVcomment
155+
p74
156+
VThis is the create comment
157+
p75
158+
sVpassword
159+
p76
160+
g16
161+
sVpassword_hash
162+
p77
163+
VPBKDF2$sha256$10000$b'/TkhLk4yMGf6XhaY'$b'7HUeQ9iwCkE4YMQAaCd+ZdrN+y8EzkJH'
164+
p78
165+
sVdistinguished_name
166+
p79
167+
g62
168+
sVlocality
169+
p80
170+
g16
171+
sVorganizational_unit
172+
p81
173+
g16
174+
sVexpire
175+
p82
176+
I1758970812
177+
sVcreated
178+
p83
179+
F1727434813.0792377
180+
sVunique_id
181+
p84
182+
VaTza92klrnN2wfylm6HnphCy9C3PReGpQ6jklJ7zF3xjeaUDw36tW95Avx43vtba
183+
p85
184+
sVopenid_names
185+
p86
186+
(lp87
187+
ss.

tests/support/__init__.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ def is_path_within(path, start=None, _msg=None):
276276
return not relative.startswith('..')
277277

278278

279-
def fixturefile(relative_path, fixture_format=None):
279+
def fixturefile(relative_path, fixture_format=None, include_path=False):
280280
"""Support function for loading fixtures from their serialised format.
281281
282282
Doing so is a little more involved than it may seem because serialisation
@@ -296,12 +296,24 @@ def fixturefile(relative_path, fixture_format=None):
296296
#_, extension = os.path.splitext(os.path.basename(tmp_path))
297297
#assert fixture_format == extension, "fixture file does not match format"
298298

299-
if fixture_format == 'json':
300-
return _fixturefile_json(tmp_path)
299+
data = None
300+
301+
if fixture_format == 'binary':
302+
with open(tmp_path, 'rb') as binfile:
303+
data = binfile.read()
304+
elif fixture_format == 'json':
305+
data = _fixturefile_json(tmp_path)
301306
else:
302307
raise AssertionError(
303308
"unsupported fixture format: %s" % (fixture_format,))
304309

310+
return (data, tmp_path) if include_path else data
311+
312+
313+
def fixturefile_normname(relative_path, prefix=None):
314+
normname, _ = relative_path.split('--')
315+
return os.path.join(prefix, normname) if prefix else normname
316+
305317

306318
_FIXTUREFILE_HINTAPPLIERS = {
307319
'array_of_tuples': lambda value: [tuple(x) for x in value]

tests/test_mig_cgibin_cat.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
from __future__ import print_function
22
import importlib
33
import os
4+
import shutil
45
import sys
56

6-
from tests.support import MIG_BASE, MigTestCase, testmain, _temppath
7+
from tests.support import MIG_BASE, MigTestCase, testmain, _temppath, \
8+
fixturefile, fixturefile_normname
79

810
from mig.shared.base import client_id_dir
911
from mig.shared.functionality.cat import _main as main
@@ -29,6 +31,13 @@ def _provide_configuration(self):
2931
def before_each(self):
3032
user_home = self.configuration.user_home[:-1]
3133
client_dir = client_id_dir(self.TEST_CLIENT_ID)
34+
35+
# ensure a user db with our test user
36+
db_home = self.configuration.user_db_home
37+
db_fixture, db_fixture_file = fixturefile('MiG-users.db--example', fixture_format='binary', include_path=True)
38+
test_db_file = _temppath(fixturefile_normname('MiG-users.db--example', prefix=db_home), self)
39+
shutil.copyfile(db_fixture_file, test_db_file)
40+
3241
# create the test user home directory
3342
self.test_user_dir = _temppath(os.path.join(user_home, client_dir), self, ensure_dir=True)
3443
self.test_environ = create_wsgi_environ(self.configuration)

0 commit comments

Comments
 (0)