Skip to content

Commit 5b224ed

Browse files
authored
Fix the Naptr records serialization issue (Azure#46386)
* Fix the Naptr records serialization issue * Update DnsRecordDataTest.cs * Update RecordTest.cs * Remove trailing whitespaces * Remove trailing whitespace * Update assets.json
1 parent 7376d41 commit 5b224ed

File tree

4 files changed

+147
-4
lines changed

4 files changed

+147
-4
lines changed

sdk/dns/Azure.ResourceManager.Dns/assets.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
"AssetsRepo": "Azure/azure-sdk-assets",
33
"AssetsRepoPrefixPath": "net",
44
"TagPrefix": "net/dns/Azure.ResourceManager.Dns",
5-
"Tag": "net/dns/Azure.ResourceManager.Dns_3e51cc04bf"
5+
"Tag": "net/dns/Azure.ResourceManager.Dns_653d15ae77"
66
}

sdk/dns/Azure.ResourceManager.Dns/src/Customization/Models/DnsNaptrData.Serialization.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ void IJsonModel<DnsNaptrRecordData>.Write(Utf8JsonWriter writer, ModelReaderWrit
8282
}
8383
if (Optional.IsCollectionDefined(DnsNaptrRecords))
8484
{
85-
writer.WritePropertyName("NaptrRecords"u8);
85+
writer.WritePropertyName("NAPTRRecords"u8);
8686
writer.WriteStartArray();
8787
foreach (var item in DnsNaptrRecords)
8888
{
@@ -234,7 +234,7 @@ internal static DnsNaptrRecordData DeserializeDnsNaptrRecordData(JsonElement ele
234234
trafficManagementProfile = JsonSerializer.Deserialize<WritableSubResource>(property0.Value.ToString());
235235
continue;
236236
}
237-
if (property0.NameEquals("NaptrRecords"u8))
237+
if (property0.NameEquals("NAPTRRecords"u8))
238238
{
239239
if (property0.Value.ValueKind == JsonValueKind.Null)
240240
{

sdk/dns/Azure.ResourceManager.Dns/tests/Scenario/DnsRecordDataTest.cs

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public async Task RecordTypeRetrive()
4444
await Create_SRV();
4545
await Create_TXT();
4646
await Create_PTR();
47+
await Create_NAPTR();
4748
var allRecordData = _dnsZone.GetAllRecordDataAsync();
4849
// NS SOA is created by default
4950
await foreach (Dns.DnsRecordData item in allRecordData)
@@ -53,7 +54,7 @@ public async Task RecordTypeRetrive()
5354
Console.WriteLine(recordType.ToString());
5455
count++;
5556
}
56-
Assert.AreEqual(count, 10);
57+
Assert.AreEqual(count, 11);
5758
}
5859

5960
private async Task Create_A()
@@ -176,6 +177,52 @@ private async Task Create_MX()
176177
var mxRecord = await collection.CreateOrUpdateAsync(WaitUntil.Completed, mxRecordName, data);
177178
}
178179

180+
private async Task Create_NAPTR()
181+
{
182+
var collection = _dnsZone.GetDnsNaptrRecords();
183+
string naptrRecordName = Recording.GenerateAssetName("naptr");
184+
int orderValue1 = 1;
185+
int orderValue2 = 2;
186+
int preferenceValue1 = 10;
187+
int preferenceValue2 = 20;
188+
string flagsValue1 = "s";
189+
string flagsValue2 = "a";
190+
string servicesValue1 = "e2u";
191+
string servicesValue2 = "sip";
192+
string regexpValue1 = "!^(\\+441632960083)$!sip:\\[email protected]!";
193+
string regexpValue2 = "";
194+
string replacementValue1 = ".";
195+
string replacementValue2 = "customer-service.example.com";
196+
197+
// CreateOrUpdate
198+
var data = new DnsNaptrRecordData()
199+
{
200+
TtlInSeconds = 3600,
201+
DnsNaptrRecords =
202+
{
203+
new DnsNaptrRecordInfo()
204+
{
205+
Order = orderValue1,
206+
Preference = preferenceValue1,
207+
Flags = flagsValue1,
208+
Services = servicesValue1,
209+
Regexp = regexpValue1,
210+
Replacement = replacementValue1
211+
},
212+
new DnsNaptrRecordInfo()
213+
{
214+
Order = orderValue2,
215+
Preference = preferenceValue2,
216+
Flags = flagsValue2,
217+
Services = servicesValue2,
218+
Regexp = regexpValue2,
219+
Replacement = replacementValue2
220+
},
221+
}
222+
};
223+
var naptrRecord = await collection.CreateOrUpdateAsync(WaitUntil.Completed, naptrRecordName, data);
224+
}
225+
179226
private async Task Create_SRV()
180227
{
181228
var collection = _dnsZone.GetDnsSrvRecords();

sdk/dns/Azure.ResourceManager.Dns/tests/Scenario/RecordTest.cs

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,102 @@ public async Task MXRecordOperationTest()
395395
Assert.IsFalse(flag);
396396
}
397397

398+
[RecordedTest]
399+
public async Task NAPTRRecordOperationTest()
400+
{
401+
var collection = _dnsZone.GetDnsNaptrRecords();
402+
string naptrRecordName = Recording.GenerateAssetName("naptr");
403+
int orderValue1 = 10;
404+
int orderValue2 = 20;
405+
int preferenceValue1 = 100;
406+
int preferenceValue2 = 200;
407+
string flagsValue1 = "s";
408+
string flagsValue2 = "a";
409+
string servicesValue1 = "eau";
410+
string servicesValue2 = "eau+sip";
411+
string regexpValue1 = "";
412+
string regexpValue2 = "!^(\\+441632960083)$!sip:\\[email protected]!";
413+
string replacementValue1 = "sip.contoso.com";
414+
string replacementValue2 = ".";
415+
// CreateOrUpdate
416+
var data = new DnsNaptrRecordData()
417+
{
418+
TtlInSeconds = 3600,
419+
DnsNaptrRecords =
420+
{
421+
new DnsNaptrRecordInfo()
422+
{
423+
Order = orderValue1,
424+
Preference = preferenceValue1,
425+
Flags = flagsValue1,
426+
Services = servicesValue1,
427+
Regexp = regexpValue1,
428+
Replacement = replacementValue1
429+
},
430+
new DnsNaptrRecordInfo()
431+
{
432+
Order = orderValue2,
433+
Preference = preferenceValue2,
434+
Flags = flagsValue2,
435+
Services = servicesValue2,
436+
Regexp = regexpValue2,
437+
Replacement = replacementValue2
438+
},
439+
}
440+
};
441+
442+
var naptrRecord = await collection.CreateOrUpdateAsync(WaitUntil.Completed, naptrRecordName, data);
443+
ValidateRecordBaseInfo(naptrRecord.Value.Data, naptrRecordName);
444+
Assert.AreEqual("dnszones/NAPTR", naptrRecord.Value.Data.ResourceType.Type.ToString());
445+
Assert.AreEqual(3600, naptrRecord.Value.Data.TtlInSeconds);
446+
Assert.AreEqual(orderValue1, naptrRecord.Value.Data.DnsNaptrRecords[0].Order);
447+
Assert.AreEqual(preferenceValue1, naptrRecord.Value.Data.DnsNaptrRecords[0].Preference);
448+
Assert.AreEqual(flagsValue1, naptrRecord.Value.Data.DnsNaptrRecords[0].Flags);
449+
Assert.AreEqual(servicesValue1, naptrRecord.Value.Data.DnsNaptrRecords[0].Services);
450+
Assert.AreEqual(regexpValue1, naptrRecord.Value.Data.DnsNaptrRecords[0].Regexp);
451+
Assert.AreEqual(replacementValue1, naptrRecord.Value.Data.DnsNaptrRecords[0].Replacement);
452+
Assert.AreEqual(orderValue2, naptrRecord.Value.Data.DnsNaptrRecords[1].Order);
453+
Assert.AreEqual(preferenceValue2, naptrRecord.Value.Data.DnsNaptrRecords[1].Preference);
454+
Assert.AreEqual(flagsValue2, naptrRecord.Value.Data.DnsNaptrRecords[1].Flags);
455+
Assert.AreEqual(servicesValue2, naptrRecord.Value.Data.DnsNaptrRecords[1].Services);
456+
Assert.AreEqual(regexpValue2, naptrRecord.Value.Data.DnsNaptrRecords[1].Regexp);
457+
Assert.AreEqual(replacementValue2, naptrRecord.Value.Data.DnsNaptrRecords[1].Replacement);
458+
459+
// Exist
460+
bool flag = await collection.ExistsAsync(naptrRecordName);
461+
Assert.IsTrue(flag);
462+
463+
// Update
464+
var updateResponse = await naptrRecord.Value.UpdateAsync(new DnsNaptrRecordData() { TtlInSeconds = 7200 });
465+
Assert.AreEqual(7200, updateResponse.Value.Data.TtlInSeconds);
466+
467+
// Get
468+
var getResponse = await collection.GetAsync(naptrRecordName);
469+
ValidateRecordBaseInfo(getResponse.Value.Data, naptrRecordName);
470+
Assert.AreEqual(orderValue1, naptrRecord.Value.Data.DnsNaptrRecords[0].Order);
471+
Assert.AreEqual(preferenceValue1, naptrRecord.Value.Data.DnsNaptrRecords[0].Preference);
472+
Assert.AreEqual(flagsValue1, naptrRecord.Value.Data.DnsNaptrRecords[0].Flags);
473+
Assert.AreEqual(servicesValue1, naptrRecord.Value.Data.DnsNaptrRecords[0].Services);
474+
Assert.AreEqual(regexpValue1, naptrRecord.Value.Data.DnsNaptrRecords[0].Regexp);
475+
Assert.AreEqual(replacementValue1, naptrRecord.Value.Data.DnsNaptrRecords[0].Replacement);
476+
Assert.AreEqual(orderValue2, naptrRecord.Value.Data.DnsNaptrRecords[1].Order);
477+
Assert.AreEqual(preferenceValue2, naptrRecord.Value.Data.DnsNaptrRecords[1].Preference);
478+
Assert.AreEqual(flagsValue2, naptrRecord.Value.Data.DnsNaptrRecords[1].Flags);
479+
Assert.AreEqual(servicesValue2, naptrRecord.Value.Data.DnsNaptrRecords[1].Services);
480+
Assert.AreEqual(regexpValue2, naptrRecord.Value.Data.DnsNaptrRecords[1].Regexp);
481+
Assert.AreEqual(replacementValue2, naptrRecord.Value.Data.DnsNaptrRecords[1].Replacement);
482+
483+
// GetAll
484+
var list = await collection.GetAllAsync().ToEnumerableAsync();
485+
Assert.IsNotEmpty(list);
486+
ValidateRecordBaseInfo(list.First(item => item.Data.Name == naptrRecordName).Data, naptrRecordName);
487+
488+
// Delete
489+
await naptrRecord.Value.DeleteAsync(WaitUntil.Completed);
490+
flag = await collection.ExistsAsync(naptrRecordName);
491+
Assert.IsFalse(flag);
492+
}
493+
398494
[RecordedTest]
399495
public async Task NSRecordOperationTest()
400496
{

0 commit comments

Comments
 (0)