Exemplo n.º 1
0
 def test_has_pending(self, session, fake_new_account_request, attrs):
     fake_new_account_request = fake_new_account_request._replace(**attrs)
     session.add(
         StoredNewAccountRequest.from_request(fake_new_account_request,
                                              'reason'))
     session.commit()
     assert user_has_request_pending(session, fake_new_account_request)
Exemplo n.º 2
0
 def test_not_has_pending_zero_group(self, session, fake_new_account_request):
     """callink_oid=0 can create infinite accounts."""
     fake_new_account_request = fake_new_account_request._replace(
         is_group=True,
         callink_oid=0,
         calnet_uid=None,
     )
     session.add(StoredNewAccountRequest.from_request(fake_new_account_request, 'reason'))
     session.commit()
     assert not user_has_request_pending(session, fake_new_account_request)
Exemplo n.º 3
0
 def test_not_has_pending_zero_group(self, session, fake_new_account_request):
     """callink_oid=0 can create infinite accounts."""
     fake_new_account_request = fake_new_account_request._replace(
         is_group=True,
         callink_oid=0,
         calnet_uid=None,
     )
     session.add(StoredNewAccountRequest.from_request(fake_new_account_request, 'reason'))
     session.commit()
     assert not user_has_request_pending(session, fake_new_account_request)
Exemplo n.º 4
0
def validate_request(request, credentials, session):
    """Validate a request, returning lists of errors and warnings."""
    from ocflib.account.submission import username_pending
    from ocflib.account.submission import user_has_request_pending

    errors, warnings = [], []

    @contextmanager
    def validate_section():
        try:
            yield
        except ValidationWarning as ex:
            warnings.append(str(ex))
        except ValidationError as ex:
            errors.append(str(ex))

    # TODO: figure out where to sanitize real_name

    # user name
    with validate_section():
        if username_pending(session, request):
            raise ValidationError(
                'Username {} has already been requested.'.format(
                    request.user_name, ))

        validate_username(request.user_name, request.real_name)

    # calnet uid / callink oid
    with validate_section():
        if request.is_group:
            validate_callink_oid(request.callink_oid)
        else:
            validate_calnet_uid(request.calnet_uid)

        if user_has_request_pending(session, request):
            raise ValidationError('You have already requested an account.')

    # email
    with validate_section():
        validate_email(request.email)

    # password
    with validate_section():
        password = decrypt_password(
            request.encrypted_password,
            RSA.importKey(open(credentials.encryption_key).read()),
        )
        validate_password(request.user_name, password)

    return errors, warnings
Exemplo n.º 5
0
def validate_request(request, credentials, session):
    """Validate a request, returning lists of errors and warnings."""
    from ocflib.account.submission import username_pending
    from ocflib.account.submission import user_has_request_pending

    errors, warnings = [], []

    @contextmanager
    def validate_section():
        try:
            yield
        except ValidationWarning as ex:
            warnings.append(str(ex))
        except ValidationError as ex:
            errors.append(str(ex))

    # TODO: figure out where to sanitize real_name

    # user name
    with validate_section():
        if username_pending(session, request):
            raise ValidationError('Username {} has already been requested.'.format(
                request.user_name,
            ))

        validate_username(request.user_name, request.real_name)

    # calnet uid / callink oid
    with validate_section():
        if request.is_group:
            validate_callink_oid(request.callink_oid)
        else:
            validate_calnet_uid(request.calnet_uid)

        if user_has_request_pending(session, request):
            raise ValidationError('You have already requested an account.')

    # email
    with validate_section():
        validate_email(request.email)

    # password
    with validate_section():
        password = decrypt_password(
            request.encrypted_password,
            RSA.importKey(open(credentials.encryption_key).read()),
        )
        validate_password(request.user_name, password)

    return errors, warnings
Exemplo n.º 6
0
 def test_not_has_pending(self, session, fake_new_account_request):
     assert not user_has_request_pending(session, fake_new_account_request)
Exemplo n.º 7
0
 def test_not_has_pending(self, session, fake_new_account_request):
     assert not user_has_request_pending(session, fake_new_account_request)
Exemplo n.º 8
0
 def test_has_pending(self, session, fake_new_account_request, attrs):
     fake_new_account_request = fake_new_account_request._replace(**attrs)
     session.add(StoredNewAccountRequest.from_request(fake_new_account_request, 'reason'))
     session.commit()
     assert user_has_request_pending(session, fake_new_account_request)