summaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
authorSerena Feng <feng.xiaowei@zte.com.cn>2017-10-23 01:27:12 +0000
committerGerrit Code Review <gerrit@opnfv.org>2017-10-23 01:27:12 +0000
commit5ec8f63f0d6c2980f3ebe27572e1a3ad7e16a824 (patch)
treeabc11252f5ad7baf497bf638e3400a2f776a95c2 /utils
parentca745dbf6dd3dbc5642fae6b6397e878b6eb8aca (diff)
parent410025769a5f59469722704cdb1d53bfe1d20ba0 (diff)
Merge "allow authentication to be disabled"
Diffstat (limited to 'utils')
-rw-r--r--utils/test/testapi/etc/config.ini3
-rw-r--r--utils/test/testapi/opnfv_testapi/cmd/server.py2
-rw-r--r--utils/test/testapi/opnfv_testapi/common/check.py3
-rw-r--r--utils/test/testapi/opnfv_testapi/tests/unit/common/test_config.py3
-rw-r--r--utils/test/testapi/opnfv_testapi/ui/auth/user.py15
5 files changed, 18 insertions, 8 deletions
diff --git a/utils/test/testapi/etc/config.ini b/utils/test/testapi/etc/config.ini
index 8d0bde20b..86cb0caa7 100644
--- a/utils/test/testapi/etc/config.ini
+++ b/utils/test/testapi/etc/config.ini
@@ -16,7 +16,8 @@ results_per_page = 20
# With debug_on set to true, error traces will be shown in HTTP responses
debug = True
-authenticate = False
+token_check = False
+authenticate = True
[ui]
url = http://localhost:8000
diff --git a/utils/test/testapi/opnfv_testapi/cmd/server.py b/utils/test/testapi/opnfv_testapi/cmd/server.py
index b7d3caa20..011a6cd6e 100644
--- a/utils/test/testapi/opnfv_testapi/cmd/server.py
+++ b/utils/test/testapi/opnfv_testapi/cmd/server.py
@@ -42,7 +42,7 @@ def make_app():
return swagger.Application(
url_mappings.mappings,
debug=CONF.api_debug,
- auth=CONF.api_authenticate,
+ auth=CONF.api_token_check,
cookie_secret='opnfv-testapi',
)
diff --git a/utils/test/testapi/opnfv_testapi/common/check.py b/utils/test/testapi/opnfv_testapi/common/check.py
index 1dff37a67..667578fed 100644
--- a/utils/test/testapi/opnfv_testapi/common/check.py
+++ b/utils/test/testapi/opnfv_testapi/common/check.py
@@ -14,13 +14,14 @@ from tornado import gen
from opnfv_testapi.common import constants
from opnfv_testapi.common import message
from opnfv_testapi.common import raises
+from opnfv_testapi.common.config import CONF
from opnfv_testapi.db import api as dbapi
def is_authorized(method):
@functools.wraps(method)
def wrapper(self, *args, **kwargs):
- if self.table in ['pods']:
+ if CONF.api_authenticate and self.table in ['pods']:
testapi_id = self.get_secure_cookie(constants.TESTAPI_ID)
if not testapi_id:
raises.Unauthorized(message.not_login())
diff --git a/utils/test/testapi/opnfv_testapi/tests/unit/common/test_config.py b/utils/test/testapi/opnfv_testapi/tests/unit/common/test_config.py
index ea2297275..6d160ce1d 100644
--- a/utils/test/testapi/opnfv_testapi/tests/unit/common/test_config.py
+++ b/utils/test/testapi/opnfv_testapi/tests/unit/common/test_config.py
@@ -12,7 +12,8 @@ def test_config_normal(mocker, config_normal):
assert CONF.mongo_dbname == 'test_results_collection'
assert CONF.api_port == 8000
assert CONF.api_debug is True
- assert CONF.api_authenticate is False
+ assert CONF.api_token_check is False
+ assert CONF.api_authenticate is True
assert CONF.ui_url == 'http://localhost:8000'
diff --git a/utils/test/testapi/opnfv_testapi/ui/auth/user.py b/utils/test/testapi/opnfv_testapi/ui/auth/user.py
index ab86007f1..ff2c2a993 100644
--- a/utils/test/testapi/opnfv_testapi/ui/auth/user.py
+++ b/utils/test/testapi/opnfv_testapi/ui/auth/user.py
@@ -1,5 +1,6 @@
from opnfv_testapi.common import constants
from opnfv_testapi.common import raises
+from opnfv_testapi.common.config import CONF
from opnfv_testapi.resources import handlers
from opnfv_testapi.resources import models
@@ -19,8 +20,14 @@ class UserHandler(handlers.GenericApiHandler):
self.table_cls = User
def get(self):
- username = self.get_secure_cookie(constants.TESTAPI_ID)
- if username:
- self._get_one(query={'user': username})
+ if CONF.api_authenticate:
+ username = self.get_secure_cookie(constants.TESTAPI_ID)
+ if username:
+ self._get_one(query={'user': username})
+ else:
+ raises.Unauthorized('Unauthorized')
else:
- raises.Unauthorized('Unauthorized')
+ self.finish_request(User('anonymous',
+ 'anonymous@linuxfoundation.com',
+ 'anonymous lf',
+ constants.TESTAPI_USERS).format())