Refactor clearing authLevel for httpTrigger webhooks
This commit is contained in:
Родитель
b15561a8dd
Коммит
e56e4d4d7f
|
@ -158,6 +158,13 @@ namespace MakeFunctionJson
|
|||
|
||||
// Serialize the direction
|
||||
obj["direction"] = direction.ToString();
|
||||
|
||||
// Clear AuthLevel from httpTrigger that has a webHook property
|
||||
if (obj["type"]?.ToString() == "httpTrigger" && obj["webHookType"]?.ToString() != null)
|
||||
{
|
||||
obj.Remove("authLevel");
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
|
|
@ -60,14 +60,6 @@ namespace MakeFunctionJson
|
|||
returnOutputBindings = new[] { JObject.FromObject(new { name = "$return", type = "http", direction = "out" }) };
|
||||
}
|
||||
|
||||
// Clear AuthLevel from httpTrigger that has a webHook property
|
||||
var webHook = bindings.FirstOrDefault(b => b["type"]?.ToString() == "httpTrigger" && b["webHookType"]?.ToString() != null);
|
||||
|
||||
if (webHook != null)
|
||||
{
|
||||
webHook.Remove("authLevel");
|
||||
}
|
||||
|
||||
return new FunctionJsonSchema
|
||||
{
|
||||
// For every SDK parameter, convert it to a FunctionJson bindings.
|
||||
|
|
|
@ -23,20 +23,17 @@ namespace Microsoft.NET.Sdk.Functions.Test
|
|||
jObject["authLevel"].Should().Be("function");
|
||||
}
|
||||
|
||||
public class FunctionClass
|
||||
[Fact]
|
||||
public void HttpTriggerAttributeWithWebHookTypeShouldntHaveAnAuthLevel()
|
||||
{
|
||||
public static void Run([HttpTrigger(WebHookType = "something")] string message) { }
|
||||
}
|
||||
var attribute = new HttpTriggerAttribute()
|
||||
{
|
||||
WebHookType = "something"
|
||||
};
|
||||
|
||||
[Theory]
|
||||
[InlineData(typeof(FunctionClass), "Run")]
|
||||
public void HttpTriggerAttributeWithWebHookTypeShouldntHaveAnAuthLevel(Type type, string methodName)
|
||||
{
|
||||
var method = type.GetMethod(methodName);
|
||||
var funcJson = method.ToFunctionJson(string.Empty);
|
||||
var jObject = attribute.ToJObject();
|
||||
|
||||
funcJson.Bindings.Should().HaveCount(2);
|
||||
funcJson.Bindings.First()["authLevel"].Should().BeNull();
|
||||
jObject["authLevel"].Should().BeNull();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче