@ResourceGroupPreparer(parameter_name='kv_resource_group', location=WINDOWS_ASP_LOCATION_WEBAPP)
@ResourceGroupPreparer(location=WINDOWS_ASP_LOCATION_WEBAPP)
def test_webapp_ssl_import_crossrg(self, resource_group, kv_resource_group):
    plan_name = self.create_random_name(prefix='ssl-test-plan', length=24)
    webapp_name = self.create_random_name(prefix='web-ssl-test', length=20)
    kv_name = self.create_random_name(prefix='kv-ssl-test', length=20)
    pfx_file = os.path.join(TEST_DIR, 'server.pfx')
    cert_password = 'test'
    cert_thumbprint = '9E9735C45C792B03B3FFCCA614852B32EE71AD6B'
    cert_name = 'test-cert'
    self.cmd('appservice plan create -g {} -n {} --sku B1'.format(resource_group, plan_name))
    self.cmd('webapp create -g {} -n {} --plan {}'.format(resource_group, webapp_name, plan_name))
    kv_id = self.cmd('keyvault create -g {} -n {}'.format(kv_resource_group, kv_name)).get_output_in_json()['id']
    self.cmd('keyvault set-policy -g {} --name {} --spn {} --secret-permissions get'.format(kv_resource_group, kv_name, 'Microsoft.Azure.WebSites'))
    self.cmd('keyvault certificate import --name {} --vault-name {} --file "{}" --password {}'.format(cert_name, kv_name, pfx_file, cert_password))
    self.cmd('webapp config ssl import --resource-group {} --name {}  --key-vault {} --key-vault-certificate-name {}'.format(resource_group, webapp_name, kv_id, cert_name), checks=[JMESPathCheck('keyVaultSecretStatus', 'Initialized'), JMESPathCheck('thumbprint', cert_thumbprint)])
    self.cmd('webapp config ssl bind -g {} -n {} --certificate-thumbprint {} --ssl-type {}'.format(resource_group, webapp_name, cert_thumbprint, 'SNI'), checks=[JMESPathCheck("hostNameSslStates|[?name=='{}.azurewebsites.net']|[0].sslState".format(webapp_name), 'SniEnabled'), JMESPathCheck("hostNameSslStates|[?name=='{}.azurewebsites.net']|[0].thumbprint".format(webapp_name), cert_thumbprint)])
@ResourceGroupPreparer(parameter_name='kv_resource_group', location=WINDOWS_ASP_LOCATION_WEBAPP)
@ResourceGroupPreparer(location=WINDOWS_ASP_LOCATION_WEBAPP)
def test_webapp_ssl_import_crossrg(self, resource_group, kv_resource_group):
    plan_name = self.create_random_name(prefix='ssl-test-plan', length=24)
    webapp_name = self.create_random_name(prefix='web-ssl-test', length=20)
    kv_name = self.create_random_name(prefix='kv-ssl-test', length=20)
    pfx_file = os.path.join(TEST_DIR, 'server.pfx')
    cert_password = 'test'
    cert_thumbprint = '9E9735C45C792B03B3FFCCA614852B32EE71AD6B'
    cert_name = 'test-cert'
    self.cmd('appservice plan create -g {} -n {} --sku B1'.format(resource_group, plan_name))
    self.cmd('webapp create -g {} -n {} --plan {}'.format(resource_group, webapp_name, plan_name))
    kv_id = self.cmd('keyvault create -g {} -n {}'.format(kv_resource_group, kv_name)).get_output_in_json()['id']
    self.cmd('keyvault set-policy -g {} --name {} --spn {} --secret-permissions get'.format(kv_resource_group, kv_name, 'Microsoft.Azure.WebSites'))
    self.cmd('keyvault certificate import --name {} --vault-name {} --file "{}" --password {}'.format(cert_name, kv_name, pfx_file, cert_password))
    self.cmd('webapp config ssl import --resource-group {} --name {}  --key-vault {} --key-vault-certificate-name {}'.format(resource_group, webapp_name, kv_id, cert_name), checks=[JMESPathCheck('keyVaultSecretStatus', 'Initialized'), JMESPathCheck('thumbprint', cert_thumbprint)])
    self.cmd('webapp config ssl bind -g {} -n {} --certificate-thumbprint {} --ssl-type {}'.format(resource_group, webapp_name, cert_thumbprint, 'SNI'), checks=[JMESPathCheck("hostNameSslStates|[?name=='{}.azurewebsites.net']|[0].sslState".format(webapp_name), 'SniEnabled'), JMESPathCheck("hostNameSslStates|[?name=='{}.azurewebsites.net']|[0].thumbprint".format(webapp_name), cert_thumbprint)])