Exemple #1
0
    def validate_basic_standalone_extension_node(self):
        set_up_context_mock()
        self.set_up_test_extension()

        extension_data = {
            '@context': self.extension_context_url,
            '@type': ['Extension', 'extensions:UnknownExtension'],
            'unknownProperty': 'I\'m a property, short and sweet'
        }

        store = extension_validation_store(extension_data)
        report = generate_report(store)

        self.assertTrue(report['report']['valid'])

        extension_data[
            'unknownProperty'] = 42  # provokes extension schema error: should be a string.

        store = extension_validation_store(extension_data)
        report = generate_report(store)

        self.assertFalse(report['report']['valid'])

        del extension_data['@type']
        extension_data['unknownProperty'] = "Ok, valid string again"

        store = extension_validation_store(extension_data)
        report = generate_report(store)

        self.assertFalse(
            report['report']['valid'],
            "Should report an error if there weren't any discoverable extension types to test."
        )
Exemple #2
0
    def test_original_json_option(self):
        store = create_store(main_reducer, INITIAL_STATE)
        store.dispatch(
            store_original_resource('http://example.org/1',
                                    '{"data": "test data"}'))

        report = generate_report(store)
        self.assertNotIn('original_json', list(report['input'].keys()))

        report = generate_report(store, {'include_original_json': True})
        self.assertIn('original_json', list(report['input'].keys()))
 def test_confirmed_recipient_profile_reported(self):
     url = 'https://example.org/beths-robotics-badge.json'
     email = '*****@*****.**'
     self.set_response_mocks()
     store = verification_store(url, recipient_profile={'email': email})
     report = generate_report(store)
     self.assertEqual(report['report']['recipientProfile']['email'], email)
 def test_subject_set_from_badge_image(self):
     with open(os.path.join(os.path.dirname(__file__), 'testfiles', 'public_domain_heart.png'), 'rb') as f:
         image = bake(f, test_components['2_0_basic_assertion'])
         self.set_response_mocks()
         store = verification_store(image)
         report = generate_report(store)
         self.assertEqual(report['report']['validationSubject'], 'https://example.org/beths-robotics-badge.json')
Exemple #5
0
    def test_message_reporting(self):
        store = create_store(main_reducer, INITIAL_STATE)
        store.dispatch(report_message('TEST MESSAGE'))

        state = store.get_state()
        self.assertEqual(len(state['tasks']), 1)

        result = generate_report(store)
        self.assertEqual(len(result['report']['messages']), 1)
        self.assertEqual(result['report']['messages'][0]['result'],
                         'TEST MESSAGE')
    def full_validate_0_5_to_2_0_conversion(self):
        setUpContextCache()
        assertion_url = 'http://example.org/assertion'
        assertion_data = {
            "recipient":
            "sha256$a4a934a0bfc882a34a3e71650e40789453b2db9799a51a2d084a64caadd72397",
            "salt": "2e2bad0df9e11272ffbcee86e4c7edd4",
            "issued_on": "2017-01-01",
            "badge": {
                "name": "Test Badge for [email protected]",
                "image": "http://example.org/image",
                "description": "Awarded using the php example codebase",
                "criteria": "http://example.org/criteria",
                "issuer": {
                    "origin": "http://example.org",
                    "name": "Test Issuer",
                    "org": None,
                    "contact": '*****@*****.**'
                }
            }
        }

        responses.add(responses.GET, assertion_url, json=assertion_data)
        png_badge = os.path.join(os.path.dirname(__file__), 'testfiles',
                                 'public_domain_heart.png')
        with open(png_badge, 'rb') as image:
            responses.add(responses.GET,
                          assertion_data['badge']['image'],
                          body=image.read(),
                          status=200,
                          content_type='image/png')

        store = verification_store(assertion_url)
        state = store.get_state()
        report = generate_report(store)

        self.assertTrue(report['report']['valid'])
        assertion_node = state['graph'][0]
        badgeclass_node = state['graph'][2]
        issuer_node = state['graph'][1]

        self.assertEqual(assertion_node['id'], assertion_url)
        self.assertEqual(badgeclass_node['@context'],
                         OPENBADGES_CONTEXT_V2_URI)
        self.assertEqual(issuer_node['type'], OBClasses.Profile)

        self.assertEqual(report['report']['openBadgesVersion'], '0.5')
    def full_validate_1_0_to_2_0_conversion(self):
        setUpContextCache()
        assertion_data = json.loads(
            test_components['1_0_basic_assertion_with_extra_properties'])
        badgeclass_data = json.loads(test_components['1_0_basic_badgeclass'])
        issuer_data = json.loads(test_components['1_0_basic_issuer'])

        responses.add(responses.GET,
                      assertion_data['verify']['url'],
                      json=assertion_data)
        responses.add(responses.GET,
                      assertion_data['badge'],
                      json=badgeclass_data)
        responses.add(responses.GET,
                      badgeclass_data['issuer'],
                      json=issuer_data)
        png_badge = os.path.join(os.path.dirname(__file__), 'testfiles',
                                 'public_domain_heart.png')
        with open(png_badge, 'rb') as image:
            responses.add(responses.GET,
                          badgeclass_data['image'],
                          body=image.read(),
                          status=200,
                          content_type='image/png')

        store = verification_store(assertion_data['verify']['url'])
        state = store.get_state()
        report = generate_report(store)

        self.assertTrue(report['report']['valid'])
        assertion_node = state['graph'][0]
        badgeclass_node = state['graph'][1]
        issuer_node = state['graph'][2]

        self.assertEqual(assertion_node['id'], assertion_data['verify']['url'])
        self.assertEqual(badgeclass_node['@context'],
                         OPENBADGES_CONTEXT_V2_URI)
        self.assertEqual(issuer_node['type'], OBClasses.Issuer)

        self.assertEqual(report['report']['openBadgesVersion'], '1.0')
 def test_subject_set_from_badge_input(self):
     url = 'https://example.org/beths-robotics-badge.json'
     self.set_response_mocks()
     store = verification_store(url)
     report = generate_report(store)
     self.assertEqual(report['report']['validationSubject'], url)
Exemple #9
0
 def test_valid_when_no_graph(self):
     state = INITIAL_STATE.copy()
     store = create_store(main_reducer, state)
     result = generate_report(store)
     self.assertFalse(result['report']['valid'])