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']))
def upload_ssl_cert(resource_group_name, name, certificate_password, certificate_file): client = web_client_factory() webapp = _generic_site_operation(resource_group_name, name, 'get') cert_file = open(certificate_file, 'rb') cert_contents = cert_file.read() hosting_environment_profile_param = webapp.hosting_environment_profile if hosting_environment_profile_param is None: hosting_environment_profile_param = "" thumb_print = _get_cert(certificate_password, certificate_file) cert_name = _generate_cert_name(thumb_print, hosting_environment_profile_param, webapp.location, resource_group_name) cert = Certificate(password=certificate_password, pfx_blob=cert_contents, location=webapp.location) return client.certificates.create_or_update(resource_group_name, cert_name, cert)