def main(): parser = argparse.ArgumentParser(description='Validates different entries') parser.add_argument('head_input_file', help='JSON file') parser.add_argument('base_input_file', help='JSON file') parser.add_argument('--show-warnings', action='store_true', help='print warnings to the console') args = parser.parse_args() head_entries_from_json = common.read_issuer_entries_from_json_file(args.head_input_file) base_entries_from_json = common.read_issuer_entries_from_json_file(args.base_input_file) ## ensure no duplicate iss values duplicate_entries = common.duplicate_entries(head_entries_from_json) if len(duplicate_entries) > 1: print('Found duplicate entries') for entry in duplicate_entries: print(entry) exit(1) ## only validate new entries and changes diffs = common.compute_diffs(base_entries_from_json, head_entries_from_json) additions = diffs.additions changes = [change.new for change in diffs.changes] if len(additions) + len(changes) == 0: print('No entries have been added or changed') exit(0) print(f'Validating {len(additions)} new entries') for addition in additions: print(addition) print(f'Validating {len(changes)} changed entries') for change in changes: print(change) additions_validation_results = common.validate_entries(additions) additions_valid = common.analyze_results(additions_validation_results, True, args.show_warnings, cors_issue_is_error=True) changes_validation_results = common.validate_entries(changes) changes_valid = common.analyze_results(changes_validation_results, True, args.show_warnings, cors_issue_is_error=True) if additions_valid and changes_valid: print('All entries are valid') exit(0) else: print('One or more entries are invalid') exit(1)
def test_invalid_website_entry(self): entries = [ IssuerEntry('SHC Example Issuer', 'https://spec.smarthealth.cards/examples/issuer', 'https://spec.smarthealth.cards/unknown', None), ] actual = validate_entries(entries) self.assertEqual(actual[0].issuer_entry, entries[0]) self.assertEqual(actual[0].is_valid, False) self.assertEqual(actual[0].issues[0].type, IssueType.WEBSITE_DOES_NOT_RESOLVE)
def test_valid_canonical_iss(self): entries = [ IssuerEntry('State of California', 'https://myvaccinerecord.cdph.ca.gov/creds', None, None), IssuerEntry('State of Louisiana', 'https://healthcardcert.lawallet.com', None, None), IssuerEntry('SHC Example Issuer', 'https://spec.smarthealth.cards/examples/issuer', None, 'https://myvaccinerecord.cdph.ca.gov/creds'), ] actual = validate_entries(entries) expected = [ValidationResult(entry, True, []) for entry in entries] self.assertEqual(actual, expected)
def test_invalid_canonical_iss_multihop_reference(self): entries = [ IssuerEntry('State of California', 'https://myvaccinerecord.cdph.ca.gov/creds', None, None), IssuerEntry('State of Louisiana', 'https://healthcardcert.lawallet.com', None, 'https://myvaccinerecord.cdph.ca.gov/creds'), IssuerEntry('SHC Example Issuer', 'https://spec.smarthealth.cards/examples/issuer', None, 'https://healthcardcert.lawallet.com'), ] actual = validate_entries(entries) self.assertEqual(actual[0].issuer_entry, entries[0]) self.assertEqual(actual[0].is_valid, True) self.assertEqual(actual[0].issues, []) self.assertEqual(actual[1].issuer_entry, entries[1]) self.assertEqual(actual[1].is_valid, True) self.assertEqual(actual[1].issues, []) self.assertEqual(actual[2].issuer_entry, entries[2]) self.assertEqual(actual[2].is_valid, False) self.assertEqual(actual[2].issues[0].type, IssueType.CANONICAL_ISS_MULTIHOP_REFERENCE)
def test_valid_and_invalid_entry(self): entries = [ IssuerEntry('SHC Example Issuer', 'https://spec.smarthealth.cards/examples/issuer', None, None), IssuerEntry('Invalid issuer 1', 'https://spec.smarthealth.cards/examples/iss', None, None), IssuerEntry('Invalid issuer 2', 'https://spec.smarthealth.cards/examples/issuer/', None, None), ] actual = validate_entries(entries) self.assertEqual(actual[0].issuer_entry, entries[0]) self.assertEqual(actual[0].is_valid, True) self.assertEqual(actual[0].issues, []) self.assertEqual(actual[1].issuer_entry, entries[1]) self.assertEqual(actual[1].is_valid, False) self.assertEqual(actual[1].issues[0].type, IssueType.FETCH_EXCEPTION) self.assertEqual(actual[2].issuer_entry, entries[2]) self.assertEqual(actual[2].is_valid, False) self.assertEqual(actual[2].issues[0].type, IssueType.ISS_ENDS_WITH_TRAILING_SLASH)
def test_validate_entries1(self): entries = [ IssuerEntry('SHC Example Issuer 1', 'https://spec.smarthealth.cards/examples/issuer', 'https://smarthealth.cards/', None), IssuerEntry('SHC Example Issuer 2', 'https://spec.smarthealth.cards/examples/issuer', 'https://spec.smarthealth.cards/', None), IssuerEntry('SHC Example Issuer 3', 'https://spec.smarthealth.cards/examples/issuer', None, None), IssuerEntry('SHC Example Issuer 4', 'https://spec.smarthealth.cards/examples/issuer', None, None), IssuerEntry('SHC Example Issuer 5', 'https://spec.smarthealth.cards/examples/issuer', None, None), IssuerEntry('SHC Example Issuer 6', 'https://spec.smarthealth.cards/examples/issuer', None, None), IssuerEntry('SHC Example Issuer 7', 'https://spec.smarthealth.cards/examples/issuer', None, None), IssuerEntry('SHC Example Issuer 8', 'https://spec.smarthealth.cards/examples/issuer', None, None), IssuerEntry('SHC Example Issuer 9', 'https://spec.smarthealth.cards/examples/issuer', None, None), IssuerEntry('SHC Example Issuer 10', 'https://spec.smarthealth.cards/examples/issuer', None, None) ] actual = validate_entries(entries) expected = [ValidationResult(entry, True, []) for entry in entries] self.assertEqual(actual, expected)