def test_get_external_ip_from_ase(self, client_factory_mock): client = mock.Mock() client_factory_mock.return_value = client cmd_mock = mock.MagicMock() # set up the web inside a ASE, with an ip based ssl binding host_env = HostingEnvironmentProfile(id='id11') host_env.name = 'ase1' host_env.resource_group = 'myRg' host_ssl_state = HostNameSslState(ssl_state=SslState.ip_based_enabled, virtual_ip='1.2.3.4') client.web_apps.get.return_value = Site( name='antarctica', hosting_environment_profile=host_env, host_name_ssl_states=[host_ssl_state], location='westus') client.app_service_environments.list_vips.return_value = AddressResponse( ) # action result = get_external_ip(cmd_mock, 'myRg', 'myWeb') # assert, we return the virtual ip from the ip based ssl binding self.assertEqual('1.2.3.4', result['ip']) # tweak to have no ip based ssl binding, but it is in an internal load balancer host_ssl_state2 = HostNameSslState(ssl_state=SslState.sni_enabled) client.web_apps.get.return_value = Site( name='antarctica', hosting_environment_profile=host_env, host_name_ssl_states=[host_ssl_state2], location='westus') client.app_service_environments.list_vips.return_value = AddressResponse( internal_ip_address='4.3.2.1') # action result = get_external_ip(cmd_mock, 'myRg', 'myWeb') # assert, we take the ILB address self.assertEqual('4.3.2.1', result['ip']) # tweak to have no ip based ssl binding, and not in internal load balancer host_ssl_state2 = HostNameSslState(ssl_state=SslState.sni_enabled) client.web_apps.get.return_value = Site( name='antarctica', hosting_environment_profile=host_env, host_name_ssl_states=[host_ssl_state2], location='westus') client.app_service_environments.list_vips.return_value = AddressResponse( service_ip_address='1.1.1.1') # action result = get_external_ip(cmd_mock, 'myRg', 'myWeb') # assert, we take service ip self.assertEqual('1.1.1.1', result['ip'])
def test_get_external_ip_from_dns(self, resolve_hostname_mock, client_factory_mock): client = mock.Mock() client_factory_mock.return_value = client # set up the web inside a ASE, with an ip based ssl binding site = Site('antarctica') site.default_host_name = 'myweb.com' client.web_apps.get.return_value = site # action get_external_ip('myRg', 'myWeb') # assert, we return the virtual ip from the ip based ssl binding resolve_hostname_mock.assert_called_with('myweb.com')
def test_get_external_ip_from_dns(self, resolve_hostname_mock, client_factory_mock): client = mock.Mock() client_factory_mock.return_value = client # set up the web inside a ASE, with an ip based ssl binding site = Site('antarctica') site.default_host_name = 'myweb.com' client.web_apps.get.return_value = site # action get_external_ip('myRg', 'myWeb') # assert, we return the virtual ip from the ip based ssl binding resolve_hostname_mock.assert_called_with('myweb.com')
def test_get_external_ip_from_ase(self, client_factory_mock): client = mock.Mock() client_factory_mock.return_value = client cmd_mock = mock.MagicMock() # set up the web inside a ASE, with an ip based ssl binding host_env = HostingEnvironmentProfile('id11') host_env.name = 'ase1' host_env.resource_group = 'myRg' host_ssl_state = HostNameSslState(ssl_state=SslState.ip_based_enabled, virtual_ip='1.2.3.4') client.web_apps.get.return_value = Site('antarctica', hosting_environment_profile=host_env, host_name_ssl_states=[host_ssl_state]) client.app_service_environments.list_vips.return_value = AddressResponse() # action result = get_external_ip(cmd_mock, 'myRg', 'myWeb') # assert, we return the virtual ip from the ip based ssl binding self.assertEqual('1.2.3.4', result['ip']) # tweak to have no ip based ssl binding, but it is in an internal load balancer host_ssl_state2 = HostNameSslState(ssl_state=SslState.sni_enabled) client.web_apps.get.return_value = Site('antarctica', hosting_environment_profile=host_env, host_name_ssl_states=[host_ssl_state2]) client.app_service_environments.list_vips.return_value = AddressResponse(internal_ip_address='4.3.2.1') # action result = get_external_ip(cmd_mock, 'myRg', 'myWeb') # assert, we take the ILB address self.assertEqual('4.3.2.1', result['ip']) # tweak to have no ip based ssl binding, and not in internal load balancer host_ssl_state2 = HostNameSslState(ssl_state=SslState.sni_enabled) client.web_apps.get.return_value = Site('antarctica', hosting_environment_profile=host_env, host_name_ssl_states=[host_ssl_state2]) client.app_service_environments.list_vips.return_value = AddressResponse(service_ip_address='1.1.1.1') # action result = get_external_ip(cmd_mock, 'myRg', 'myWeb') # assert, we take service ip self.assertEqual('1.1.1.1', result['ip'])