def test_update_host_certs(self, client_mock, show_webapp_mock,
                               host_ssl_update_mock, site_op_mock):
        faked_web_client = mock.MagicMock()
        client_mock.return_value = faked_web_client
        faked_site = Site('antarctica', server_farm_id='big_plan')
        faked_web_client.web_apps.get.side_effect = [faked_site, faked_site]
        test_hostname = '*.foo.com'
        cert1 = Certificate('antarctica', host_names=[test_hostname])
        cert1.thumbprint = 't1'
        faked_web_client.certificates.list_by_resource_group.return_value = [
            cert1
        ]
        hostname_binding1 = HostNameBinding(
            'antarctica',
            name='web1/admin.foo.com',
        )
        hostname_binding2 = HostNameBinding('antarctica',
                                            name='web1/logs.foo.com')
        site_op_mock.return_value = [hostname_binding1, hostname_binding2]

        # action
        bind_ssl_cert('rg1', 'web1', 't1', SslState.sni_enabled)

        # assert
        self.assertEqual(len(host_ssl_update_mock.call_args_list), 2)
        host_names_updated = set(
            [x[0][3] for x in host_ssl_update_mock.call_args_list])
        self.assertEqual(host_names_updated,
                         set(['logs.foo.com', 'admin.foo.com']))
Beispiel #2
0
def add_hostname(resource_group_name, webapp_name, name, slot=None):
    client = web_client_factory()
    webapp = client.web_apps.get(resource_group_name, webapp_name)
    binding = HostNameBinding(webapp.location, host_name_binding_name=name, site_name=webapp.name)
    if slot is None:
        return client.web_apps.create_or_update_host_name_binding(
            resource_group_name, webapp.name, name, binding)
    else:
        return client.web_apps.create_or_update_host_name_binding_slot(
            resource_group_name, webapp.name, name, binding, slot)
    def test_set_domain_name(self, client_factory_mock):
        client_factory_mock.return_value = self.client
        # set up the return value for getting a webapp
        webapp = Site('westus')
        webapp.name = 'veryNiceWebApp'
        self.client.web_apps.get = lambda _, _1: webapp

        # set up the result value of putting a domain name
        domain = 'veryNiceDomain'
        binding = HostNameBinding(webapp.location, name=domain,
                                  custom_host_name_dns_record_type='A',
                                  host_name_type='Managed')
        self.client.web_apps._client = mock.MagicMock()
        self.client.web_apps._client.send.return_value = FakedResponse(200)
        self.client.web_apps._deserialize = mock.MagicMock()
        self.client.web_apps._deserialize.return_value = binding
        # action
        result = add_hostname('g1', webapp.name, domain)

        # assert
        self.assertEqual(result.name, domain)