def test_valid_app_specific_token(app): user = model.user.get_user("devtable") app_specific_token = model.appspecifictoken.create_token(user, "some token") full_token = model.appspecifictoken.get_full_token_string(app_specific_token) result, kind = validate_credentials(APP_SPECIFIC_TOKEN_USERNAME, full_token) assert kind == CredentialKind.app_specific_token assert result == ValidateResult(AuthKind.credentials, appspecifictoken=app_specific_token)
def test_unicode(app): result, kind = validate_credentials("someusername", "some₪code") assert kind == CredentialKind.user assert not result.auth_valid assert result == ValidateResult( AuthKind.credentials, error_message="Invalid Username or Password" )
def test_apply_context(get_entity, entity_kind, app): assert get_authenticated_context() is None entity = get_entity() args = {} args[entity_kind] = entity result = ValidateResult(AuthKind.basic, **args) result.apply_to_context() expected_user = entity if entity_kind == 'user' or entity_kind == 'robot' else None if entity_kind == 'oauthtoken': expected_user = entity.authorized_user if entity_kind == 'appspecifictoken': expected_user = entity.user expected_token = entity if entity_kind == 'token' else None expected_oauth = entity if entity_kind == 'oauthtoken' else None expected_appspecifictoken = entity if entity_kind == 'appspecifictoken' else None expected_grant = entity if entity_kind == 'signed_data' else None assert get_authenticated_context().authed_user == expected_user assert get_authenticated_context().token == expected_token assert get_authenticated_context().oauthtoken == expected_oauth assert get_authenticated_context( ).appspecifictoken == expected_appspecifictoken assert get_authenticated_context().signed_data == expected_grant
def test_unicode_robot(app): robot, _ = model.user.create_robot("somerobot", model.user.get_user("devtable")) result, kind = validate_credentials(robot.username, "some₪code") assert kind == CredentialKind.robot assert not result.auth_valid msg = "Could not find robot with username: devtable+somerobot and supplied password." assert result == ValidateResult(AuthKind.credentials, error_message=msg)
def test_valid_app_specific_token_for_disabled_user(app): user = model.user.get_user("devtable") user.enabled = False user.save() app_specific_token = model.appspecifictoken.create_token(user, "some token") full_token = model.appspecifictoken.get_full_token_string(app_specific_token) result, kind = validate_credentials(APP_SPECIFIC_TOKEN_USERNAME, full_token) assert kind == CredentialKind.app_specific_token err = "This user has been disabled. Please contact your administrator." assert result == ValidateResult(AuthKind.credentials, error_message=err)