예제 #1
0
        public void CanGetSingleVaultTest()
        {
            getVaultCmdlet = new GetAzureKeyVault()
            {
                CommandRuntime           = commandRuntimeMock.Object,
                ResourcesClient          = resourcesClientMock.Object,
                KeyVaultManagementClient = keyVaultMgmtClientMock.Object,
                ActiveDirectoryClient    = adClientMock.Object,
                VaultName         = vaultName,
                ResourceGroupName = resourceGroupName
            };

            ManagementApi.Vault mgmtVault = new ManagementApi.Vault()
            {
                Id         = "/subscriptions/aaaa/resourceGroups/" + resourceGroupName + "/providers/Microsoft.KeyVault/vaults/" + vaultName,
                Location   = "East US",
                Name       = vaultName,
                Type       = "Microsoft.KeyVault/vaults",
                Properties = new ManagementApi.VaultProperties()
                {
                    EnabledForDeployment = true,
                    Sku = new ManagementApi.Sku()
                    {
                        Family = "A", Name = "Standard"
                    },
                    TenantId       = tenantId,
                    VaultUri       = "https://" + vaultName + ".vault.azure.net",
                    AccessPolicies = new List <ManagementApi.AccessPolicyEntry>()
                    {
                        new ManagementApi.AccessPolicyEntry()
                        {
                            TenantId             = tenantId,
                            ObjectId             = objectId,
                            PermissionsToKeys    = new string[] { "all" },
                            PermissionsToSecrets = new string[] { "all" }
                        }
                    }
                }
            };

            keyVaultMgmtClientMock.Setup(kv => kv.GetVault(vaultName, resourceGroupName, adClientMock.Object)).Returns(new Vault(mgmtVault, adClientMock.Object));
            adClientMock.Setup(ad => ad.GetADObject(new ADObjectFilterOptions()
            {
                Id     = objectId.ToString(),
                Paging = true,
            })).Returns(new PSADServicePrincipal()
            {
                Id                   = objectId,
                DisplayName          = "Test App",
                ServicePrincipalName = "http://contoso.com",
            });

            getVaultCmdlet.ExecuteCmdlet();
            keyVaultMgmtClientMock.VerifyAll();
            adClientMock.VerifyAll();
        }
        public void CanGetSingleVaultTest()
        {
            getVaultCmdlet = new GetAzureKeyVault()
            {
                CommandRuntime = commandRuntimeMock.Object,
                ResourcesClient = resourcesClientMock.Object,
                KeyVaultManagementClient = keyVaultMgmtClientMock.Object,
                ActiveDirectoryClient = adClientMock.Object,
                VaultName = vaultName,
                ResourceGroupName = resourceGroupName
            };

            ManagementApi.Vault mgmtVault = new ManagementApi.Vault()
            {
                Id = "/subscriptions/aaaa/resourceGroups/" + resourceGroupName + "/providers/Microsoft.KeyVault/vaults/" + vaultName,
                Location = "East US",
                Name = vaultName,
                Type = "Microsoft.KeyVault/vaults",
                Properties = new ManagementApi.VaultProperties()
                {
                    EnabledForDeployment = true,
                    Sku = new ManagementApi.Sku() { Family = "A", Name = "Standard" },
                    TenantId = tenantId,
                    VaultUri = "https://" + vaultName + ".vault.azure.net",
                    AccessPolicies = new List<ManagementApi.AccessPolicyEntry>(){
                               new ManagementApi.AccessPolicyEntry()
                               {
                                   TenantId = tenantId,
                                   ObjectId = objectId,
                                   PermissionsToKeys = new string[]{"all"},
                                   PermissionsToSecrets = new string[] {"all"}
                               }
                           }
                }
            };

            keyVaultMgmtClientMock.Setup(kv => kv.GetVault(vaultName, resourceGroupName, adClientMock.Object)).Returns(new Vault(mgmtVault, adClientMock.Object));
            adClientMock.Setup(ad => ad.GetADObject(new ADObjectFilterOptions()
                {
                    Id = objectId.ToString(),
                    Paging = true,
                })).Returns(new PSADServicePrincipal()
                {
                    Id = objectId,
                    DisplayName = "Test App",
                    ServicePrincipalName = "http://contoso.com",
                });

            getVaultCmdlet.ExecuteCmdlet();
            keyVaultMgmtClientMock.VerifyAll();
            adClientMock.VerifyAll();
        }
예제 #3
0
        public PSVault(KeyVaultManagement.Vault vault, PSResourceManagerModels.ActiveDirectory.ActiveDirectoryClient adClient)
        {
            var vaultTenantDisplayName = ModelExtensions.GetDisplayNameForTenant(vault.Properties.TenantId, adClient);

            VaultName         = vault.Name;
            Location          = vault.Location;
            ResourceId        = vault.Id;
            ResourceGroupName = (new PSResourceManagerModels.ResourceIdentifier(vault.Id)).ResourceGroupName;
            Tags                 = TagsConversionHelper.CreateTagHashtable(vault.Tags);
            Sku                  = vault.Properties.Sku.Name;
            TenantId             = vault.Properties.TenantId;
            TenantName           = vaultTenantDisplayName;
            VaultUri             = vault.Properties.VaultUri;
            EnabledForDeployment = vault.Properties.EnabledForDeployment;
            AccessPolicies       = vault.Properties.AccessPolicies.Select(s => new PSVaultAccessPolicy(s, adClient)).ToArray();
            OriginalVault        = vault;
        }