summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorBruno Wagner <bwagner@thoughtworks.com>2014-10-27 18:05:02 +0100
committerBruno Wagner <bwagner@thoughtworks.com>2014-10-27 18:05:02 +0100
commit30ab7258392ebb884ca835ec32000275c61c65d0 (patch)
tree24414e02bb91da8fec327d7ce79b8595bc1486c7 /service
parent69dfbb0377c3378edabf3a78353907223f2d2f17 (diff)
Errors out if pipe file doesn't exist
Diffstat (limited to 'service')
-rw-r--r--service/pixelated/runserver.py26
-rw-r--r--service/test/unit/runserver_test.py25
2 files changed, 43 insertions, 8 deletions
diff --git a/service/pixelated/runserver.py b/service/pixelated/runserver.py
index 75b6d2a9..314a5d71 100644
--- a/service/pixelated/runserver.py
+++ b/service/pixelated/runserver.py
@@ -15,6 +15,7 @@
# along with Pixelated. If not, see <http://www.gnu.org/licenses/>.
import os
+import sys
import logging
from flask import Flask
from leap.common.events import server as events_server
@@ -29,6 +30,7 @@ import pixelated.support.ext_sqlcipher # monkey patch for sqlcipher in debian
app = Flask(__name__, static_url_path='', static_folder=app_factory.get_static_folder())
+credentials_pipe = os.path.join('/', 'data', 'credentials-fifo')
def setup():
@@ -42,10 +44,13 @@ def setup():
register(*args.register[::-1])
else:
if args.dispatcher:
- raise Exception('Dispatcher mode not implemented yet')
+ provider, user, password = fetch_credentials_from_dispatcher()
+ app.config['LEAP_SERVER_NAME'] = provider
+ app.config['LEAP_USERNAME'] = user
+ app.config['LEAP_PASSWORD'] = password
else:
- configuration_setup(app, args.config)
- start_services(app, debugger)
+ configuration_setup(args.config)
+ start_services(debugger)
finally:
reactor_manager.stop_reactor_on_exit()
@@ -57,6 +62,17 @@ def register(username, server_name):
print('User already exists')
+def fetch_credentials_from_dispatcher():
+ if not os.path.exists(credentials_pipe):
+ print('The credentials pipe doesn\'t exist')
+ sys.exit(1)
+ with open(credentials_pipe, 'r') as cred_file:
+ provider = cred_file.read()
+ username = cred_file.read()
+ password = cred_file.read()
+ return provider, username, password
+
+
def setup_debugger(enabled):
debug_enabled = enabled or os.environ.get('DEBUG', False)
if not debug_enabled:
@@ -66,7 +82,7 @@ def setup_debugger(enabled):
return debug_enabled
-def configuration_setup(app, config):
+def configuration_setup(config):
if config is not None:
config_file = os.path.abspath(os.path.expanduser(config))
app.config.from_pyfile(config_file)
@@ -77,7 +93,7 @@ def configuration_setup(app, config):
app.config['LEAP_PASSWORD'] = password
-def start_services(app, debug):
+def start_services(debug):
reactor_manager.start_reactor(logging=debug)
events_server.ensure_server(port=8090)
app_factory.create_app(app, debug)
diff --git a/service/test/unit/runserver_test.py b/service/test/unit/runserver_test.py
index 80cbf543..57e211c9 100644
--- a/service/test/unit/runserver_test.py
+++ b/service/test/unit/runserver_test.py
@@ -16,21 +16,24 @@
import unittest
import sys
+import os
+import thread
import pixelated.runserver
from mockito import *
import pixelated.config.reactor_manager as reactor_manager
-import pixelated.adapter.mail
import pixelated.config.app_factory as app_factory
class RunserverTest(unittest.TestCase):
+ def setUp(self):
+ when(reactor_manager).start_reactor().thenReturn(None)
+ when(app_factory).create_app().thenReturn(None)
+
def test_that_config_file_can_be_specified_on_command_line(self):
orig_config = pixelated.runserver.app.config
try:
- when(reactor_manager).start_reactor().thenReturn(None)
- when(app_factory).create_app().thenReturn(None)
pixelated.runserver.app.config = mock(dict)
pixelated.runserver.app.config.__setitem__ = mock()
@@ -40,3 +43,19 @@ class RunserverTest(unittest.TestCase):
verify(pixelated.runserver.app.config).from_pyfile('/tmp/some/config/file')
finally:
pixelated.runserver.app.config = orig_config
+
+ def test_that_organization_switch_reads_the_credentials_from_pipe(self):
+ fifo_path = '/tmp/credentials-pipe'
+ if os.path.exists(fifo_path):
+ os.remove(fifo_path)
+ test_fifo = os.mkfifo('/tmp/credentials-pipe')
+ thread.start_new_thread(self.spin_up_fifo, (fifo_path,))
+ sys.argv = ['tmp/does_not_exist', '--dispatcher']
+ pixelated.runserver.credentials_pipe = fifo_path
+ pixelated.runserver.setup()
+
+ def spin_up_fifo(self, test_fifo):
+ with open(test_fifo, 'w') as fifo:
+ fifo.write('test_provider')
+ fifo.write('test_user')
+ fifo.write('test_password')