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')
Пример #3
0
    def test_verify_badge_against_expected_profile(self):
        recipient_profile = {'email': '*****@*****.**'}
        url = 'https://example.org/beths-robotics-badge.json'
        assertion = json.loads(test_components['2_0_basic_assertion'])
        assertion['recipient']['identity'] = 'sha256$' + hashlib.sha256(
            recipient_profile['email'].encode('utf8') + assertion['recipient']['salt'].encode('utf8')).hexdigest()

        responses.add(
            responses.GET, url, body=json.dumps(assertion), status=200,
            content_type='application/ld+json'
        )
        set_up_image_mock('https://example.org/beths-robot-badge.png')
        responses.add(
            responses.GET, 'https://w3id.org/openbadges/v2',
            body=test_components['openbadges_context'], status=200,
            content_type='application/ld+json'
        )
        responses.add(
            responses.GET, 'https://example.org/robotics-badge.json',
            body=test_components['2_0_basic_badgeclass'], status=200,
            content_type='application/ld+json'
        )
        set_up_image_mock('https://example.org/robotics-badge.png')
        responses.add(
            responses.GET, 'https://example.org/organization.json',
            body=test_components['2_0_basic_issuer'], status=200,
            content_type='application/ld+json'
        )

        result = verification_store(url, recipient_profile)
        state = result.get_state()
        profile_verification_tasks = filter_tasks(state, name=VERIFY_RECIPIENT_IDENTIFIER)

        self.assertEqual(len(filter_failed_tasks(state)), 0)
        self.assertEqual(len(profile_verification_tasks), 1)
        self.assertTrue(profile_verification_tasks[0]['success'])

        recipient_profile = {'email': ['*****@*****.**', '*****@*****.**']}
        result = verification_store(url, recipient_profile)
        state = result.get_state()
        profile_verification_tasks = filter_tasks(state, name=VERIFY_RECIPIENT_IDENTIFIER)
        self.assertEqual(len(filter_failed_tasks(state)), 0)
        self.assertEqual(len(profile_verification_tasks), 1)
        self.assertTrue(profile_verification_tasks[0]['success'])
    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)