Exemplo n.º 1
0
 def test_default_ports(self, mock_log, mock_open_port, mock_close_port):
     # The default ports are properly opened.
     setup_ports(None, None)
     mock_log.assert_called_once_with('Opening default ports 80 and 443.')
     self.assertEqual(2, mock_open_port.call_count)
     mock_open_port.assert_has_calls([mock.call(80), mock.call(443)])
     self.assertFalse(mock_close_port.called)
Exemplo n.º 2
0
 def test_from_invalid_to_defaults(self, mock_log, mock_open_port, mock_close_port):
     # The user switches back to default after providing an invalid port.
     setup_ports(0, None)
     mock_log.assert_called_once_with("Opening default ports 80 and 443.")
     self.assertEqual(2, mock_open_port.call_count)
     mock_open_port.assert_has_calls([mock.call(80), mock.call(443)])
     self.assertFalse(mock_close_port.called)
Exemplo n.º 3
0
 def start(self, backend):
     log("Starting Juju GUI.")
     config = backend.config
     build_dir = utils.compute_build_dir(config["juju-gui-debug"], config["serve-tests"])
     # Check if a secure WebSocket client connection is required.
     secure = config.get("ws-secure")
     if secure is None:
         # WebSocket security is not explicitly provided: use secure
         # WebSocket if the GUI server is running in secure mode.
         secure = config["secure"]
     utils.write_gui_config(
         config["juju-gui-console-enabled"],
         config.get("login-help"),
         config["read-only"],
         config["charmworld-url"],
         config["charmstore-url"],
         build_dir,
         secure=secure,
         sandbox=config["sandbox"],
         cached_fonts=config["cached-fonts"],
         ga_key=config["ga-key"],
         hide_login_button=config["hide-login-button"],
         juju_core_version=config.get("juju-core-version"),
         password=config.get("password"),
         juju_env_uuid=os.getenv("JUJU_ENV_UUID", None),
     )
     # Set up TCP ports.
     previous_port = backend.prev_config.get("port")
     current_port = backend.config.get("port")
     utils.setup_ports(previous_port, current_port)
Exemplo n.º 4
0
 def test_default_ports(self, mock_log, mock_open_port, mock_close_port):
     # The default ports are properly opened.
     setup_ports(None, None)
     mock_log.assert_called_once_with("Opening default ports 80 and 443.")
     self.assertEqual(2, mock_open_port.call_count)
     mock_open_port.assert_has_calls([mock.call(80), mock.call(443)])
     self.assertFalse(mock_close_port.called)
Exemplo n.º 5
0
 def start(self, backend):
     log('Starting Juju GUI.')
     config = backend.config
     build_dir = utils.compute_build_dir(config['juju-gui-debug'],
                                         config['serve-tests'])
     # Check if a secure WebSocket client connection is required.
     secure = config.get('ws-secure')
     if secure is None:
         # WebSocket security is not explicitly provided: use secure
         # WebSocket if the GUI server is running in secure mode.
         secure = config['secure']
     utils.write_gui_config(
         config['juju-gui-console-enabled'],
         config.get('login-help'),
         config['read-only'],
         config['charmworld-url'],
         config['charmstore-url'],
         build_dir,
         secure=secure,
         sandbox=config['sandbox'],
         cached_fonts=config['cached-fonts'],
         ga_key=config['ga-key'],
         hide_login_button=config['hide-login-button'],
         juju_core_version=config.get('juju-core-version'),
         password=config.get('password'),
         juju_env_uuid=os.getenv('JUJU_ENV_UUID', None))
     # Set up TCP ports.
     previous_port = backend.prev_config.get('port')
     current_port = backend.config.get('port')
     utils.setup_ports(previous_port, current_port)
Exemplo n.º 6
0
 def test_from_invalid_to_defaults(
         self, mock_log, mock_open_port, mock_close_port):
     # The user switches back to default after providing an invalid port.
     setup_ports(0, None)
     mock_log.assert_called_once_with('Opening default ports 80 and 443.')
     self.assertEqual(2, mock_open_port.call_count)
     mock_open_port.assert_has_calls([mock.call(80), mock.call(443)])
     self.assertFalse(mock_close_port.called)
Exemplo n.º 7
0
 def test_from_invalid_to_new_port(self, mock_log, mock_open_port, mock_close_port):
     # The user fixes a previously provided invalid port.
     setup_ports(123456, 8000)
     self.assertEqual(2, mock_log.call_count)
     mock_log.assert_has_calls(
         [mock.call("Closing default ports 80 and 443."), mock.call("Opening user provided port 8000.")]
     )
     mock_open_port.assert_called_once_with(8000)
     self.assertEqual(2, mock_close_port.call_count)
     mock_close_port.assert_has_calls([mock.call(80), mock.call(443)])
Exemplo n.º 8
0
 def test_from_defaults_to_invalid(self, mock_log, mock_open_port, mock_close_port):
     # The user provides an invalid port.
     setup_ports(None, 100000)
     self.assertEqual(2, mock_log.call_count)
     mock_log.assert_has_calls(
         [mock.call("Ignoring provided port 100000: not in range."), mock.call("Opening default ports 80 and 443.")]
     )
     self.assertEqual(2, mock_open_port.call_count)
     mock_open_port.assert_has_calls([mock.call(80), mock.call(443)])
     self.assertFalse(mock_close_port.called)
Exemplo n.º 9
0
 def test_from_previous_port_to_defaults(self, mock_log, mock_open_port, mock_close_port):
     # The user provided a port and then switches back to defaults.
     setup_ports(1234, None)
     self.assertEqual(2, mock_log.call_count)
     mock_log.assert_has_calls(
         [mock.call("Closing user provided port 1234."), mock.call("Opening default ports 80 and 443.")]
     )
     self.assertEqual(2, mock_open_port.call_count)
     mock_open_port.assert_has_calls([mock.call(80), mock.call(443)])
     mock_close_port.assert_called_once_with(1234)
Exemplo n.º 10
0
 def test_from_defaults_to_new_port(self, mock_log, mock_open_port, mock_close_port):
     # The user provides a customized port.
     setup_ports(None, 8080)
     self.assertEqual(2, mock_log.call_count)
     mock_log.assert_has_calls(
         [mock.call("Closing default ports 80 and 443."), mock.call("Opening user provided port 8080.")]
     )
     mock_open_port.assert_called_once_with(8080)
     self.assertEqual(2, mock_close_port.call_count)
     mock_close_port.assert_has_calls([mock.call(80), mock.call(443)])
Exemplo n.º 11
0
 def test_from_invalid_to_new_port(
         self, mock_log, mock_open_port, mock_close_port):
     # The user fixes a previously provided invalid port.
     setup_ports(123456, 8000)
     self.assertEqual(2, mock_log.call_count)
     mock_log.assert_has_calls([
         mock.call('Closing default ports 80 and 443.'),
         mock.call('Opening user provided port 8000.')
     ])
     mock_open_port.assert_called_once_with(8000)
     self.assertEqual(2, mock_close_port.call_count)
     mock_close_port.assert_has_calls([mock.call(80), mock.call(443)])
Exemplo n.º 12
0
 def test_from_defaults_to_invalid(
         self, mock_log, mock_open_port, mock_close_port):
     # The user provides an invalid port.
     setup_ports(None, 100000)
     self.assertEqual(2, mock_log.call_count)
     mock_log.assert_has_calls([
         mock.call('Ignoring provided port 100000: not in range.'),
         mock.call('Opening default ports 80 and 443.'),
     ])
     self.assertEqual(2, mock_open_port.call_count)
     mock_open_port.assert_has_calls([mock.call(80), mock.call(443)])
     self.assertFalse(mock_close_port.called)
Exemplo n.º 13
0
 def test_from_previous_port_to_defaults(
         self, mock_log, mock_open_port, mock_close_port):
     # The user provided a port and then switches back to defaults.
     setup_ports(1234, None)
     self.assertEqual(2, mock_log.call_count)
     mock_log.assert_has_calls([
         mock.call('Closing user provided port 1234.'),
         mock.call('Opening default ports 80 and 443.'),
     ])
     self.assertEqual(2, mock_open_port.call_count)
     mock_open_port.assert_has_calls([mock.call(80), mock.call(443)])
     mock_close_port.assert_called_once_with(1234)
Exemplo n.º 14
0
 def test_from_defaults_to_new_port(
         self, mock_log, mock_open_port, mock_close_port):
     # The user provides a customized port.
     setup_ports(None, 8080)
     self.assertEqual(2, mock_log.call_count)
     mock_log.assert_has_calls([
         mock.call('Closing default ports 80 and 443.'),
         mock.call('Opening user provided port 8080.'),
     ])
     mock_open_port.assert_called_once_with(8080)
     self.assertEqual(2, mock_close_port.call_count)
     mock_close_port.assert_has_calls([mock.call(80), mock.call(443)])
Exemplo n.º 15
0
 def test_from_previous_port_to_invalid(
         self, mock_log, mock_open_port, mock_close_port):
     # The user switches from a previously provided port to an invalid one.
     setup_ports(8080, 0)
     self.assertEqual(3, mock_log.call_count)
     mock_log.assert_has_calls([
         mock.call('Closing user provided port 8080.'),
         mock.call('Ignoring provided port 0: not in range.'),
         mock.call('Opening default ports 80 and 443.'),
     ])
     self.assertEqual(2, mock_open_port.call_count)
     mock_open_port.assert_has_calls([mock.call(80), mock.call(443)])
     mock_close_port.assert_called_once_with(8080)
Exemplo n.º 16
0
 def test_from_previous_port_to_invalid(
         self, mock_log, mock_open_port, mock_close_port):
     # The user switches from a previously provided port to an invalid one.
     setup_ports(8080, 0)
     self.assertEqual(3, mock_log.call_count)
     mock_log.assert_has_calls([
         mock.call('Closing user provided port 8080.'),
         mock.call('Ignoring provided port 0: not in range.'),
         mock.call('Opening default ports 80 and 443.'),
     ])
     self.assertEqual(2, mock_open_port.call_count)
     mock_open_port.assert_has_calls([mock.call(80), mock.call(443)])
     mock_close_port.assert_called_once_with(8080)
Exemplo n.º 17
0
 def test_from_previous_port_to_new_port(self, mock_log, mock_open_port, mock_close_port):
     # The user switches from a previously provided port to a new one.
     setup_ports(8080, 1234)
     self.assertEqual(3, mock_log.call_count)
     mock_log.assert_has_calls(
         [
             mock.call("Closing user provided port 8080."),
             # Always close the default ports in those cases.
             mock.call("Closing default ports 80 and 443."),
             mock.call("Opening user provided port 1234."),
         ]
     )
     mock_open_port.assert_called_once_with(1234)
     self.assertEqual(3, mock_close_port.call_count)
     mock_close_port.assert_has_calls([mock.call(8080), mock.call(80), mock.call(443)])
Exemplo n.º 18
0
 def test_from_previous_port_to_new_port(
         self, mock_log, mock_open_port, mock_close_port):
     # The user switches from a previously provided port to a new one.
     setup_ports(8080, 1234)
     self.assertEqual(3, mock_log.call_count)
     mock_log.assert_has_calls([
         mock.call('Closing user provided port 8080.'),
         # Always close the default ports in those cases.
         mock.call('Closing default ports 80 and 443.'),
         mock.call('Opening user provided port 1234.')
     ])
     mock_open_port.assert_called_once_with(1234)
     self.assertEqual(3, mock_close_port.call_count)
     mock_close_port.assert_has_calls([
         mock.call(8080), mock.call(80), mock.call(443)])
Exemplo n.º 19
0
 def start(self, backend):
     log('Starting Juju GUI.')
     # Set up TCP ports.
     previous_port = backend.prev_config.get('port')
     current_port = backend.config.get('port')
     utils.setup_ports(previous_port, current_port)