[X2Go-Commits] [x2gobroker] 17/17: HTTP broker: Add &login=<server_user> support to plain and json broker frontends.

git-admin at x2go.org git-admin at x2go.org
Fri Dec 14 09:56:13 CET 2018


This is an automated email from the git hooks/post-receive script.

x2go pushed a commit to branch master
in repository x2gobroker.

commit 9fa371e903671dcc6c7eef8bd0cbefd83f1e067f
Author: Mike Gabriel <mike.gabriel at das-netzwerkteam.de>
Date:   Fri Dec 14 09:53:42 2018 +0100

    HTTP broker: Add &login=<server_user> support to plain and json broker frontends.
---
 debian/changelog                        |  2 ++
 x2gobroker/tests/test_web_plain_base.py | 21 +++++++++++++++++++++
 x2gobroker/web/json.py                  | 19 +++++++++++--------
 x2gobroker/web/plain.py                 | 19 +++++++++++--------
 4 files changed, 45 insertions(+), 16 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 752f29c..24d8990 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -83,6 +83,8 @@ x2gobroker (0.0.4.0-0x2go1) UNRELEASED; urgency=medium
     - x2gobroker/loadchecker.py: Avoid rare cases where at the end of a load
       checking cycle a negative sleep time would have been calculated.
       (Fixes: #1315). Thanks to Walid Moghrabi for catching this.
+    - HTTP broker: Add &login=<server_user> support to plain and json broker
+      frontends.
     - SSH broker: Add --login option. This now supports X2Go Broker user and
       X2Go Server username being different accounts.
     - bin/x2gobroker: Correctly use split_host_address() function call.
diff --git a/x2gobroker/tests/test_web_plain_base.py b/x2gobroker/tests/test_web_plain_base.py
index 0e6e255..35b2718 100644
--- a/x2gobroker/tests/test_web_plain_base.py
+++ b/x2gobroker/tests/test_web_plain_base.py
@@ -83,6 +83,27 @@ auth-mech = testsuite
         r.mustcontain('Access granted')
         x2gobroker.defaults.X2GOBROKER_CONFIG = _cf_bak
 
+    ### TEST RESPONSE: simple authentication with user name and login name (check_access)
+
+    def test_checkaccess_user_and_login(self):
+        testApp = TestApp(application)
+        r = testApp.get('/plain/base/', expect_errors=True)
+        assert_equal(r.status, 404)
+        _config = """
+[broker_base]
+enable = true
+auth-mech = testsuite
+"""
+        tf = tempfile.NamedTemporaryFile(mode='w')
+        tf.write(_config)
+        tf.seek(0)
+        _cf_bak = x2gobroker.defaults.X2GOBROKER_CONFIG
+        x2gobroker.defaults.X2GOBROKER_CONFIG = tf.name
+        r = testApp.get('/plain/base/', params={'user': 'test', 'login': 'test_user_on_server', 'password': 'sweet', }, expect_errors=True)
+        assert_equal(r.status, 200)
+        r.mustcontain('Access granted')
+        x2gobroker.defaults.X2GOBROKER_CONFIG = _cf_bak
+
     ### TEST RESPONSE: simple authentication with accentuated chars in password (check_access)
 
     def test_checkaccess_with_accentuated_chars(self):
diff --git a/x2gobroker/web/json.py b/x2gobroker/web/json.py
index c96c2ef..a802866 100644
--- a/x2gobroker/web/json.py
+++ b/x2gobroker/web/json.py
@@ -105,7 +105,10 @@ class X2GoBrokerWeb(_RequestHandler):
             logger_error.error('client could not provide an IP address, pretending: 404 Not Found')
             raise tornado.web.HTTPError(404)
 
-        username = self.get_argument('user', default='')
+        broker_username = self.get_argument('user', default='')
+        server_username = self.get_argument('login', default='')
+        if not server_username:
+            server_username = broker_username
         password = self.get_argument('password', default='', strip=False)
         cookie = self.get_argument('authid', default='')
         pubkey = self.get_argument('pubkey', default='')
@@ -121,12 +124,12 @@ class X2GoBrokerWeb(_RequestHandler):
             'task': task,
         }
 
-        username, password, task, profile_id, ip, cookie, authed, server = broker_backend.run_optional_script(script_type='pre_auth_scripts', username=username, password=password, task=task, profile_id=profile_id, ip=ip, cookie=cookie)
+        broker_username, password, task, profile_id, ip, cookie, authed, server = broker_backend.run_optional_script(script_type='pre_auth_scripts', username=broker_username, password=password, task=task, profile_id=profile_id, ip=ip, cookie=cookie)
 
-        logger_broker.debug ('username: {username}, password: {password}, task: {task}, profile_id: {profile_id}, cookie: {cookie}'.format(username=username, password='XXXXX', task=task, profile_id=profile_id, cookie=cookie))
-        access, next_cookie = broker_backend.check_access(username=username, password=password, ip=ip, cookie=cookie)
+        logger_broker.debug ('username: {username}, password: {password}, task: {task}, profile_id: {profile_id}, cookie: {cookie}'.format(broker_username=broker_username, server_username=server_username, password='XXXXX', task=task, profile_id=profile_id, cookie=cookie))
+        access, next_cookie = broker_backend.check_access(username=broker_username, password=password, ip=ip, cookie=cookie)
 
-        username, password, task, profile_id, ip, cookie, authed, server = broker_backend.run_optional_script(script_type='post_auth_scripts', username=username, password=password, task=task, profile_id=profile_id, ip=ip, cookie=cookie, authed=access)
+        broker_username, password, task, profile_id, ip, cookie, authed, server = broker_backend.run_optional_script(script_type='post_auth_scripts', username=broker_username, password=password, task=task, profile_id=profile_id, ip=ip, cookie=cookie, authed=access)
 
         if access:
 
@@ -161,7 +164,7 @@ class X2GoBrokerWeb(_RequestHandler):
             if task == 'listsessions' or task == 'listprofiles':
 
                 payload.update({
-                    'profiles': broker_backend.list_profiles(username),
+                    'profiles': broker_backend.list_profiles(username=broker_username),
                 })
 
             elif task == 'selectsession':
@@ -173,9 +176,9 @@ class X2GoBrokerWeb(_RequestHandler):
 
                     selected_session = {}
 
-                    profile_info = broker_backend.select_session(profile_id=profile_id, username=username, pubkey=pubkey)
+                    profile_info = broker_backend.select_session(profile_id=profile_id, username=server_username, pubkey=pubkey)
                     if 'server' in profile_info:
-                        username, password, task, profile_id, ip, cookie, authed, server = broker_backend.run_optional_script(script_type='select_session_scripts', username=username, password=password, task=task, profile_id=profile_id, ip=ip, cookie=cookie, authed=access, server=profile_info['server'])
+                        server_username, password, task, profile_id, ip, cookie, authed, server = broker_backend.run_optional_script(script_type='select_session_scripts', username=server_username, password=password, task=task, profile_id=profile_id, ip=ip, cookie=cookie, authed=access, server=profile_info['server'])
                         selected_session['server'] = "{server}".format(server=server)
                         if 'port' in profile_info:
                             selected_session['port'] = "{port}".format(port=profile_info['port'])
diff --git a/x2gobroker/web/plain.py b/x2gobroker/web/plain.py
index 36c84cb..9b1a17e 100644
--- a/x2gobroker/web/plain.py
+++ b/x2gobroker/web/plain.py
@@ -101,7 +101,10 @@ class X2GoBrokerWeb(_RequestHandler):
             logger_error.error('client could not provide an IP address, pretending: 404 Not Found')
             raise tornado.web.HTTPError(404)
 
-        username = self.get_argument('user', default='')
+        broker_username = self.get_argument('user', default='')
+        server_username = self.get_argument('login', default='')
+        if not server_username:
+            server_username = broker_username
         password = self.get_argument('password', default='', strip=False)
         cookie = self.get_argument('authid', default='')
         pubkey = self.get_argument('pubkey', default='')
@@ -111,12 +114,12 @@ class X2GoBrokerWeb(_RequestHandler):
 
         output = ''
 
-        username, password, task, profile_id, ip, cookie, authed, server = broker_backend.run_optional_script(script_type='pre_auth_scripts', username=username, password=password, task=task, profile_id=profile_id, ip=ip, cookie=cookie)
+        broker_username, password, task, profile_id, ip, cookie, authed, server = broker_backend.run_optional_script(script_type='pre_auth_scripts', username=broker_username, password=password, task=task, profile_id=profile_id, ip=ip, cookie=cookie)
 
-        logger_broker.debug ('username: {username}, password: {password}, task: {task}, profile_id: {profile_id}, cookie: {cookie}'.format(username=username, password='XXXXX', task=task, profile_id=profile_id, cookie=cookie))
-        access, next_cookie = broker_backend.check_access(username=username, password=password, ip=ip, cookie=cookie)
+        logger_broker.debug ('broker_username: {broker_username}, server_username: {server_username}, password: {password}, task: {task}, profile_id: {profile_id}, cookie: {cookie}'.format(broker_username=broker_username, server_username=server_username, password='XXXXX', task=task, profile_id=profile_id, cookie=cookie))
+        access, next_cookie = broker_backend.check_access(username=broker_username, password=password, ip=ip, cookie=cookie)
 
-        username, password, task, profile_id, ip, cookie, authed, server = broker_backend.run_optional_script(script_type='post_auth_scripts', username=username, password=password, task=task, profile_id=profile_id, ip=ip, cookie=cookie, authed=access)
+        broker_username, password, task, profile_id, ip, cookie, authed, server = broker_backend.run_optional_script(script_type='post_auth_scripts', username=broker_username, password=password, task=task, profile_id=profile_id, ip=ip, cookie=cookie, authed=access)
 
         if access:
 
@@ -144,7 +147,7 @@ class X2GoBrokerWeb(_RequestHandler):
 
             if task == 'listsessions':
 
-                profiles = broker_backend.list_profiles(username)
+                profiles = broker_backend.list_profiles(broker_username)
                 if profiles:
                     output += "START_USER_SESSIONS\n\n"
                     profile_ids = list(profiles.keys())
@@ -168,10 +171,10 @@ class X2GoBrokerWeb(_RequestHandler):
 
                 if profile_id:
 
-                    profile_info = broker_backend.select_session(profile_id=profile_id, username=username, pubkey=pubkey)
+                    profile_info = broker_backend.select_session(profile_id=profile_id, username=server_username, pubkey=pubkey)
 
                     if 'server' in profile_info:
-                        username, password, task, profile_id, ip, cookie, authed, server = broker_backend.run_optional_script(script_type='select_session_scripts', username=username, password=password, task=task, profile_id=profile_id, ip=ip, cookie=cookie, authed=access, server=profile_info['server'])
+                        server_username, password, task, profile_id, ip, cookie, authed, server = broker_backend.run_optional_script(script_type='select_session_scripts', username=server_username, password=password, task=task, profile_id=profile_id, ip=ip, cookie=cookie, authed=access, server=profile_info['server'])
                         output += "SERVER:"
                         output += server
                         if 'port' in profile_info:

--
Alioth's /home/x2go-admin/maintenancescripts/git/hooks/post-receive-email on /srv/git/code.x2go.org/x2gobroker.git


More information about the x2go-commits mailing list