Test for auth/__init__ validate function
This is just an initial test to start stubbing out the auth test code. We can add here, and add more auth tests into this directory. Change-Id: If8063a00af58a4a6d59fa7c93900e25029950c95
This commit is contained in:
parent
fc52671ad0
commit
d81cfb08cd
0
tests/auth/__init__.py
Normal file
0
tests/auth/__init__.py
Normal file
48
tests/auth/test_init.py
Normal file
48
tests/auth/test_init.py
Normal file
@ -0,0 +1,48 @@
|
||||
# -*- coding:utf-8 -*-
|
||||
#
|
||||
# Copyright 2015 Nebula Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
import mock
|
||||
import os
|
||||
import unittest
|
||||
|
||||
from pecan import conf
|
||||
|
||||
|
||||
class AuthInitTests(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(AuthInitTests, self).setUp()
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
def test_validate(self):
|
||||
config = 'pecan.conf.__values__'
|
||||
data = {'auth': {'static': {'secret': 'simplepassword',
|
||||
'user': 'myusername'},
|
||||
}
|
||||
}
|
||||
with mock.patch.dict(config, data):
|
||||
# can't import until mock'd
|
||||
from anchor import auth
|
||||
from anchor.auth.results import AUTH_FAILED
|
||||
from anchor.auth.results import AuthDetails
|
||||
|
||||
valid_user = data['auth']['static']['user']
|
||||
valid_pass = data['auth']['static']['secret']
|
||||
|
||||
expected = AuthDetails(username=valid_user, groups=[])
|
||||
assert (auth.validate(valid_user, valid_pass) == expected)
|
||||
assert (auth.validate(valid_user, 'badpass') == AUTH_FAILED)
|
Loading…
x
Reference in New Issue
Block a user