Skip to content

Commit

Permalink
Add support and tests for SSL on custom domains in CDN (Azure#5406)
Browse files Browse the repository at this point in the history
* Add support and tests for SSL on custom domains in CDN

* Fix the test failure for profiles

* Fix the build and refactor the profile tests

Since we use an existing susbscription that is used for other testing too, the tests failed beacuse they assumed it is a clean subscription. I changed that assumption so that they(hopefully) work with any subscription in record mode.

* Update nuget package version

* Update file version

* Update the moinor version since new functionality was added
  • Loading branch information
nachakra authored and mentat9 committed Jun 10, 2019
1 parent 50abde5 commit 87720be
Show file tree
Hide file tree
Showing 28 changed files with 5,219 additions and 2,359 deletions.
41 changes: 32 additions & 9 deletions src/SDKs/Cdn/Cdn.Tests/ScenarioTests/CustomDomainTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Cdn.Tests.ScenarioTests
{
public class CustomDomainTests
{
[Fact(Skip = "ReRecord due to CR change")]
[Fact]
public void CustomDomainCRUDTest()
{
var handler1 = new RecordedDelegatingHandler { StatusCodeToReturn = HttpStatusCode.OK };
Expand All @@ -36,7 +36,7 @@ public void CustomDomainCRUDTest()
Profile createParameters = new Profile
{
Location = "WestUs",
Sku = new Sku { Name = SkuName.StandardVerizon },
Sku = new Sku { Name = SkuName.StandardMicrosoft },
Tags = new Dictionary<string, string>
{
{"key1","value1"},
Expand Down Expand Up @@ -70,13 +70,13 @@ public void CustomDomainCRUDTest()
Assert.Empty(customDomains);

// NOTE: There is a CName mapping already created for this custom domain and endpoint hostname
// "sdk-1-f3757d2a3e10.azureedge-test.net" maps to "endpoint-f3757d2a3e10.azureedge.net"
// "sdk-2-f3757d2a3e10.azureedge-test.net" maps to "endpoint-f3757d2a3e10.azureedge.net"
// "sdk-1-f3757d2a3e10.DUSTYDOGPETCARE.US" maps to "endpoint-f3757d2a3e10.azureedge.net"
// "sdk-2-f3757d2a3e10.DUSTYDOGPETCARE.US" maps to "endpoint-f3757d2a3e10.azureedge.net"

// Create custom domain on running endpoint should succeed
string customDomainName1 = TestUtilities.GenerateName("customDomain");

cdnMgmtClient.CustomDomains.Create(resourceGroupName, profileName, endpointName, customDomainName1, "sdk-1-f3757d2a3e10.azureedge-test.net");
cdnMgmtClient.CustomDomains.Create(resourceGroupName, profileName, endpointName, customDomainName1, "sdk-1-f3757d2a3e10.DUSTYDOGPETCARE.US");

// List custom domains one this endpoint should return one
customDomains = cdnMgmtClient.CustomDomains.ListByEndpoint(resourceGroupName, profileName, endpointName);
Expand All @@ -87,13 +87,13 @@ public void CustomDomainCRUDTest()

// Create another custom domain on stopped endpoint should succeed
string customDomainName2 = TestUtilities.GenerateName("customDomain");
cdnMgmtClient.CustomDomains.Create(resourceGroupName, profileName, endpointName, customDomainName2, "sdk-2-f3757d2a3e10.azureedge-test.net");
cdnMgmtClient.CustomDomains.Create(resourceGroupName, profileName, endpointName, customDomainName2, "sdk-2-f3757d2a3e10.DUSTYDOGPETCARE.US");

// List custom domains one this endpoint should return two
customDomains = cdnMgmtClient.CustomDomains.ListByEndpoint(resourceGroupName, profileName, endpointName);
Assert.Equal(2, customDomains.Count());

// Enable custom https on custom domain that is already enabled should fail
// Disable custom https on custom domain that is not enabled should fail
Assert.ThrowsAny<ErrorResponseException>(() => {
cdnMgmtClient.CustomDomains.DisableCustomHttps(resourceGroupName, profileName, endpointName, customDomainName2);
});
Expand All @@ -112,17 +112,40 @@ public void CustomDomainCRUDTest()
// Start endpoint
cdnMgmtClient.Endpoints.Start(resourceGroupName, profileName, endpointName);

// Enable custom https on custom domain that is already enabled should fail
// Enable custom https using CDN managed certificate on custom domain
cdnMgmtClient.CustomDomains.EnableCustomHttps(resourceGroupName, profileName, endpointName, customDomainName1);

// Delete first custom domain on stopped endpoint should succeed
// add the same deleted custom domain again
cdnMgmtClient.CustomDomains.Create(resourceGroupName, profileName, endpointName, customDomainName2, "sdk-2-f3757d2a3e10.DUSTYDOGPETCARE.US");

// Enable custom https using BYOC on custom domain
var byocParameters = new KeyVaultCertificateSourceParameters()
{
ResourceGroupName = "byoc",
SecretName = "CdnSDKE2EBYOCTest",
SecretVersion = "526c5d25cc1a46a5bb85ce85ee2b89cc",
SubscriptionId = "3c0124f9-e564-4c42-86f7-fa79457aedc3",
VaultName = "Azure-CDN-BYOC"
};

cdnMgmtClient.CustomDomains.EnableCustomHttps(resourceGroupName, profileName, endpointName, customDomainName2, new UserManagedHttpsParameters(ProtocolType.ServerNameIndication, byocParameters));

// Delete first custom domain should succeed
cdnMgmtClient.CustomDomains.Delete(resourceGroupName, profileName, endpointName, customDomainName1);

// Get deleted custom domain should fail
Assert.ThrowsAny<ErrorResponseException>(() => {
cdnMgmtClient.CustomDomains.Get(resourceGroupName, profileName, endpointName, customDomainName1);
});

// Delete second custom domain should succeed
cdnMgmtClient.CustomDomains.Delete(resourceGroupName, profileName, endpointName, customDomainName2);

// Get deleted custom domain should fail
Assert.ThrowsAny<ErrorResponseException>(() => {
cdnMgmtClient.CustomDomains.Get(resourceGroupName, profileName, endpointName, customDomainName2);
});

// List custom domains on endpoint should return none
customDomains = cdnMgmtClient.CustomDomains.ListByEndpoint(resourceGroupName, profileName, endpointName);
Assert.Empty(customDomains);
Expand Down
46 changes: 21 additions & 25 deletions src/SDKs/Cdn/Cdn.Tests/ScenarioTests/ProfileTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -381,14 +381,14 @@ public void ProfileListBySubcriptionTest()
// Create clients
var cdnMgmtClient = CdnTestUtilities.GetCdnManagementClient(context, handler1);
var resourcesClient = CdnTestUtilities.GetResourceManagementClient(context, handler2);

// List profiles should return none
var profiles = cdnMgmtClient.Profiles.List();
Assert.Empty(profiles);


// Create resource group
var resourceGroupName1 = CdnTestUtilities.CreateResourceGroup(resourcesClient);

// List profiles should return all profiles in the subscription
var profiles = cdnMgmtClient.Profiles.List();
var existingProfileCount = profiles.Count();

// Create a standard cdn profile
string profileName = TestUtilities.GenerateName("profile");
Profile createParameters = new Profile
Expand All @@ -409,10 +409,6 @@ public void ProfileListBySubcriptionTest()
var existingProfile = cdnMgmtClient.Profiles.Get(resourceGroupName1, profileName);
VerifyProfilesEqual(profile, existingProfile);

// List profiles should return one profile
profiles = cdnMgmtClient.Profiles.List();
Assert.Single(profiles);

// Create another resource group
var resourceGroupName2 = CdnTestUtilities.CreateResourceGroup(resourcesClient);

Expand All @@ -432,23 +428,23 @@ public void ProfileListBySubcriptionTest()
profile = cdnMgmtClient.Profiles.Create(resourceGroupName2, profileName2, createParameters);
VerifyProfileCreated(profile, createParameters);

// List profiles should return two profiles
// List profiles should return the new profiles
profiles = cdnMgmtClient.Profiles.List();
Assert.Equal(2, profiles.Count());

Assert.Equal(existingProfileCount + 2, profiles.Count());
// Delete first profile
cdnMgmtClient.Profiles.Delete(resourceGroupName1, profileName);

// List profiles should return only one profile
// List profiles should return initial profile count + 1
profiles = cdnMgmtClient.Profiles.List();
Assert.Single(profiles);
Assert.Equal(existingProfileCount + 1, profiles.Count());

// Delete second profile
cdnMgmtClient.Profiles.Delete(resourceGroupName2, profileName2);

// List profiles should none
// List profiles should return initial profile count
profiles = cdnMgmtClient.Profiles.List();
Assert.Empty(profiles);
Assert.Equal(existingProfileCount, profiles.Count());

// Delete resource groups
CdnTestUtilities.DeleteResourceGroup(resourcesClient, resourceGroupName1);
Expand Down Expand Up @@ -573,13 +569,13 @@ public void ProfileCheckUsageTest()
var cdnMgmtClient = CdnTestUtilities.GetCdnManagementClient(context, handler1);
var resourcesClient = CdnTestUtilities.GetResourceManagementClient(context, handler2);

// CheckUsage on subscription should return zero profiles
// CheckUsage on subscription to get existing usage for profiles
var subscriptionLevelUsages = cdnMgmtClient.ResourceUsage.List();
Assert.Single(subscriptionLevelUsages);

var defaultUsage = subscriptionLevelUsages.First();
Assert.Equal(25, defaultUsage.Limit);
Assert.Equal(0, defaultUsage.CurrentValue);
var defaultSubscriptionUsage = subscriptionLevelUsages.First();
var existingSubscriptionUsageLimit = defaultSubscriptionUsage.Limit;
var existingSubscriptionUsageCurrentValue = defaultSubscriptionUsage.CurrentValue;

// Create resource group
var resourceGroupName = CdnTestUtilities.CreateResourceGroup(resourcesClient);
Expand All @@ -604,15 +600,15 @@ public void ProfileCheckUsageTest()
Assert.Single(subscriptionLevelUsages);

var usageAfterCreation = subscriptionLevelUsages.First();
Assert.Equal(25, usageAfterCreation.Limit);
Assert.Equal(1, usageAfterCreation.CurrentValue);
Assert.Equal(existingSubscriptionUsageLimit, usageAfterCreation.Limit);
Assert.Equal(existingSubscriptionUsageCurrentValue + 1, usageAfterCreation.CurrentValue);

// test Profile level usage
// test Profile level usage - usage for endpoints under the profile
var profileLevelUsages = cdnMgmtClient.Profiles.ListResourceUsage(resourceGroupName, profileName);
Assert.Single(profileLevelUsages);

var profileLevelUsage = profileLevelUsages.First();
Assert.Equal(10, profileLevelUsage.Limit);
Assert.Equal(25, profileLevelUsage.Limit);
Assert.Equal(0, profileLevelUsage.CurrentValue);

//Create an endpoint under this profile
Expand All @@ -638,7 +634,7 @@ public void ProfileCheckUsageTest()
Assert.Single(profileLevelUsages);

var profileLevelUsageAfterEndpointCreation = profileLevelUsages.First();
Assert.Equal(10, profileLevelUsageAfterEndpointCreation.Limit);
Assert.Equal(25, profileLevelUsageAfterEndpointCreation.Limit);
Assert.Equal(1, profileLevelUsageAfterEndpointCreation.CurrentValue);

// Delete resource group
Expand Down
Loading

0 comments on commit 87720be

Please sign in to comment.