예제 #1
0
    def test_validate_saml2int(self):
        """ -- Test API with profile saml2int against idp_incomplete.xml """
        logging.info(TestValidator.test_validate_saml2int.__doc__)
        print(TestValidator.test_validate_saml2int.__doc__)
        PROJROOT = os.path.dirname(os.path.dirname(__file__))
        logging.info('PROJROOT=' + PROJROOT)
        md_fname = os.path.join(PROJROOT, 'testdata', 'idp_incomplete.xml')
        #profile_fname = os.path.join(PROJROOT, 'rules', 'profiles', 'saml2int.json')
        import pkgdata
        profile_fname = pkgdata.get_path(
            'rules', os.path.join('profiles', 'saml2int.json'))
        validator = Validator(
            ApiArgs(md_xml=md_fname, profile=profile_fname).cliInvocation)
        val_result = validator.validate()

        workdir = os.path.join(PROJROOT, 'work')
        if not os.path.exists(workdir):
            os.makedirs(workdir)
        fname = os.path.join(workdir, 'saml2int.json')
        with open(fname, 'w') as fd:
            fd.write(val_result.get_json())
        try:
            assertNoDiff(fname)
        except (AssertionError, FileNotFoundError) as e:
            print(e)
예제 #2
0
    def runTest(self):
        logging.info(
            '  -- Test PAT06a: create PMP import file for CA root certificate')
        certificate_file = os.path.abspath(
            'testdata/PAT/06/StartComCa_root.pem')
        pmpinput_file = make_dirs(
            os.path.abspath('work/PAT/06/StartComCa_root.json'))  # output
        cliClient = CliPatool([
            '-v', 'caCert', '--certfile', certificate_file, '--pvprole', 'IDP',
            pmpinput_file
        ])
        PAtool.run_me(cliClient)
        assertNoDiff(os.path.basename(pmpinput_file), subdir='PAT/06')

        logging.info(
            '  -- Test PAT06b: create PMP import file for CA intermediate certificate'
        )
        certificate_file = os.path.abspath(
            'testdata/PAT/06/StartComCa_intermed.pem')
        pmpinput_file = os.path.abspath(
            'work/PAT/06/StartComCa_intermed.json')  # output
        cliClient = CliPatool([
            '-v', 'caCert', '--certfile', certificate_file, '--pvprole', 'IDP',
            pmpinput_file
        ])
        PAtool.run_me(cliClient)
        assertNoDiff(os.path.basename(pmpinput_file), subdir='PAT/06')
예제 #3
0
 def runTest(self):
     logging.info('  -- Test PAT05: create PMP import file to revoke a certificate')
     certificate_file = os.path.abspath('testdata/PAT/05/gondorMagwienGvAt_2011-cer.pem')
     pmpinput_file = make_dirs(os.path.abspath('work/PAT/05/gondorMagwienGvAt_2011-cer_revoke.json'))  # output
     cliClient = CliPatool(['-v', 'revokeCert',
                            '--certfile', certificate_file,
                            '--reason', 'testing revocation',
                            pmpinput_file])
     PAtool.run_me(cliClient)
     assertNoDiff(os.path.basename(pmpinput_file), subdir='PAT/05')
예제 #4
0
 def runTest(self):
     logging.info('  -- Test PAT01: create EntitDescriptor from certificate (pvzd:pvptype="R-Profile")')
     certificate_file = os.path.abspath('testdata/PAT/01/redmineIdentineticsCom-cer.pem')
     entitydescriptor_file = 'redmineIdentineticsCom_idpXml.unsigned.xml'
     output_dir = make_dirs(os.path.abspath('work/PAT/01/'), dir=True)
     cliClient = CliPatool(['-v', 'createED',
                         '-e', 'https://redmine.identinetics.com/idp.xml',
                         '-r', 'IDP',
                         '-o', output_dir,
                         certificate_file])
     PAtool.run_me(cliClient)
     assertNoDiff(os.path.basename(entitydescriptor_file), subdir='PAT/01')
예제 #5
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)
예제 #6
0
 def runTest(self):
     logging.info(
         '  -- Test PAT01: create EntitDescriptor from certificate (pvzd:pvptype="R-Profile")'
     )
     certificate_file = os.path.abspath(
         'testdata/PAT/01/redmineIdentineticsCom-cer.pem')
     entitydescriptor_file = 'redmineIdentineticsCom_idpXml.unsigned.xml'
     output_dir = make_dirs(os.path.abspath('work/PAT/01/'), dir=True)
     cliClient = CliPatool([
         '-v', 'createED', '-e', 'https://redmine.identinetics.com/idp.xml',
         '-r', 'IDP', '-o', output_dir, certificate_file
     ])
     PAtool.run_me(cliClient)
     assertNoDiff(os.path.basename(entitydescriptor_file), subdir='PAT/01')
예제 #7
0
 def runTest(self):
     logging.info(
         '  -- Test PAT05: create PMP import file to revoke a certificate')
     certificate_file = os.path.abspath(
         'testdata/PAT/05/gondorMagwienGvAt_2011-cer.pem')
     pmpinput_file = make_dirs(
         os.path.abspath(
             'work/PAT/05/gondorMagwienGvAt_2011-cer_revoke.json')
     )  # output
     cliClient = CliPatool([
         '-v', 'revokeCert', '--certfile', certificate_file, '--reason',
         'testing revocation', pmpinput_file
     ])
     PAtool.run_me(cliClient)
     assertNoDiff(os.path.basename(pmpinput_file), subdir='PAT/05')
예제 #8
0
    def runTest(self):
        logging.info('  -- Test PAT06a: create PMP import file for CA root certificate')
        certificate_file = os.path.abspath('testdata/PAT/06/StartComCa_root.pem')
        pmpinput_file = make_dirs(os.path.abspath('work/PAT/06/StartComCa_root.json'))  # output
        cliClient = CliPatool(['-v', 'caCert',
                               '--certfile', certificate_file,
                               '--pvprole', 'IDP',
                               pmpinput_file])
        PAtool.run_me(cliClient)
        assertNoDiff(os.path.basename(pmpinput_file), subdir='PAT/06')

        logging.info('  -- Test PAT06b: create PMP import file for CA intermediate certificate')
        certificate_file = os.path.abspath('testdata/PAT/06/StartComCa_intermed.pem')
        pmpinput_file = os.path.abspath('work/PAT/06/StartComCa_intermed.json')  # output
        cliClient = CliPatool(['-v', 'caCert',
                               '--certfile', certificate_file,
                               '--pvprole', 'IDP',
                               pmpinput_file])
        PAtool.run_me(cliClient)
        assertNoDiff(os.path.basename(pmpinput_file), subdir='PAT/06')
    def test_validate_saml2int(self):
        """ -- Test API with profile saml2int against idp_incomplete.xml """
        logging.info(TestValidator.test_validate_saml2int.__doc__)
        print(TestValidator.test_validate_saml2int.__doc__)
        PROJROOT = os.path.dirname(os.path.dirname(__file__))
        logging.info('PROJROOT=' + PROJROOT)
        md_fname = os.path.join(PROJROOT, 'testdata', 'idp_incomplete.xml')
        #profile_fname = os.path.join(PROJROOT, 'rules', 'profiles', 'saml2int.json')
        import pkgdata
        profile_fname =  pkgdata.get_path('rules', os.path.join('profiles', 'saml2int.json'))
        validator = Validator(ApiArgs(md_xml=md_fname, profile=profile_fname).cliInvocation)
        val_result = validator.validate()

        workdir = os.path.join(PROJROOT, 'work')
        if not os.path.exists(workdir):
            os.makedirs(workdir)
        fname = os.path.join(workdir, 'saml2int.json')
        with open(fname, 'w') as fd:
            fd.write(val_result.get_json())
        try:
            assertNoDiff(fname)
        except (AssertionError, FileNotFoundError) as e:
            print(e)
예제 #10
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)
예제 #11
0
    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')
예제 #12
0
    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')
예제 #13
0
def assert_no_diff(test_no, file, subdir):
    assertNoDiff(os.path.join(testdatadir, test_no, 'expected_output'),
                 testout,
                 file,
                 subdir=subdir)