Ejemplo n.º 1
0
def test_verify_phone_phone_not_found(session, mock_normalize_number):
    vc_obj = VerificationCodeFactory.build()
    session.add(vc_obj)
    session.commit()

    args = {
        'eth_address': str_eth(sample_eth_address),
        'phone': 'garbage',
        'code': vc_obj.code
    }
    with pytest.raises(PhoneVerificationError) as service_err:
        VerificationService.verify_phone(**args)

    assert str(service_err.value) == 'The given phone number was not found.'
Ejemplo n.º 2
0
def test_verify_phone_wrong_code(session, mock_normalize_number):
    vc_obj = VerificationCodeFactory.build()
    session.add(vc_obj)
    session.commit()

    args = {
        'eth_address': str_eth(sample_eth_address),
        'phone': vc_obj.phone,
        'code': 'garbage'
    }
    with pytest.raises(PhoneVerificationError) as service_err:
        VerificationService.verify_phone(**args)

    assert str(service_err.value) == 'The code you provided is invalid.'
Ejemplo n.º 3
0
def test_verify_phone_expired_code(session, mock_normalize_number):
    vc_obj = VerificationCodeFactory.build()
    vc_obj.expires_at = utcnow() - datetime.timedelta(days=1)
    session.add(vc_obj)
    session.commit()

    args = {
        'eth_address': str_eth(sample_eth_address),
        'phone': vc_obj.phone,
        'code': vc_obj.code
    }
    with pytest.raises(PhoneVerificationError) as service_err:
        VerificationService.verify_phone(**args)

    assert str(service_err.value) == 'The code you provided has expired.'
def test_verify_phone_valid_code():
    responses.add(
        responses.GET,
        'https://api.authy.com/protected/json/phones/verification/check',
        json={
            'message': 'Verification code is correct.',
            'success': True
        }
    )

    args = {
        'eth_address': str_eth(sample_eth_address),
        'country_calling_code': '1',
        'phone': '12341234',
        'code': '123456'
    }
    response = VerificationService.verify_phone(**args)
    assert isinstance(response, VerificationServiceResponse)

    assert len(response.data['signature']) == SIGNATURE_LENGTH
    assert response.data['claim_type'] == CLAIM_TYPES['phone']
    assert response.data['data'] == 'phone verified'

    attestations = Attestation.query.all()
    assert(len(attestations)) == 1
    assert(attestations[0].method) == AttestationTypes.PHONE
    assert(attestations[0].value) == "1 12341234"
Ejemplo n.º 5
0
def test_verify_phone_valid_code(app):
    responses.add(
        responses.GET,
        'https://api.authy.com/protected/json/phones/verification/check',
        json={
            'message': 'Verification code is correct.',
            'success': True
        })

    args = {
        'eth_address': str_eth(sample_eth_address),
        'country_calling_code': '1',
        'phone': '12341234',
        'code': '123456'
    }

    with mock.patch('logic.attestation_service.session', dict()) as session:
        session['phone_verification_method'] = 'sms'
        with app.test_request_context():
            response = VerificationService.verify_phone(**args)
    assert isinstance(response, VerificationServiceResponse)

    assert response.data['signature']['version'] == '1.0.0'
    assert len(response.data['signature']['bytes']) == SIGNATURE_LENGTH
    assert response.data[
        'schemaId'] == 'https://schema.originprotocol.com/attestation_1.0.0.json'
    validate_issuer(response.data['data']['issuer'])
    assert response.data['data']['issueDate']
    assert response.data['data']['attestation']['verificationMethod']['sms']
    assert response.data['data']['attestation']['phone']['verified']

    attestations = Attestation.query.all()
    assert (len(attestations)) == 1
    assert (attestations[0].method) == AttestationTypes.PHONE
    assert (attestations[0].value) == "1 12341234"
Ejemplo n.º 6
0
def test_verify_phone_invalid_code():
    responses.add(
        responses.GET,
        'https://api.authy.com/protected/json/phones/verification/check',
        json={'error_code': '60022'},  # No pending verification
        status=401)

    args = {
        'eth_address': str_eth(sample_eth_address),
        'country_calling_code': '1',
        'phone': '12341234',
        'code': 'garbage'
    }
    with pytest.raises(ValidationError) as validation_err:
        VerificationService.verify_phone(**args)

    assert (
        validation_err.value.messages[0]) == 'Verification code is incorrect.'
    assert (validation_err.value.field_names[0]) == 'code'
Ejemplo n.º 7
0
def test_verify_phone_expired_code():
    responses.add(
        responses.GET,
        'https://api.authy.com/protected/json/phones/verification/check',
        json={'error_code': '60023'},  # No pending verification
        status=404)

    args = {
        'eth_address': str_eth(sample_eth_address),
        'country_calling_code': '1',
        'phone': '12341234',
        'code': '123456'
    }
    with mock.patch('logic.attestation_service.session', dict()) as session:
        session['phone_verification_method'] = 'call'
        with pytest.raises(ValidationError) as validation_err:
            VerificationService.verify_phone(**args)

    assert (
        validation_err.value.messages[0]) == 'Verification code has expired.'
    assert (validation_err.value.field_names[0]) == 'code'
Ejemplo n.º 8
0
def test_verify_phone_valid_code(session, mock_normalize_number):
    vc_obj = VerificationCodeFactory.build()
    session.add(vc_obj)
    session.commit()

    args = {
        'eth_address': str_eth(sample_eth_address),
        'phone': vc_obj.phone,
        'code': vc_obj.code
    }
    resp = VerificationService.verify_phone(**args)
    assert isinstance(resp, VerificationServiceResponse)
    resp_data = resp.data

    assert len(resp_data['signature']) == SIGNATURE_LENGTH
    assert resp_data['claim_type'] == CLAIM_TYPES['phone']
    assert resp_data['data'] == 'phone verified'