-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement a test covering operation of the cat funcitonality file.
Make use of the seam that exists by virtue of the functionality files return output objects which are intrepreted by a wrapper to unit test the behaviour of cat. Specifically, we can arrange for a suitable environment plus arguments and then check the right output_objects are created. Allow doing this by exposing a variant of the cat main method which returns them rather than invoking the outer wrapper. Name this _main and call it from the original main. Note that this change is in effect a blueprint that can be used when adding coverage for other functionaity files.
- Loading branch information
Showing
5 changed files
with
295 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
(dp0 | ||
V/C=DK/ST=NA/L=NA/O=Test Org/OU=NA/CN=b'Test User'/emailAddress=dummy-user | ||
p1 | ||
(dp2 | ||
Vfull_name | ||
p3 | ||
Vb'Test User' | ||
p4 | ||
sVorganization | ||
p5 | ||
VTest Org | ||
p6 | ||
sVstate | ||
p7 | ||
VNA | ||
p8 | ||
sVcountry | ||
p9 | ||
VDK | ||
p10 | ||
sVemail | ||
p11 | ||
Vdummy-user | ||
p12 | ||
sVcomment | ||
p13 | ||
VThis is the create comment | ||
p14 | ||
sVpassword | ||
p15 | ||
V | ||
p16 | ||
sVpassword_hash | ||
p17 | ||
VPBKDF2$sha256$10000$b't0JM/JjkQ347th0Q'$b'QupJt53hA5KhESEeqDhTQTCPOrCBvZ6H' | ||
p18 | ||
sVdistinguished_name | ||
p19 | ||
V/C=DK/ST=NA/L=NA/O=Test Org/OU=NA/CN=b'Test User'/emailAddress=dummy-user | ||
p20 | ||
sVlocality | ||
p21 | ||
g16 | ||
sVorganizational_unit | ||
p22 | ||
g16 | ||
sVexpire | ||
p23 | ||
I1757925298 | ||
sVcreated | ||
p24 | ||
F1726233828.2676349 | ||
sVunique_id | ||
p25 | ||
VktyCKIRg9HvsVzXMQ22EaKS67t9atchv9JKTiJqrtBiGN3qksKrbTTYIH8mitY2K | ||
p26 | ||
sVopenid_names | ||
p27 | ||
(lp28 | ||
sVold_password_hash | ||
p29 | ||
VPBKDF2$sha256$10000$b'GL7Qq92iLe/hZXBo'$b'ZwB/5IZqgU7onP+ZqZk9zcHVZOx7jmWz' | ||
p30 | ||
sVrenewed | ||
p31 | ||
F1726389298.7801197 | ||
ssV/C=DK/ST=NA/L=NA/O=Test Org/OU=NA/CN=Test User/emailAddress=dummy-user | ||
p32 | ||
(dp33 | ||
Vfull_name | ||
p34 | ||
VTest User | ||
p35 | ||
sVorganization | ||
p36 | ||
VTest Org | ||
p37 | ||
sVstate | ||
p38 | ||
VNA | ||
p39 | ||
sVcountry | ||
p40 | ||
VDK | ||
p41 | ||
sVemail | ||
p42 | ||
Vdummy-user | ||
p43 | ||
sVcomment | ||
p44 | ||
VThis is the create comment | ||
p45 | ||
sVpassword | ||
p46 | ||
g16 | ||
sVpassword_hash | ||
p47 | ||
VPBKDF2$sha256$10000$b'kZ8WgLNH+wg3X11d'$b't1d08MV4g215WYW7S7EbkjHqDF+MCjMa' | ||
p48 | ||
sVdistinguished_name | ||
p49 | ||
V/C=DK/ST=NA/L=NA/O=Test Org/OU=NA/CN=Test User/emailAddress=dummy-user | ||
p50 | ||
sVlocality | ||
p51 | ||
g16 | ||
sVorganizational_unit | ||
p52 | ||
g16 | ||
sVexpire | ||
p53 | ||
I1759243332 | ||
sVcreated | ||
p54 | ||
F1726602273.7987707 | ||
sVunique_id | ||
p55 | ||
VKdYHJ21t37jAoHUmBq6t8Xnsnih6JWR5i0QepHoVXfDpQxz9fQGnEmegoDNrPzbe | ||
p56 | ||
sVopenid_names | ||
p57 | ||
(lp58 | ||
sVold_password_hash | ||
p59 | ||
VPBKDF2$sha256$10000$b'yObizsUepZvvJ0/r'$b'uKIt7n6Lf/7WXD6pKDGyvT30L2uowBnV' | ||
p60 | ||
sVrenewed | ||
p61 | ||
F1727707333.0969944 | ||
ssV/C=DK/ST=NA/L=NA/O=Test Org/OU=NA/CN=Test User/[email protected] | ||
p62 | ||
(dp63 | ||
Vfull_name | ||
p64 | ||
VTest User | ||
p65 | ||
sVorganization | ||
p66 | ||
VTest Org | ||
p67 | ||
sVstate | ||
p68 | ||
VNA | ||
p69 | ||
sVcountry | ||
p70 | ||
VDK | ||
p71 | ||
sVemail | ||
p72 | ||
[email protected] | ||
p73 | ||
sVcomment | ||
p74 | ||
VThis is the create comment | ||
p75 | ||
sVpassword | ||
p76 | ||
g16 | ||
sVpassword_hash | ||
p77 | ||
VPBKDF2$sha256$10000$b'/TkhLk4yMGf6XhaY'$b'7HUeQ9iwCkE4YMQAaCd+ZdrN+y8EzkJH' | ||
p78 | ||
sVdistinguished_name | ||
p79 | ||
g62 | ||
sVlocality | ||
p80 | ||
g16 | ||
sVorganizational_unit | ||
p81 | ||
g16 | ||
sVexpire | ||
p82 | ||
I1758970812 | ||
sVcreated | ||
p83 | ||
F1727434813.0792377 | ||
sVunique_id | ||
p84 | ||
VaTza92klrnN2wfylm6HnphCy9C3PReGpQ6jklJ7zF3xjeaUDw36tW95Avx43vtba | ||
p85 | ||
sVopenid_names | ||
p86 | ||
(lp87 | ||
ss. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
from __future__ import print_function | ||
import importlib | ||
import os | ||
import shutil | ||
import sys | ||
|
||
from tests.support import MIG_BASE, MigTestCase, testmain, \ | ||
fixturefile, fixturefile_normname, \ | ||
_ensuredirs, _temppath | ||
|
||
from mig.shared.base import client_id_dir | ||
from mig.shared.functionality.cat import _main as main | ||
|
||
|
||
def create_http_environ(configuration, wsgi_variables={}): | ||
"""Small helper that can create a minimum viable environ dict suitable | ||
for passing to http-facing code for the supplied configuration.""" | ||
|
||
environ = {} | ||
environ['MIG_CONF'] = configuration.config_file | ||
environ['HTTP_HOST'] = wsgi_variables.get('http_host', 'localhost') | ||
environ['PATH_INFO'] = wsgi_variables.get('path_info', '/') | ||
environ['REMOTE_ADDR'] = wsgi_variables.get('remote_addr', '127.0.0.1') | ||
environ['SCRIPT_URI'] = ''.join(('http://', environ['HTTP_HOST'], environ['PATH_INFO'])) | ||
return environ | ||
|
||
|
||
class MigCgibinCat(MigTestCase): | ||
TEST_CLIENT_ID = '/C=DK/ST=NA/L=NA/O=Test Org/OU=NA/CN=Test User/[email protected]' | ||
|
||
def _provide_configuration(self): | ||
return 'testconfig' | ||
|
||
def before_each(self): | ||
# ensure a user home directory for our test user | ||
conf_user_home = self.configuration.user_home[:-1] | ||
test_client_dir = client_id_dir(self.TEST_CLIENT_ID) | ||
test_user_dir = os.path.join(conf_user_home, test_client_dir) | ||
|
||
# ensure a user db that includes our test user | ||
conf_user_db_home = _ensuredirs(self.configuration.user_db_home) | ||
_temppath(conf_user_db_home, self) | ||
db_fixture, db_fixture_file = fixturefile('MiG-users.db--example', fixture_format='binary', include_path=True) | ||
test_db_file = _temppath(fixturefile_normname('MiG-users.db--example', prefix=conf_user_db_home), self) | ||
shutil.copyfile(db_fixture_file, test_db_file) | ||
|
||
# create the test user home directory | ||
self.test_user_dir = _ensuredirs(test_user_dir) | ||
_temppath(self.test_user_dir, self) | ||
self.test_environ = create_http_environ(self.configuration) | ||
|
||
def test_returns_file_output_with_single_file_match(self): | ||
with open(os.path.join(self.test_user_dir, 'foobar.txt'), 'w'): | ||
pass | ||
payload = { | ||
'path': ['foobar.txt'], | ||
} | ||
|
||
(output_objects, status) = main(self.configuration, self.logger, client_id=self.TEST_CLIENT_ID, user_arguments_dict=payload, environ=self.test_environ) | ||
self.assertEqual(len(output_objects), 1) | ||
output_obj = output_objects[0] | ||
self.assertEqual(output_obj['object_type'], 'file_output') | ||
|
||
|
||
if __name__ == '__main__': | ||
testmain() |