Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
08c5b2a
Add generation of 2023-07-01-preview and new tests for dns resolver d…
jamesvoongms Sep 20, 2024
02660d3
Add rule and link tests
jamesvoongms Sep 24, 2024
ecf5176
Fix test domain names and add to code owners and fix readme link to s…
jamesvoongms Oct 4, 2024
60b67fe
Fix CODEOWNERS for dns resolver
jamesvoongms Oct 4, 2024
a4565e1
Merge remote-tracking branch 'origin/main' into release-2023-07-01-pr…
jamesvoong Oct 4, 2024
b6b4cb1
Merge branch 'main' into release-2023-07-01-preview-dns-resolver-poli…
jamesvoongms Oct 4, 2024
c3dfd1b
Update .github/CODEOWNERS
jamesvoongms Oct 7, 2024
cd39810
Update .github/CODEOWNERS
jamesvoongms Oct 7, 2024
482c846
Merge branch 'release-2023-07-01-preview-dns-resolver-policy-addition…
jamesvoongms Oct 7, 2024
4970154
Fix additional codeowner addition
jamesvoongms Oct 7, 2024
4f0a10b
Add Servfail to cspell word list
jamesvoongms Oct 7, 2024
e7b550d
Run Export-Api
jamesvoongms Oct 7, 2024
d3128b5
Add assets file after pushing recording
jamesvoongms Oct 7, 2024
0d266d9
Record tests for dns resolver as well
jamesvoongms Oct 7, 2024
810dd26
Change ActionType to DnsSecurityRuleActionTYpe
jamesvoongms Oct 8, 2024
1782531
Re-record DNS security rule tests after ActionType changes
jamesvoongms Oct 8, 2024
4d958d7
Change DNS resolver to DNS private resolver in codeowners
jamesvoongms Oct 8, 2024
0a749b4
Merge remote-tracking branch 'origin/main' into release-2023-07-01-pr…
jamesvoong Oct 11, 2024
98224c6
Add new release version and notes
jamesvoongms Oct 11, 2024
34fe153
Fix to using 1.2.0-beta.1 as the new version
jamesvoongms Oct 11, 2024
23976f4
Remove empty sections in the changelog
jamesvoongms Oct 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add rule and link tests
  • Loading branch information
jamesvoongms committed Sep 24, 2024
commit 02660d388208d267538ae2036ef25b8d63af1578
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class DnsResolverTestBase : ManagementRecordedTestBase<DnsResolverManagem
public ResourceIdentifier DefaultVnetID;
public ResourceIdentifier DefaultSubnetID;
protected AzureLocation DefaultLocation => AzureLocation.AustraliaEast;
protected int DefaultDnsSecurityRulePriority => 100;
protected ArmClient Client { get; private set; }
protected SubscriptionResource DefaultSubscription { get; private set; }
public DnsResolverTestBase(bool isAsync) : base(isAsync)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System.Threading.Tasks;
using NUnit.Framework;
using Azure.Core.TestFramework;
using Azure.ResourceManager.Resources.Models;
using Azure.Core;
using Azure.ResourceManager.DnsResolver.Models;
using System.Linq;
using System.Collections.Generic;

namespace Azure.ResourceManager.DnsResolver.Tests
{
public class DnsResolverPolicyLinkTests : DnsResolverTestBase
{
private DnsResolverPolicyCollection _dnsResolverPolicyCollection;
private DnsResolverPolicyResource _dnsResolverPolicy;
private string _dnsResolverPolicyName;

public DnsResolverPolicyLinkTests(bool async) : base(async)//, RecordedTestMode.Record)
{
}

public async Task CreateDnsResolverCollection()
{
var vnetName = Recording.GenerateAssetName("vnet-");
_dnsResolverPolicyName = Recording.GenerateAssetName("dnsResolverPolicy-");
var resourceGroup = await CreateResourceGroupAsync();
_dnsResolverPolicyCollection = resourceGroup.GetDnsResolverPolicies();

await CreateVirtualNetworkAsync();
_dnsResolverPolicy = await CreateDnsResolverPolicy(_dnsResolverPolicyName);
}

private async Task<DnsResolverPolicyResource> CreateDnsResolverPolicy(string dnsResolverPolicyName)
{
var dnsResolverPolicyData = new DnsResolverPolicyData(this.DefaultLocation);

return (await _dnsResolverPolicyCollection.CreateOrUpdateAsync(WaitUntil.Completed, dnsResolverPolicyName, dnsResolverPolicyData)).Value;
}

[Test]
[RecordedTest]
public async Task CreateDnsResolverPolicyLink()
{
// ARRANGE
var dnsResolverPolicyLinkName = Recording.GenerateAssetName("dnsResolverPolicyLink-");
await CreateDnsResolverCollection();
var dnsResolverPolicyLinkData = new DnsResolverPolicyVirtualNetworkLinkData(this.DefaultLocation, new WritableSubResource
{
Id = new ResourceIdentifier(DefaultVnetID),
});

// ACT
var createdDnsResolverPolicyLink = await _dnsResolverPolicy.GetDnsResolverPolicyVirtualNetworkLinks().CreateOrUpdateAsync(WaitUntil.Completed, dnsResolverPolicyLinkName, dnsResolverPolicyLinkData);

// ASSERT
Assert.AreEqual(createdDnsResolverPolicyLink.Value.Data.ProvisioningState, DnsResolverProvisioningState.Succeeded);
}

[Test]
[RecordedTest]
public async Task GetDnsResolverPolicyLink()
{
// ARRANGE
var dnsResolverPolicyLinkName = Recording.GenerateAssetName("dnsResolverPolicyLink-");
await CreateDnsResolverCollection();
var dnsResolverPolicyLinkData = new DnsResolverPolicyVirtualNetworkLinkData(this.DefaultLocation, new WritableSubResource
{
Id = new ResourceIdentifier(DefaultVnetID),
});

await _dnsResolverPolicy.GetDnsResolverPolicyVirtualNetworkLinks().CreateOrUpdateAsync(WaitUntil.Completed, dnsResolverPolicyLinkName, dnsResolverPolicyLinkData);

// ACT
var retrievedDnsResolverPolicyLink = await _dnsResolverPolicy.GetDnsResolverPolicyVirtualNetworkLinks().GetAsync(dnsResolverPolicyLinkName);

// ASSERT
Assert.AreEqual(retrievedDnsResolverPolicyLink.Value.Data.Name, dnsResolverPolicyLinkName);
}

[Test]
[RecordedTest]
public async Task UpdateDnsResolverPolicyLink()
{
// ARRANGE
var dnsResolverPolicyLinkName = Recording.GenerateAssetName("dnsResolverPolicyLink-");
var newTagKey = Recording.GenerateAlphaNumericId("tagKey");
var newTagValue = Recording.GenerateAlphaNumericId("tagValue");
await CreateDnsResolverCollection();
var dnsResolverPolicyLinkData = new DnsResolverPolicyVirtualNetworkLinkData(this.DefaultLocation, new WritableSubResource
{
Id = new ResourceIdentifier(DefaultVnetID),
});

var createdDnsResolverPolicyLink = await _dnsResolverPolicy.GetDnsResolverPolicyVirtualNetworkLinks().CreateOrUpdateAsync(WaitUntil.Completed, dnsResolverPolicyLinkName, dnsResolverPolicyLinkData);

var patchableDnsResolverPolicyLinkData = new DnsResolverPolicyVirtualNetworkLinkPatch();
patchableDnsResolverPolicyLinkData.Tags.Add(newTagKey, newTagValue);

// ACT
var patchedDnsResolverPolicyLink = await createdDnsResolverPolicyLink.Value.UpdateAsync(WaitUntil.Completed, patchableDnsResolverPolicyLinkData);

// ASSERT
CollectionAssert.AreEquivalent(patchedDnsResolverPolicyLink.Value.Data.Tags, patchableDnsResolverPolicyLinkData.Tags);
}

[Test]
[RecordedTest]
public async Task RemoveDnsResolverPolicyLink()
{
// ARRANGE
var dnsResolverPolicyLinkName = Recording.GenerateAssetName("dnsResolverPolicyLink-");
await CreateDnsResolverCollection();
var dnsResolverPolicyLinkData = new DnsResolverPolicyVirtualNetworkLinkData(this.DefaultLocation, new WritableSubResource
{
Id = new ResourceIdentifier(DefaultVnetID),
});

var createdDnsResolverPolicyLink = await _dnsResolverPolicy.GetDnsResolverPolicyVirtualNetworkLinks().CreateOrUpdateAsync(WaitUntil.Completed, dnsResolverPolicyLinkName, dnsResolverPolicyLinkData);

// ACT
await createdDnsResolverPolicyLink.Value.DeleteAsync(WaitUntil.Completed);

// ASSERT
var getDnsResolverPolicyLink = await _dnsResolverPolicy.GetDnsResolverPolicyVirtualNetworkLinks().ExistsAsync(dnsResolverPolicyLinkName);
Assert.AreEqual(getDnsResolverPolicyLink.Value, false);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using System.Threading.Tasks;
using NUnit.Framework;
using Azure.Core.TestFramework;
using Azure.ResourceManager.Resources.Models;
using Azure.Core;
using Azure.ResourceManager.DnsResolver.Models;
using System.Linq;
using System.Collections.Generic;

namespace Azure.ResourceManager.DnsResolver.Tests
{
public class DnsSecurityRuleTests : DnsResolverTestBase
{
private DnsResolverPolicyCollection _dnsResolverPolicyCollection;
private DnsResolverDomainListCollection _dnsResolverDomainListCollection;
private DnsResolverPolicyResource _dnsResolverPolicy;
private DnsResolverDomainListResource _dnsResolverDomainList;
private string _dnsResolverPolicyName;
private string _dnsResolverDomainListName;

public DnsSecurityRuleTests(bool async) : base(async)//, RecordedTestMode.Record)
{
}

public async Task CreateDnsResolverCollection()
{
_dnsResolverPolicyName = Recording.GenerateAssetName("dnsResolverPolicy-");
_dnsResolverDomainListName = Recording.GenerateAssetName("dnsResolverDomainList-");
var resourceGroup = await CreateResourceGroupAsync();
_dnsResolverPolicyCollection = resourceGroup.GetDnsResolverPolicies();
_dnsResolverDomainListCollection = resourceGroup.GetDnsResolverDomainLists();

_dnsResolverPolicy = await CreateDnsResolverPolicy(_dnsResolverPolicyName);
_dnsResolverDomainList = await CreateDnsResolverDomainList(_dnsResolverDomainListName);
}

private async Task<DnsResolverPolicyResource> CreateDnsResolverPolicy(string dnsResolverPolicyName)
{
var dnsResolverPolicyData = new DnsResolverPolicyData(this.DefaultLocation);

return (await _dnsResolverPolicyCollection.CreateOrUpdateAsync(WaitUntil.Completed, dnsResolverPolicyName, dnsResolverPolicyData)).Value;
}

private async Task<DnsResolverDomainListResource> CreateDnsResolverDomainList(string dnsResolverDomainListName)
{
var defaultDomains = new List<string>() { "test.com.", "env.com." };
var dnsResolverDomainListData = new DnsResolverDomainListData(this.DefaultLocation, defaultDomains);

return (await _dnsResolverDomainListCollection.CreateOrUpdateAsync(WaitUntil.Completed, dnsResolverDomainListName, dnsResolverDomainListData)).Value;
}

[Test]
[RecordedTest]
public async Task CreateDnsSecurityRule()
{
// ARRANGE
var dnsSecurityRuleName = Recording.GenerateAssetName("dnsSecurityRule-");
await CreateDnsResolverCollection();
var dnsSecurityRuleAction = new DnsSecurityRuleAction() { ActionType = ActionType.Block, BlockResponseCode = BlockResponseCode.Servfail };

var dnsSecurityRuleData = new DnsSecurityRuleData(this.DefaultLocation, this.DefaultDnsSecurityRulePriority, dnsSecurityRuleAction,
new List<WritableSubResource> {
new WritableSubResource
{
Id = new ResourceIdentifier(_dnsResolverDomainList.Id),
}
}
);

// ACT
var createdDnsSecurityRule = await _dnsResolverPolicy.GetDnsSecurityRules().CreateOrUpdateAsync(WaitUntil.Completed, dnsSecurityRuleName, dnsSecurityRuleData);

// ASSERT
Assert.AreEqual(createdDnsSecurityRule.Value.Data.ProvisioningState, DnsResolverProvisioningState.Succeeded);
}

[Test]
[RecordedTest]
public async Task GetDnsSecurityRule()
{
// ARRANGE
var dnsSecurityRuleName = Recording.GenerateAssetName("dnsSecurityRule-");
await CreateDnsResolverCollection();
var dnsSecurityRuleAction = new DnsSecurityRuleAction() { ActionType = ActionType.Block, BlockResponseCode = BlockResponseCode.Servfail };

var dnsSecurityRuleData = new DnsSecurityRuleData(this.DefaultLocation, this.DefaultDnsSecurityRulePriority, dnsSecurityRuleAction,
new List<WritableSubResource> {
new WritableSubResource
{
Id = new ResourceIdentifier(_dnsResolverDomainList.Id),
}
}
);

await _dnsResolverPolicy.GetDnsSecurityRules().CreateOrUpdateAsync(WaitUntil.Completed, dnsSecurityRuleName, dnsSecurityRuleData);

// ACT
var retrievedDnsSecurityRule = await _dnsResolverPolicy.GetDnsSecurityRules().GetAsync(dnsSecurityRuleName);

// ASSERT
Assert.AreEqual(retrievedDnsSecurityRule.Value.Data.Name, dnsSecurityRuleName);
}

[Test]
[RecordedTest]
public async Task UpdateDnsSecurityRule()
{
// ARRANGE
var dnsSecurityRuleName = Recording.GenerateAssetName("dnsSecurityRule-");
var newTagKey = Recording.GenerateAlphaNumericId("tagKey");
var newTagValue = Recording.GenerateAlphaNumericId("tagValue");
await CreateDnsResolverCollection();
var dnsSecurityRuleAction = new DnsSecurityRuleAction() { ActionType = ActionType.Block, BlockResponseCode = BlockResponseCode.Servfail };

var dnsSecurityRuleData = new DnsSecurityRuleData(this.DefaultLocation, this.DefaultDnsSecurityRulePriority, dnsSecurityRuleAction,
new List<WritableSubResource> {
new WritableSubResource
{
Id = new ResourceIdentifier(_dnsResolverDomainList.Id),
}
}
);

var createdDnsSecurityRule = await _dnsResolverPolicy.GetDnsSecurityRules().CreateOrUpdateAsync(WaitUntil.Completed, dnsSecurityRuleName, dnsSecurityRuleData);

var patchableDnsSecurityRuleData = new DnsSecurityRulePatch();
patchableDnsSecurityRuleData.Tags.Add(newTagKey, newTagValue);

// ACT
var patchedDnsSecurityRule = await createdDnsSecurityRule.Value.UpdateAsync(WaitUntil.Completed, patchableDnsSecurityRuleData);

// ASSERT
CollectionAssert.AreEquivalent(patchedDnsSecurityRule.Value.Data.Tags, patchableDnsSecurityRuleData.Tags);
}

[Test]
[RecordedTest]
public async Task RemoveDnsSecurityRule()
{
// ARRANGE
var dnsSecurityRuleName = Recording.GenerateAssetName("dnsSecurityRule-");
await CreateDnsResolverCollection();
var dnsSecurityRuleAction = new DnsSecurityRuleAction() { ActionType = ActionType.Block, BlockResponseCode = BlockResponseCode.Servfail };

var dnsSecurityRuleData = new DnsSecurityRuleData(this.DefaultLocation, this.DefaultDnsSecurityRulePriority, dnsSecurityRuleAction,
new List<WritableSubResource> {
new WritableSubResource
{
Id = new ResourceIdentifier(_dnsResolverDomainList.Id),
}
}
);

var createdDnsSecurityRule = await _dnsResolverPolicy.GetDnsSecurityRules().CreateOrUpdateAsync(WaitUntil.Completed, dnsSecurityRuleName, dnsSecurityRuleData);

// ACT
await createdDnsSecurityRule.Value.DeleteAsync(WaitUntil.Completed);

// ASSERT
var getDnsSecurityRule = await _dnsResolverPolicy.GetDnsSecurityRules().ExistsAsync(dnsSecurityRuleName);
Assert.AreEqual(getDnsSecurityRule.Value, false);
}
}
}