public async Task OnAuthorization_WithNamedKeyHeader_Succeeds() { var attribute = new SystemAuthorizationLevelAttribute(TestSystemKeyName1); HttpRequestMessage request = new HttpRequestMessage(); request.Headers.Add(AuthorizationLevelAttribute.FunctionsKeyHeaderName, TestSystemKeyValue1); var actionContext = CreateActionContext(typeof(SystemTestController).GetMethod(nameof(SystemTestController.Get)), HttpConfig); actionContext.ControllerContext.Request = request; await attribute.OnAuthorizationAsync(actionContext, CancellationToken.None); Assert.Null(actionContext.Response); }
public async Task GetAuthorizationLevel_ValidCodeQueryParam_WithNamedKeyRequirement_ReturnsExpectedLevel(string keyName, string keyValue, AuthorizationLevel expectedLevel, string functionName = null) { Uri uri = new Uri(string.Format("http://functions/api/foo?code={0}", keyValue)); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, uri); Func <IDictionary <string, string>, string, bool> evaluator = (secrets, value) => SystemAuthorizationLevelAttribute.EvaluateKeyMatch(secrets, value, keyName); AuthorizationLevel level = await AuthorizationLevelAttribute.GetAuthorizationLevelAsync(request, MockSecretManager.Object, evaluator, functionName : functionName); Assert.Equal(expectedLevel, level); }
public void HasAuthorizationLevelAttribute() { SystemAuthorizationLevelAttribute attribute = typeof(SwaggerController).GetCustomAttribute <SystemAuthorizationLevelAttribute>(); Assert.Equal(AuthorizationLevel.System, attribute.Level); }