Пример #1
0
        public void ShouldSkipAuthOnWrongAuthScheme()
        {
            var builder = new AppBuilderFactory().Create();

            var         context = new OwinContext();
            OwinRequest request = (OwinRequest)context.Request;

            request.Set <Action <Action <object>, object> >("server.OnSendingHeaders", RegisterForOnSendingHeaders);
            request.Method = "get";
            request.SetUri(new Uri("http://example.com:8080/resource/4?filter=a"));
            request.SetHeader("Authorization", new string[] { "Basic " });

            var response = context.Response;

            var middleware = new HawkAuthenticationMiddleware(
                new AppFuncTransition((env) =>
            {
                response.StatusCode = 200;
                return(Task.FromResult <object>(null));
            }),
                builder,
                new HawkAuthenticationOptions
            {
                Credentials = GetCredential
            }
                );

            middleware.Invoke(context);

            Assert.IsNotNull(response);
            Assert.AreEqual(200, response.StatusCode);
        }
        public static IDictionary <string, object> WithHeader(this IDictionary <string, object> env, string key, string value)
        {
            var request = new OwinRequest(env);

            request.SetHeader(key, value);

            return(request.Dictionary);
        }
        public static IDictionary <string, object> WithBody(this IDictionary <string, object> env, Stream stream)
        {
            var request = new OwinRequest(env);

            request.Body = stream;
            request.SetHeader("Content-Length", stream.Length.ToString());

            return(request.Dictionary);
        }