Azure / azure-libraries-for-net

Azure libraries for .Net
MIT License
380 stars 192 forks source link

[BUG] AnalyzeCustomHostnameAsync does not work #642

Open Suchiman opened 5 years ago

Suchiman commented 5 years ago

Describe the bug If you call AnalyzeCustomHostnameAsync you get an exception because the Request forgot to include Accept: application/json and thus got XML as response. If you fix this with a DelegatingHandler, then you get an object with all properties set to null returned.

Exception or Stack Trace

Microsoft.Rest.SerializationException
  HResult=0x80131500
  Message=Unable to deserialize the response.
  Source=Microsoft.Azure.Management.AppService.Fluent
  StackTrace:
   at Microsoft.Azure.Management.AppService.Fluent.WebAppsOperations.<AnalyzeCustomHostnameWithHttpMessagesAsync>d__11.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Azure.Management.AppService.Fluent.WebAppsOperationsExtensions.<AnalyzeCustomHostnameAsync>d__6.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at AzureTest.Program.<AddDomainAsync>d__1.MoveNext() in Program.cs:line 84
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at AzureTest.Program.<Main>d__0.MoveNext() in Program.cs:line 31
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at AzureTest.Program.<Main>(String[] args)

Inner Exception 1:
JsonReaderException: Unexpected character encountered while parsing value: <. Path '', line 0, position 0.

To Reproduce

var result = await azure.WebApps.Inner.AnalyzeCustomHostnameAsync(resourceGroup, appName, fqdn);

additionally, the properties on the result class look quite odd and have the wrong property names:

//
// Summary:
//     /// Gets &lt;code&gt;true&lt;/code&gt; if hostname is /// already verified; otherwise,
//     /// &lt;code&gt;false&lt;/code&gt;. ///
[JsonProperty(PropertyName = "properties.isHostnameAlreadyVerified")]
public bool? IsHostnameAlreadyVerified
{
    get;
    private set;
}

Expected behavior I get the results i can see in fiddler in my object without exception.

Setup (please complete the following information):

Information Checklist Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report

praries880 commented 5 years ago

Thank you for opening this issue! We are routing it to the appropriate team for follow up.

praries880 commented 5 years ago

@Suchiman The properties match what is in the rest API specs

As for XML coming back from the service, can you kindly capture the fiddler traces and capture the response from the server and paste it here?

Suchiman commented 5 years ago

Following Request and Response are issued by the SDK. Request:

GET https://management.microsoftazure.de/subscriptions/REDACTED/resourceGroups/REDACTED/providers/Microsoft.Web/sites/REDACTED/analyzeCustomHostname?hostName=sample.de&api-version=2018-02-01 HTTP/1.1
x-ms-client-request-id: REDACTED
accept-language: en-US
Authorization: Bearer REDACTED
User-Agent: FxVersion/4.7.3324.0 OSName/Windows OSVersion/6.2.9200.0 Microsoft.Azure.Management.AppService.Fluent.WebSiteManagementClient/1.20.0.0 MacAddressHash/REDACTED
Host: management.microsoftazure.de

Response:

HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Length: 1286
Content-Type: application/xml; charset=utf-8
Expires: -1
Strict-Transport-Security: max-age=31536000; includeSubDomains
Server: Microsoft-IIS/10.0
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
x-ms-ratelimit-remaining-subscription-reads: 14992
x-ms-request-id: REDACTED
x-ms-correlation-request-id: REDACTED
x-ms-routing-request-id: GERMANYCENTRAL:REDACTED
X-Content-Type-Options: nosniff
Date: Wed, 17 Apr 2019 15:22:44 GMT

<CustomHostnameAnalysisResult xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/windowsazure"><ARecords xmlns:d2p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays"><d2p1:string>217.147.99.181</d2p1:string><d2p1:string>217.115.143.140</d2p1:string></ARecords><CustomDomainVerificationFailureInfo><Code>BadRequest</Code><Message>A CNAME record pointing from sample.de to redacted.azurewebsites.de was not found. Alternative record awverify.sample.de to awverify.redacted.azurewebsites.de was not found either.</Message><ExtendedCode>04006</ExtendedCode><MessageTemplate>A CNAME record pointing from {0} to {1} was not found. Alternative record awverify.{0} to awverify.{1} was not found either.</MessageTemplate><Parameters xmlns:d3p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays"><d3p1:string>sample.de</d3p1:string><d3p1:string>redacted.azurewebsites.de</d3p1:string></Parameters><InnerErrors i:nil="true" /></CustomDomainVerificationFailureInfo><CustomDomainVerificationTest>Failed</CustomDomainVerificationTest><HasConflictAcrossSubscription>false</HasConflictAcrossSubscription><HasConflictOnScaleUnit>false</HasConflictOnScaleUnit><IsHostnameAlreadyVerified>false</IsHostnameAlreadyVerified></CustomHostnameAnalysisResult>

If you modify the Request to include accept: application/json then you get

HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Length: 681
Content-Type: application/json; charset=utf-8
Expires: -1
Strict-Transport-Security: max-age=31536000; includeSubDomains
Server: Microsoft-IIS/10.0
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
x-ms-ratelimit-remaining-subscription-reads: 14991
x-ms-request-id: REDACTED
x-ms-correlation-request-id: REDACTED
x-ms-routing-request-id: GERMANYCENTRAL:REDACTED
X-Content-Type-Options: nosniff
Date: Wed, 17 Apr 2019 15:27:07 GMT

{"isHostnameAlreadyVerified":false,"customDomainVerificationTest":"Failed","customDomainVerificationFailureInfo":{"extendedCode":"04006","messageTemplate":"A CNAME record pointing from {0} to {1} was not found. Alternative record awverify.{0} to awverify.{1} was not found either.","parameters":["sample.de","redacted.azurewebsites.de"],"code":"BadRequest","message":"A CNAME record pointing from sample.de to redacted.azurewebsites.de was not found. Alternative record awverify.sample.de to awverify.redacted.azurewebsites.de was not found either."},"hasConflictOnScaleUnit":false,"hasConflictAcrossSubscription":false,"aRecords":["217.147.99.181","217.115.143.140","80.237.128.10"]}

Given that the generated Code declares [JsonProperty(PropertyName = "properties.isHostnameAlreadyVerified")] the JSON should be "properties.isHostnameAlreadyVerified":false but it's actually "isHostnameAlreadyVerified":false which explains why nothing gets deserialized if i add accept: application/json with a DelegatingHandler to the request.

badamsdev commented 5 years ago

I'm having the same issue with both Microsoft.WindowsAzure.Management.Websites and Microsoft.Azure.Management.Fluent.

Is this not the same issue reported in 2017? AppService AnalyzeCustomHostname method fails