def runTest(self): logging.info( ' -- Test PMPns04/1: handle broken input for append/validation: JSON not an array' ) aodsfile = os.path.abspath('work/PMP/ns01/aods.json') inputfile = os.path.abspath('testdata/PMP/ns04/pmpinput_noarray.json') logging.debug('appending invalid input file ' + inputfile) cliClient = CliPmp(['-v', '-n', '-a', aodsfile, 'append', inputfile]) with self.assertRaises(PMPInputRecNoDictError) as context: PMP.run_me(cliClient) logging.debug('Expected exception caught: ' + str(context.expected) + ': ' + context.exception.args[0]) logging.info( ' -- Test PMPns04/2: handle broken input for append/validation: FK references non-existing domain' ) inputfile = os.path.abspath( 'testdata/PMP/ns04/pmpinput_fk_invalid_domain.json') logging.debug('appending invalid input file ' + inputfile) cliClient = CliPmp(['-v', '-n', '-a', aodsfile, 'append', inputfile]) with self.assertRaises(InputValueError) as context: PMP.run_me(cliClient) logging.debug('Expected exception caught: ' + str(context.expected) + ': ' + context.exception.args[0]) logging.info( ' -- Test PMPns04/3: handle broken input for append/validation: wrong type of PK (bool not String)' ) inputfile = os.path.abspath( 'testdata/PMP/ns04/pmpinput_pk_no_str.json') logging.debug('appending invalid input file ' + inputfile) cliClient = CliPmp(['-v', '-n', '-a', aodsfile, 'append', inputfile]) with self.assertRaises(InputFormatError) as context: PMP.run_me(cliClient) logging.debug('Expected exception caught: ' + str(context.expected) + ': ' + context.exception.args[0]) logging.info( ' -- Test PMPns04/4: handle broken input for append/validation: wrong type of PK (int not String)' ) inputfile = os.path.abspath( 'testdata/PMP/ns04/pmpinput_pk_no_str.json.json') logging.debug('appending invalid input file ' + inputfile) cliClient = CliPmp(['-v', '-n', '-a', aodsfile, 'append', inputfile]) with self.assertRaises(InputFormatError) as context: PMP.run_me(cliClient) logging.debug('Expected exception caught: ' + str(context.expected) + ': ' + context.exception.args[0]) logging.info( ' -- Test PMPns04/5: handle broken input for append/validation: FK in user privilege references non-existing organization' ) inputfile = os.path.abspath( 'testdata/PMP/ns04/pmpinput_fk_invalid_org.json.json') logging.debug('appending invalid input file ' + inputfile) cliClient = CliPmp(['-v', '-n', '-a', aodsfile, 'append', inputfile]) with self.assertRaises(InputValueError) as context: PMP.run_me(cliClient) logging.debug('Expected exception caught: ' + str(context.expected) + ': ' + context.exception.args[0])
def runTest(self): logging.info(' -- Test PMPns02: detect broken hash chain') aodsfile = os.path.abspath('testdata/PMP/ns02/aods_broken_hashchain.json') logging.debug('reading aods file with broken hash chain .. ') cliClient = CliPmp(['-v', '-n', '-a', aodsfile, 'read']) with self.assertRaises(HashChainError) as context: PMP.run_me(cliClient) logging.debug('Expected exception caught: ' + str(context.expected) + ': ' + context.exception.args[0])
def runTest(self): logging.info(' -- Test PMPns03: handle broken json input for append') aodsfile = os.path.abspath('work/PMP/ns01/aods.json') inputfile = os.path.abspath('testdata/PMP/ns03/pmpinput_brokenjson.json') logging.debug('appending broken input file %s .. ' % inputfile) cliClient = CliPmp(['-v', '-n', '-a', aodsfile, 'append', inputfile]) with self.assertRaises(JSONdecodeError) as context: PMP.run_me(cliClient) logging.debug('Expected exception caught: ' + str(context.expected) + ': ' + ''.join(context.exception.args))
def runTest(self): logging.info(' -- Test PMPns02: detect broken hash chain') aodsfile = os.path.abspath( 'testdata/PMP/ns02/aods_broken_hashchain.json') logging.debug('reading aods file with broken hash chain .. ') cliClient = CliPmp(['-v', '-n', '-a', aodsfile, 'read']) with self.assertRaises(HashChainError) as context: PMP.run_me(cliClient) logging.debug('Expected exception caught: ' + str(context.expected) + ': ' + context.exception.args[0])
def runTest(self): logging.info(' -- Test PMPns03: handle broken json input for append') aodsfile = os.path.abspath('work/PMP/ns01/aods.json') inputfile = os.path.abspath( 'testdata/PMP/ns03/pmpinput_brokenjson.json') logging.debug('appending broken input file %s .. ' % inputfile) cliClient = CliPmp(['-v', '-n', '-a', aodsfile, 'append', inputfile]) with self.assertRaises(JSONdecodeError) as context: PMP.run_me(cliClient) logging.debug('Expected exception caught: ' + str(context.expected) + ': ' + ''.join(context.exception.args))
def runTest(self): logging.info(' -- Test PMPns04/1: handle broken input for append/validation: JSON not an array') aodsfile = os.path.abspath('work/PMP/ns01/aods.json') inputfile = os.path.abspath('testdata/PMP/ns04/pmpinput_noarray.json') logging.debug('appending invalid input file ' + inputfile) cliClient = CliPmp(['-v', '-n', '-a', aodsfile, 'append', inputfile]) with self.assertRaises(PMPInputRecNoDictError) as context: PMP.run_me(cliClient) logging.debug('Expected exception caught: ' + str(context.expected) + ': ' + context.exception.args[0]) logging.info(' -- Test PMPns04/2: handle broken input for append/validation: FK references non-existing domain') inputfile = os.path.abspath('testdata/PMP/ns04/pmpinput_fk_invalid_domain.json') logging.debug('appending invalid input file ' + inputfile) cliClient = CliPmp(['-v', '-n', '-a', aodsfile, 'append', inputfile]) with self.assertRaises(InputValueError) as context: PMP.run_me(cliClient) logging.debug('Expected exception caught: ' + str(context.expected) + ': ' + context.exception.args[0]) logging.info(' -- Test PMPns04/3: handle broken input for append/validation: wrong type of PK (bool not String)') inputfile = os.path.abspath('testdata/PMP/ns04/pmpinput_pk_no_str.json') logging.debug('appending invalid input file ' + inputfile) cliClient = CliPmp(['-v', '-n', '-a', aodsfile, 'append', inputfile]) with self.assertRaises(InputFormatError) as context: PMP.run_me(cliClient) logging.debug('Expected exception caught: ' + str(context.expected) + ': ' + context.exception.args[0]) logging.info(' -- Test PMPns04/4: handle broken input for append/validation: wrong type of PK (int not String)') inputfile = os.path.abspath('testdata/PMP/ns04/pmpinput_pk_no_str.json.json') logging.debug('appending invalid input file ' + inputfile) cliClient = CliPmp(['-v', '-n', '-a', aodsfile, 'append', inputfile]) with self.assertRaises(InputFormatError) as context: PMP.run_me(cliClient) logging.debug('Expected exception caught: ' + str(context.expected) + ': ' + context.exception.args[0]) logging.info(' -- Test PMPns04/5: handle broken input for append/validation: FK in user privilege references non-existing organization') inputfile = os.path.abspath('testdata/PMP/ns04/pmpinput_fk_invalid_org.json.json') logging.debug('appending invalid input file ' + inputfile) cliClient = CliPmp(['-v', '-n', '-a', aodsfile, 'append', inputfile]) with self.assertRaises(InputValueError) as context: PMP.run_me(cliClient) logging.debug('Expected exception caught: ' + str(context.expected) + ': ' + context.exception.args[0])
def runTest(self): logging.info( ' -- Test PMPws01: happy cycle: create, append, read, verify policy journal sig + struct)' ) pol_journal_fn = 'pol_journal.xml' subdir = 'PMP/ws01/' pol_journal = os.path.join('work', subdir, pol_journal_fn) policyjournal_export = 'work/PMP/ws01/pol_journal_export.json' policydir_json = 'work/PMP/ws01/poldir.json' policydir_html = 'work/PMP/ws01/poldir.html' logging.debug(' removing existing aods file %s .. ' % pol_journal) cliClient = CliPmp([ '-v', '-t', 'testdata/trustedcerts.json', '-a', pol_journal, 'scratch' ]) PMP.run_me(cliClient) logging.debug(' creating aods file .. ') cliClient = CliPmp([ '-v', '-t', 'testdata/trustedcerts.json', '-a', pol_journal, 'create' ]) PMP.run_me(cliClient) inputfile = os.path.abspath( 'testdata/PMP/ws01/pmp_initial_policy.json') logging.debug(' appending input file %s .. ' % inputfile) cliClient = CliPmp([ '-v', '-t', 'testdata/trustedcerts.json', '-a', pol_journal, 'append', inputfile ]) PMP.run_me(cliClient) logging.debug( ' reading policy journal, exporting policy journal as json.') cliClient = CliPmp(['-v', '-t', 'testdata/trustedcerts.json', '-a', pol_journal, 'read', \ '--journal', policyjournal_export]) PMP.run_me(cliClient) logging.debug( ' reading policy journal, exporting policy directory as json.') cliClient = CliPmp(['-v', '-t', 'testdata/trustedcerts.json', '-a', pol_journal, 'read', \ '--poldirjson', policydir_json]) PMP.run_me(cliClient) assertNoDiff('poldir.json', subdir=subdir) logging.debug( ' reading policy journal, exporting policy directory as html.') cliClient = CliPmp(['-v', '-t', 'testdata/trustedcerts.json', '-a', pol_journal, 'read', \ '--poldirhtml', policydir_html]) PMP.run_me(cliClient)
def runTest(self): logging.info(' -- Test PMPns01: happy cycle: create, append, read, verify; aods via option') policy_journal = os.path.abspath('work/PMP/ns01/aods.json') logging.debug('=== removing existing aods file .. ') cliClient = CliPmp(['-v', '-n', '-a', policy_journal, 'scratch']) PMP.run_me(cliClient) logging.debug('=== creating aods file .. ') cliClient = CliPmp(['-v', '-n', '-a', policy_journal, 'create']) PMP.run_me(cliClient) logging.debug('=== create done.') inputfile = os.path.abspath('testdata/PMP/ns01/append01_OK.json') logging.debug('=== appending input file %s .. ' % inputfile) cliClient = CliPmp(['-v', '-n', '-a', policy_journal, 'append', inputfile]) PMP.run_me(cliClient) logging.debug('=== append done.') inputfile = os.path.abspath('testdata/PMP/ns01/append02_delete_non_exist_rec.json') logging.debug('=== appending input file %s .. ' % inputfile) cliClient = CliPmp(['-v', '-n', '-a', policy_journal, 'append', inputfile]) with self.assertRaises(InputValueError) as context: PMP.run_me(cliClient) logging.debug('=== append done.') inputfile = os.path.abspath('testdata/PMP/ns01/append03_delete_non_exist_orgid.json') logging.debug('=== appending input file %s .. ' % inputfile) cliClient = CliPmp(['-v', '-n', '-a', policy_journal, 'append', inputfile]) with self.assertRaises(InputValueError) as context: PMP.run_me(cliClient) logging.debug('=== append done.') inputfile = os.path.abspath('testdata/PMP/ns01/append04_OK.json') logging.debug('=== appending input file %s .. ' % inputfile) cliClient = CliPmp(['-v', '-n', '-a', policy_journal, 'append', inputfile]) PMP.run_me(cliClient) logging.debug('=== append done.') logging.debug('=== reading & dumping policy journal as json, directory as json & html .. ') cliClient = CliPmp(['-v', '-n', '-a', policy_journal, 'read', '--poldirjson', os.path.abspath('work/PMP/ns01/poldir1.json'), '--poldirhtml', os.path.abspath('work/PMP/ns01/poldir1.html'), '--journal', os.path.abspath('work/PMP/ns01/pol_journal1.json')]) PMP.run_me(cliClient) assertNoDiff('poldir1.json', subdir='PMP/ns01') inputfile = os.path.abspath('testdata/PMP/ns01/append05_OK.json') logging.debug('=== appending input file %s .. ' % inputfile) cliClient = CliPmp(['-v', '-n', '-a', policy_journal, 'append', inputfile]) PMP.run_me(cliClient) logging.debug('=== append done.') logging.debug('=== reading & dumping policy journal as json, directory as json & html ..; aods via env var') os.environ['POLMAN_AODS'] = policy_journal cliClient = CliPmp(['-v', '-n', 'read', '--poldirjson', os.path.abspath('work/PMP/ns01/poldir2.json'), '--poldirhtml', os.path.abspath('work/PMP/ns01/poldir2.html'), '--journal', os.path.abspath('work/PMP/ns01/pol_journal2.json')]) PMP.run_me(cliClient) os.environ.pop('POLMAN_AODS') assertNoDiff('poldir2.json', subdir='PMP/ns01')
def runTest(self): logging.info( ' -- Test PMPns01: happy cycle: create, append, read, verify; aods via option' ) policy_journal = os.path.abspath('work/PMP/ns01/aods.json') logging.debug('=== removing existing aods file .. ') cliClient = CliPmp(['-v', '-n', '-a', policy_journal, 'scratch']) PMP.run_me(cliClient) logging.debug('=== creating aods file .. ') cliClient = CliPmp(['-v', '-n', '-a', policy_journal, 'create']) PMP.run_me(cliClient) logging.debug('=== create done.') inputfile = os.path.abspath('testdata/PMP/ns01/append01_OK.json') logging.debug('=== appending input file %s .. ' % inputfile) cliClient = CliPmp( ['-v', '-n', '-a', policy_journal, 'append', inputfile]) PMP.run_me(cliClient) logging.debug('=== append done.') inputfile = os.path.abspath( 'testdata/PMP/ns01/append02_delete_non_exist_rec.json') logging.debug('=== appending input file %s .. ' % inputfile) cliClient = CliPmp( ['-v', '-n', '-a', policy_journal, 'append', inputfile]) with self.assertRaises(InputValueError) as context: PMP.run_me(cliClient) logging.debug('=== append done.') inputfile = os.path.abspath( 'testdata/PMP/ns01/append03_delete_non_exist_orgid.json') logging.debug('=== appending input file %s .. ' % inputfile) cliClient = CliPmp( ['-v', '-n', '-a', policy_journal, 'append', inputfile]) with self.assertRaises(InputValueError) as context: PMP.run_me(cliClient) logging.debug('=== append done.') inputfile = os.path.abspath('testdata/PMP/ns01/append04_OK.json') logging.debug('=== appending input file %s .. ' % inputfile) cliClient = CliPmp( ['-v', '-n', '-a', policy_journal, 'append', inputfile]) PMP.run_me(cliClient) logging.debug('=== append done.') logging.debug( '=== reading & dumping policy journal as json, directory as json & html .. ' ) cliClient = CliPmp([ '-v', '-n', '-a', policy_journal, 'read', '--poldirjson', os.path.abspath('work/PMP/ns01/poldir1.json'), '--poldirhtml', os.path.abspath('work/PMP/ns01/poldir1.html'), '--journal', os.path.abspath('work/PMP/ns01/pol_journal1.json') ]) PMP.run_me(cliClient) assertNoDiff('poldir1.json', subdir='PMP/ns01') inputfile = os.path.abspath('testdata/PMP/ns01/append05_OK.json') logging.debug('=== appending input file %s .. ' % inputfile) cliClient = CliPmp( ['-v', '-n', '-a', policy_journal, 'append', inputfile]) PMP.run_me(cliClient) logging.debug('=== append done.') logging.debug( '=== reading & dumping policy journal as json, directory as json & html ..; aods via env var' ) os.environ['POLMAN_AODS'] = policy_journal cliClient = CliPmp([ '-v', '-n', 'read', '--poldirjson', os.path.abspath('work/PMP/ns01/poldir2.json'), '--poldirhtml', os.path.abspath('work/PMP/ns01/poldir2.html'), '--journal', os.path.abspath('work/PMP/ns01/pol_journal2.json') ]) PMP.run_me(cliClient) os.environ.pop('POLMAN_AODS') assertNoDiff('poldir2.json', subdir='PMP/ns01')
def runTest(self): logging.info(' -- Test PMPws01: happy cycle: create, append, read, verify policy journal sig + struct)') pol_journal_fn = 'pol_journal.xml' subdir = 'PMP/ws01/' pol_journal = os.path.join('work', subdir, pol_journal_fn) policyjournal_export = 'work/PMP/ws01/pol_journal_export.json' policydir_json = 'work/PMP/ws01/poldir.json' policydir_html = 'work/PMP/ws01/poldir.html' logging.debug(' removing existing aods file %s .. ' % pol_journal) cliClient = CliPmp(['-v', '-t', 'testdata/trustedcerts.json', '-a', pol_journal, 'scratch']) PMP.run_me(cliClient) logging.debug(' creating aods file .. ') cliClient = CliPmp(['-v', '-t', 'testdata/trustedcerts.json', '-a', pol_journal, 'create']); PMP.run_me(cliClient) inputfile = os.path.abspath('testdata/PMP/ws01/pmp_initial_policy.json') logging.debug(' appending input file %s .. ' % inputfile) cliClient = CliPmp(['-v', '-t', 'testdata/trustedcerts.json', '-a', pol_journal, 'append', inputfile]) PMP.run_me(cliClient) logging.debug(' reading policy journal, exporting policy journal as json.') cliClient = CliPmp(['-v', '-t', 'testdata/trustedcerts.json', '-a', pol_journal, 'read', \ '--journal', policyjournal_export]) PMP.run_me(cliClient) logging.debug(' reading policy journal, exporting policy directory as json.') cliClient = CliPmp(['-v', '-t', 'testdata/trustedcerts.json', '-a', pol_journal, 'read', \ '--poldirjson', policydir_json]) PMP.run_me(cliClient) assertNoDiff('poldir.json', subdir=subdir) logging.debug(' reading policy journal, exporting policy directory as html.') cliClient = CliPmp(['-v', '-t', 'testdata/trustedcerts.json', '-a', pol_journal, 'read', \ '--poldirhtml', policydir_html]) PMP.run_me(cliClient)