azure-sdk-for-net: [BUG] Error when CORS is set with multiple methods in the storage account

This is a duplicate of https://github.com/Azure/azure-storage-net/issues/916. Decided to open a new issue since that repo was abandoned

Describe the bug

The storage sdk cannot handle a CORS policy with a rule that has multiple methods. To make this work we would need to create one rule for each method that we want CORS to be enabled

Expected behavior SDK should allow a CORS policy with a rule of comma delimited methods. ie. Access-Control-Allow-Methods: POST, GET, OPTIONS

Actual behavior (include Exception or Stack Trace) When setting up a function app with a blob trigger, the function host return the following error

Microsoft.WindowsAzure.Storage.StorageException : Requested value 'DELETE,GET,POST,PUT,MERGE,HEAD,OPTIONS,PATCH' was not found. ---> System.ArgumentException : Requested value 'DELETE,GET,POST,PUT,MERGE,HEAD,OPTIONS,PATCH' was not found.
   at System.Enum.TryParseEnum(Type enumType,String value,Boolean ignoreCase,EnumResult& parseResult)
   at System.Enum.Parse(Type enumType,String value,Boolean ignoreCase)
   at Microsoft.WindowsAzure.Storage.Shared.Protocol.ServiceProperties.<>c.<ReadCorsPropertiesFromXml>b__67_0(XElement rule)
   at System.Linq.Enumerable.SelectEnumerableIterator`2.ToList()
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)

To Reproduce

  1. Create a storage account and set the following CORS policy image
  2. Create a function app with a blob trigger pointing to this storage account
  3. Function will never trigger because of the storage sdk error. Should be able to find function host error under kudu

Environment:

  • Windows Function App
  • Node 10.14.1

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 1
  • Comments: 18 (10 by maintainers)

Most upvoted comments

This problem existed in v11 of the library and was solved with a PR request from me but totally ignored. https://github.com/Azure/azure-storage-net/pull/917

In short the allowedMethod is not an array of items but 1 single string with comma separated list of values. As this new library is mostly generated code I’m hesitating to fix it with a PR. But the culprit is at this line https://github.com/Azure/azure-sdk-for-net/blob/9ee2b1679bfb6b2ce680a67de546886a19ddae82/sdk/storage/Azure.Management.Storage/src/Generated/Models/CorsRule.Serialization.cs#L81

Instead of foreach (var item in property.Value.EnumerateArray()) It should be foreach (var item in property.Value.EnumerateArray().SelectMany(value => value.Split(",")))

Also while you are at it please consider to add the PATCH verb to the list.