Exemplo n.º 1
0
    def test_that_organization_switch_reads_the_credentials_from_pipe(self):
        fifo_path = '/tmp/credentials-pipe'

        sys.argv = ['tmp/does_not_exist', '--dispatcher', fifo_path]
        args = parse_args()

        self._mkfifo(fifo_path)

        config_dispatcher(self.app, args)

        self.assertEquals('test_provider', self.app['LEAP_SERVER_NAME'])
        self.assertEquals('test_user', self.app['LEAP_USERNAME'])
        self.assertEquals('test_password', self.app['LEAP_PASSWORD'])
Exemplo n.º 2
0
    def test_that_organization_switch_reads_the_credentials_from_stdin(self):
        data = json.dumps({'leap_provider_hostname': 'test_provider', 'user': '******', 'password': '******'})
        orig_stdin = sys.stdin
        sys.stdin = mock()
        when(sys.stdin).read().thenReturn(data)

        try:
            sys.argv = ['tmp/does_not_exist', '--dispatcher-stdin']
            args = parse_args()

            config_dispatcher(self.app, args)

            self.assertEquals('test_provider', self.app['LEAP_SERVER_NAME'])
            self.assertEquals('test_user', self.app['LEAP_USERNAME'])
            self.assertEquals('test_password', self.app['LEAP_PASSWORD'])
        finally:
            sys.stdin = orig_stdin
Exemplo n.º 3
0
def initialize():
    args = parse_args()
    app = App()

    init_logging(args)
    init_leap_cert(args)

    if args.register:
        register(*args.register[::-1])
        sys.exit(0)

    if args.dispatcher or args.dispatcher_stdin:
        config_dispatcher(app, args)
    else:
        config_user_agent(app, args)

    init_events_server()

    def load_app():
        # welcome to deferred hell. Or maybe you'll be welcomed later, who knows.
        loading_app = loading(args)

        def init_soledad():
            return init_soledad_and_user_key(app, args.home)

        def stop_loading_app(leap_session):
            d = loading_app.stopListening()
            d.addCallback(partial(start_user_agent_app, leap_session))

        def start_user_agent_app(leap_session, _):
            app_factory.create_app(app, args, leap_session)

        d = deferToThread(init_soledad)
        d.addCallback(stop_loading_app)
        d.addErrback(error_handler)

    reactor.callWhenRunning(load_app)
    reactor.run()