|
| 1 | +# -------------------------------------------------------------------------------------------- |
| 2 | +# Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 | +# Licensed under the MIT License. See License.txt in the project root for license information. |
| 4 | +# -------------------------------------------------------------------------------------------- |
| 5 | + |
| 6 | + |
| 7 | +from azure.cli.testsdk import ScenarioTest, live_only |
| 8 | +from azure.cli.testsdk.scenario_tests import AllowLargeResponse |
| 9 | + |
| 10 | +from azure.cli.command_modules.acs.tests.latest.recording_processors import KeyReplacer |
| 11 | +from azure.cli.command_modules.acs.tests.latest.custom_preparers import ( |
| 12 | + AKSCustomResourceGroupPreparer, |
| 13 | +) |
| 14 | + |
| 15 | + |
| 16 | +class IdentityBindingTestCases(ScenarioTest): |
| 17 | + |
| 18 | + def __init__(self, method_name): |
| 19 | + super(IdentityBindingTestCases, self).__init__( |
| 20 | + method_name, |
| 21 | + recording_processors=[KeyReplacer()], |
| 22 | + ) |
| 23 | + |
| 24 | + @AllowLargeResponse() |
| 25 | + @live_only() |
| 26 | + @AKSCustomResourceGroupPreparer( |
| 27 | + random_name_length=17, |
| 28 | + name_prefix="clitest", |
| 29 | + location="eastus2", |
| 30 | + ) |
| 31 | + def test_identity_binding_usages(self, resource_group, resource_group_location): |
| 32 | + aks_name = self.create_random_name("cliakstest", 16) |
| 33 | + identity_name = self.create_random_name("cli", 16) |
| 34 | + identity_binding_name = self.create_random_name("cliib", 16) |
| 35 | + self.kwargs.update( |
| 36 | + { |
| 37 | + "resource_group": resource_group, |
| 38 | + "aks_name": aks_name, |
| 39 | + "identity_name": identity_name, |
| 40 | + "identity_binding_name": identity_binding_name, |
| 41 | + "location": resource_group_location, |
| 42 | + } |
| 43 | + ) |
| 44 | + |
| 45 | + create_aks_cmd = ("aks create --resource-group={resource_group} --name={aks_name} " |
| 46 | + "--location={location} --no-ssh-key -o json") |
| 47 | + self.cmd(create_aks_cmd, checks=[ |
| 48 | + self.check("provisioningState", "Succeeded")]) |
| 49 | + |
| 50 | + list_identity_binding_cmd = ("aks identity-binding list --resource-group {resource_group} " |
| 51 | + "--cluster-name {aks_name} -o json") |
| 52 | + self.cmd( |
| 53 | + list_identity_binding_cmd, |
| 54 | + checks=[ |
| 55 | + self.check("length(@)", 0) |
| 56 | + ] |
| 57 | + ) |
| 58 | + |
| 59 | + create_identity_cmd = ("identity create --resource-group {resource_group} --name {identity_name} " |
| 60 | + "--location {location} -o json") |
| 61 | + identity = self.cmd(create_identity_cmd).get_output_in_json() |
| 62 | + identity_resource_id = identity["id"] |
| 63 | + identity_client_id = identity["clientId"] |
| 64 | + identity_tenant_id = identity["tenantId"] |
| 65 | + |
| 66 | + identity_binding_checks = [ |
| 67 | + self.check("properties.provisioningState", "Succeeded"), |
| 68 | + self.check( |
| 69 | + "properties.managedIdentity.resourceId", |
| 70 | + identity_resource_id |
| 71 | + ), |
| 72 | + self.check( |
| 73 | + "properties.managedIdentity.clientId", |
| 74 | + identity_client_id |
| 75 | + ), |
| 76 | + self.check( |
| 77 | + "properties.managedIdentity.tenantId", |
| 78 | + identity_tenant_id |
| 79 | + ), |
| 80 | + self.check( |
| 81 | + f"ends_with(properties.oidcIssuer.oidcIssuerUrl, '/{identity_tenant_id}/{identity_client_id}')", |
| 82 | + True, |
| 83 | + ), |
| 84 | + ] |
| 85 | + |
| 86 | + create_identity_binding_cmd = ("aks identity-binding create --resource-group {resource_group} --cluster-name {aks_name} " |
| 87 | + "-n {identity_binding_name} -o json" |
| 88 | + f" --managed-identity-resource-id {identity_resource_id}") |
| 89 | + self.cmd(create_identity_binding_cmd, checks=identity_binding_checks) |
| 90 | + |
| 91 | + self.cmd( |
| 92 | + list_identity_binding_cmd, |
| 93 | + checks=[ |
| 94 | + self.check("length(@)", 1) |
| 95 | + ] |
| 96 | + ) |
| 97 | + |
| 98 | + show_identity_binding_cmd = ("aks identity-binding show --resource-group {resource_group} --cluster-name {aks_name} " |
| 99 | + "-n {identity_binding_name} -o json") |
| 100 | + self.cmd(show_identity_binding_cmd, checks=identity_binding_checks) |
| 101 | + |
| 102 | + delete_identity_binding_cmd = ("aks identity-binding delete --resource-group {resource_group} --cluster-name {aks_name} " |
| 103 | + "-n {identity_binding_name} --yes -o json") |
| 104 | + self.cmd(delete_identity_binding_cmd) |
| 105 | + |
| 106 | + self.cmd( |
| 107 | + list_identity_binding_cmd, |
| 108 | + checks=[ |
| 109 | + self.check("length(@)", 0) |
| 110 | + ] |
| 111 | + ) |
0 commit comments