36 lines
1.6 KiB
Python
36 lines
1.6 KiB
Python
from auth.credentials import (ACCESS_TOKEN_USERNAME, OAUTH_TOKEN_USERNAME, validate_credentials,
|
|
CredentialKind)
|
|
from auth.validateresult import AuthKind, ValidateResult
|
|
from data import model
|
|
|
|
from test.fixtures import *
|
|
|
|
def test_valid_user(app):
|
|
result, kind = validate_credentials('devtable', 'password')
|
|
assert kind == CredentialKind.user
|
|
assert result == ValidateResult(AuthKind.credentials, user=model.user.get_user('devtable'))
|
|
|
|
def test_valid_robot(app):
|
|
robot, password = model.user.create_robot('somerobot', model.user.get_user('devtable'))
|
|
result, kind = validate_credentials(robot.username, password)
|
|
assert kind == CredentialKind.robot
|
|
assert result == ValidateResult(AuthKind.credentials, robot=robot)
|
|
|
|
def test_valid_token(app):
|
|
access_token = model.token.create_delegate_token('devtable', 'simple', 'sometoken')
|
|
result, kind = validate_credentials(ACCESS_TOKEN_USERNAME, access_token.code)
|
|
assert kind == CredentialKind.token
|
|
assert result == ValidateResult(AuthKind.credentials, token=access_token)
|
|
|
|
def test_valid_oauth(app):
|
|
user = model.user.get_user('devtable')
|
|
oauth_token = list(model.oauth.list_access_tokens_for_user(user))[0]
|
|
result, kind = validate_credentials(OAUTH_TOKEN_USERNAME, oauth_token.access_token)
|
|
assert kind == CredentialKind.oauth_token
|
|
assert result == ValidateResult(AuthKind.oauth, oauthtoken=oauth_token)
|
|
|
|
def test_invalid_user(app):
|
|
result, kind = validate_credentials('devtable', 'somepassword')
|
|
assert kind == CredentialKind.user
|
|
assert result == ValidateResult(AuthKind.credentials,
|
|
error_message='Invalid Username or Password')
|