Extract credential handling into its own module
Will be used in Docker V1 and APPR protocols
This commit is contained in:
parent
4a5626e64b
commit
6f3d9a6fce
5 changed files with 94 additions and 49 deletions
30
auth/test/test_credentials.py
Normal file
30
auth/test/test_credentials.py
Normal file
|
@ -0,0 +1,30 @@
|
|||
from auth.credentials import ACCESS_TOKEN_USERNAME, OAUTH_TOKEN_USERNAME, validate_credentials
|
||||
from auth.validateresult import AuthKind, ValidateResult
|
||||
from data import model
|
||||
|
||||
from test.fixtures import *
|
||||
|
||||
def test_valid_user(app):
|
||||
result = validate_credentials('devtable', 'password')
|
||||
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 = validate_credentials(robot.username, password)
|
||||
assert result == ValidateResult(AuthKind.credentials, robot=robot)
|
||||
|
||||
def test_valid_token(app):
|
||||
access_token = model.token.create_delegate_token('devtable', 'simple', 'sometoken')
|
||||
result = validate_credentials(ACCESS_TOKEN_USERNAME, access_token.code)
|
||||
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 = validate_credentials(OAUTH_TOKEN_USERNAME, oauth_token.access_token)
|
||||
assert result == ValidateResult(AuthKind.oauth, oauthtoken=oauth_token)
|
||||
|
||||
def test_invalid_user(app):
|
||||
result = validate_credentials('devtable', 'somepassword')
|
||||
assert result == ValidateResult(AuthKind.credentials,
|
||||
error_message='Invalid Username or Password')
|
Reference in a new issue