aboutsummaryrefslogtreecommitdiffstats
path: root/keystone-moon/keystone
diff options
context:
space:
mode:
Diffstat (limited to 'keystone-moon/keystone')
-rw-r--r--keystone-moon/keystone/contrib/moon/controllers.py40
-rw-r--r--keystone-moon/keystone/contrib/moon/routers.py8
-rw-r--r--keystone-moon/keystone/tests/moon/func/test_func_moon_auth.py48
3 files changed, 95 insertions, 1 deletions
diff --git a/keystone-moon/keystone/contrib/moon/controllers.py b/keystone-moon/keystone/contrib/moon/controllers.py
index 0abe31be..248aea34 100644
--- a/keystone-moon/keystone/contrib/moon/controllers.py
+++ b/keystone-moon/keystone/contrib/moon/controllers.py
@@ -4,12 +4,13 @@
# or at 'http://www.apache.org/licenses/LICENSE-2.0'.
from keystone.common import controller
-from keystone.common import dependency
from keystone import config
from keystone.models import token_model
from keystone.contrib.moon.exception import *
from oslo_log import log
from uuid import uuid4
+import requests
+
CONF = config.CONF
LOG = log.getLogger(__name__)
@@ -831,3 +832,40 @@ class Logs(controller.V3Controller):
options = kw.get('options', '')
return self.moonlog_api.get_logs(user_id, options)
+
+class MoonAuth(controller.V3Controller):
+
+ def __init__(self):
+ super(MoonAuth, self).__init__()
+
+ def get_token(self, context, **kw):
+ data_auth = {
+ "auth": {
+ "identity": {
+ "methods": [
+ "password"
+ ],
+ "password": {
+ "user": {
+ "domain": {
+ "id": "Default"
+ },
+ "name": kw['username'],
+ "password": kw['password']
+ }
+ }
+ }
+ }
+ }
+
+ req = requests.post("http://localhost:5000/v3/auth/tokens",
+ json=data_auth,
+ headers={"Content-Type": "application/json"}
+ )
+ if req.status_code not in (200, 201):
+ LOG.error(req.text)
+ else:
+ TOKEN = req.headers['X-Subject-Token']
+ return {"token": TOKEN, 'message': ""}
+ return {"token": None, 'message': req.text}
+
diff --git a/keystone-moon/keystone/contrib/moon/routers.py b/keystone-moon/keystone/contrib/moon/routers.py
index fd821a49..c3bb7df0 100644
--- a/keystone-moon/keystone/contrib/moon/routers.py
+++ b/keystone-moon/keystone/contrib/moon/routers.py
@@ -36,6 +36,7 @@ class Routers(wsgi.ComposableRouter):
intra_ext_controller = controllers.IntraExtensions()
tenants_controller = controllers.Tenants()
logs_controller = controllers.Logs()
+ auth_controller = controllers.MoonAuth()
inter_ext_controller = controllers.InterExtensions()
# Configuration route
@@ -480,6 +481,13 @@ class Routers(wsgi.ComposableRouter):
action='get_logs',
conditions=dict(method=['GET']))
+ # Auth route
+ mapper.connect(
+ self.PATH_PREFIX+'/auth/tokens',
+ controller=auth_controller,
+ action='get_token',
+ conditions=dict(method=['POST']))
+
# InterExtensions route
# mapper.connect(
# controller=inter_ext_controller,
diff --git a/keystone-moon/keystone/tests/moon/func/test_func_moon_auth.py b/keystone-moon/keystone/tests/moon/func/test_func_moon_auth.py
new file mode 100644
index 00000000..56132609
--- /dev/null
+++ b/keystone-moon/keystone/tests/moon/func/test_func_moon_auth.py
@@ -0,0 +1,48 @@
+# Copyright 2015 Open Platform for NFV Project, Inc. and its contributors
+# This software is distributed under the terms and conditions of the 'Apache-2.0'
+# license which can be found in the file 'LICENSE' in this package distribution
+# or at 'http://www.apache.org/licenses/LICENSE-2.0'.
+
+import unittest
+import json
+import requests
+
+
+class AuthTest(unittest.TestCase):
+
+ def setUp(self):
+ self.data_auth = {
+ "username": "",
+ "password": ""
+ }
+
+ def tearDown(self):
+ pass
+
+ def test_authz(self):
+ self.data_auth['username'] = 'admin'
+ self.data_auth['password'] = ''
+ req = requests.post("http://localhost:5000/moon/auth/tokens",
+ json=self.data_auth,
+ headers={"Content-Type": "application/json"}
+ )
+ self.assertIn(req.status_code, (200, 201))
+ result = req.json()
+ self.assertIn("token", result.keys())
+ self.assertEqual(result["token"], None)
+
+ self.data_auth['username'] = 'admin'
+ self.data_auth['password'] = 'nomoresecrete'
+ req = requests.post("http://localhost:5000/moon/auth/tokens",
+ json=self.data_auth,
+ headers={"Content-Type": "application/json"}
+ )
+ self.assertIn(req.status_code, (200, 201))
+ result = req.json()
+ self.assertIn("token", result.keys())
+ self.assertNotEqual(result["token"], None)
+
+if __name__ == "__main__":
+ unittest.main()
+
+