コード例 #1
0
 protected void given_context()
 {
     Host        = new InMemoryHost(null);
     HostManager = Host.HostManager;
     HostManager.SetupCommunicationContext(Context = new InMemoryCommunicationContext());
     DependencyManager.SetResolver(Host.Resolver);
 }
コード例 #2
0
 protected void given_context()
 {
     Host        = new InMemoryHost();
     HostManager = Host.HostManager;
     DependencyManager.SetResolver(Host.Resolver);
     RequestScope = Host.Resolver.CreateRequestScope();
     HostManager.SetupCommunicationContext(Context = new InMemoryCommunicationContext());
 }
コード例 #3
0
        protected override void SetUp()
        {
            base.SetUp();
            var stub = new InMemoryCommunicationContext();

            Resolver.AddDependencyInstance(typeof(ICommunicationContext), stub);
            stub.ApplicationBaseUri = new Uri("http://localhost");
        }
        public void execution_is_denied()
        {
            var context = new InMemoryCommunicationContext();

            var authenticationInterceptor = new RequiresAuthenticationInterceptor(context);

            authenticationInterceptor.BeforeExecute(new Mock <IOperation>().Object).ShouldBeFalse();
            context.OperationResult.ShouldBeAssignableTo <OperationResult.Unauthorized>();
        }
コード例 #5
0
        public void error_is_collected_and_500_returned()
        {
            var pipeline = CreatePipeline(typeof(ContributorThatThrows), typeof(FakeOperationResultInvoker));
            var context  = new InMemoryCommunicationContext();

            pipeline.Run(context);
            context.Response.StatusCode.ShouldBe(500);
            context.ServerErrors.ShouldHaveCountOf(1);
        }
コード例 #6
0
        public void the_filter_doesnt_authorize_the_execution()
        {
            var context   = new InMemoryCommunicationContext();
            var principal = new PrincipalAuthorizationInterceptor(context)
            {
                InRoles = new[] { "Administrators" }
            };

            principal.BeforeExecute(new Mock <IOperation>().Object).ShouldBe(true);
        }
コード例 #7
0
        public void the_filter_doesnt_authorize_the_execution()
        {
            var context   = new InMemoryCommunicationContext();
            var principal = new PrincipalAuthorizationAttribute {
                InRoles = new[] { "Administrators" }
            };

            principal.ExecuteBefore(context)
            .ShouldBe(PipelineContinuation.RenderNow);
        }
        public void execution_is_allowed()
        {
            var context = new InMemoryCommunicationContext();

            context.User = new GenericPrincipal(new GenericIdentity("name"), null);

            var authenticationInterceptor = new RequiresAuthenticationInterceptor(context);

            authenticationInterceptor.BeforeExecute(new Mock <IOperation>().Object).ShouldBeTrue();
        }
コード例 #9
0
        // TODO: Need to be moved to the core framework.
        public static void RenderResource(this IXhtmlAnchor anchor, Uri resource)
        {
            var context = new InMemoryCommunicationContext
            {
                Request = new InMemoryRequest
                {
                    HttpMethod = "GET",
                    Uri        = resource,
                    Entity     = new HttpEntity
                    {
                        ContentLength = 0
                    }
                }
            };

            context.Request.Headers["Accept"] = MediaType.XhtmlFragment.ToString();
            var textWriterProvider = anchor.AmbientWriter as ISupportsTextWriter;

            StringBuilder inMemoryRendering = null;

            if (textWriterProvider != null && textWriterProvider.TextWriter != null)
            {
                context.Response = new InMemoryResponse
                {
                    Entity = new TextWriterEnabledEntity(textWriterProvider.TextWriter)
                }
            }
            ;
            else
            {
                inMemoryRendering = new StringBuilder();
                var writer = new StringWriter(inMemoryRendering);
                context.Response = new InMemoryResponse {
                    Entity = new TextWriterEnabledEntity(writer)
                };
            }

            anchor.Resolver.Resolve <IPipeline>().Run(context);

            if (context.Response.Entity.Stream.Length > 0)
            {
                context.Response.Entity.Stream.Position = 0;
                var
                    destinationEncoding =
                    Encoding.GetEncoding(context.Response.Entity.ContentType.CharSet ?? "UTF8");

                var reader = new StreamReader(context.Response.Entity.Stream, destinationEncoding);
                anchor.AmbientWriter.WriteUnencodedString(reader.ReadToEnd());
            }
            else if (inMemoryRendering != null && inMemoryRendering.Length > 0)
            {
                anchor.AmbientWriter.WriteUnencodedString(inMemoryRendering.ToString());
            }
        }
コード例 #10
0
        public void execution_is_denied()
        {
            var          context = new InMemoryCommunicationContext();
            const string REALM   = "Test Realm";
            var          authenticationInterceptor = new RequiresBasicAuthenticationInterceptor(context, REALM);

            authenticationInterceptor.BeforeExecute(new Mock <IOperation>().Object).ShouldBeFalse();
            context.OperationResult.ShouldBeAssignableTo <OperationResult.Unauthorized>();
            var expectedHeader = String.Format("Basic realm=\"{0}\"", REALM);

            context.Response.Headers["WWW-Authenticate"].ShouldBe(expectedHeader);
        }
コード例 #11
0
        public void the_username_is_matched_and_execution_continues()
        {
            Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("johndoe"), new[] { "Administrator" });

            var rastaContext = new InMemoryCommunicationContext();
            var authorizer   = new PrincipalAuthorizationInterceptor(rastaContext)
            {
                Users = new[] { "johndoe" }
            };

            authorizer.BeforeExecute(new Mock <IOperation>().Object).ShouldBe(true);

            rastaContext.OperationResult.ShouldBeNull();
        }
コード例 #12
0
 protected middleware_context()
 {
     Env = new InMemoryCommunicationContext
     {
         PipelineData =
         {
             PipelineStage    = new PipelineStage()
             {
                 CurrentState = PipelineContinuation.Continue
             }
         }
     };
     Next = new NextMiddleware(() => NextCalled = true);
 }
コード例 #13
0
        protected override void SetUp()
        {
            base.SetUp();
            Host     = new InMemoryHost();
            Pipeline = null;
            _actions = new Dictionary <Type, Func <ICommunicationContext, Task <PipelineContinuation> > >();
            var manager = Host.HostManager;

            Resolver.AddDependencyInstance(typeof(IErrorCollector), Errors = new TestErrorCollector());
            Resolver.AddDependency <IPathManager, PathManager>();

            manager.SetupCommunicationContext(Context = new InMemoryCommunicationContext());
            DependencyManager.SetResolver(Resolver);
        }
        public void execution_is_not_allowed()
        {
            var context = new InMemoryCommunicationContext();

            context.User = new GenericPrincipal(new GenericIdentity("name"), new [] { "Administrator" });

            var authenticationInterceptor = new RequiresRoleInterceptor(context)
            {
                Role = "SuperUser"
            };

            authenticationInterceptor.BeforeExecute(new Mock <IOperation>().Object).ShouldBeFalse();
            context.OperationResult.ShouldBeAssignableTo <OperationResult.Unauthorized>();
        }
コード例 #15
0
        public void the_username_is_matched_and_execution_continues()
        {
            Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity("johndoe"), new[] { "Administrator" });

            var rastaContext = new InMemoryCommunicationContext();
            var authorizer   = new PrincipalAuthorizationAttribute()
            {
                Users = new[] { "johndoe" }
            };

            authorizer.ExecuteBefore(rastaContext)
            .ShouldBe(PipelineContinuation.Continue);

            rastaContext.OperationResult.ShouldBeNull();
        }
コード例 #16
0
        public async Task error_is_collected_and_500_returned(Type callGraphGeneratorType)
        {
            var pipeline = CreatePipeline(callGraphGeneratorType, new[]
            {
                typeof(FakeUriMatcher),
                typeof(ContributorThatThrows),
                typeof(FakeOperationResultInvoker)
            }, false);

            var context = new InMemoryCommunicationContext();

            await pipeline.RunAsync(context);

            context.Response.StatusCode.ShouldBe(500);
            context.ServerErrors.Count.ShouldBe(1);
        }
コード例 #17
0
 public void setup()
 {
     Host = new InMemoryHost(startup: new StartupProperties
     {
         OpenRasta =
         {
             Errors                           =
             {
                 HandleAllExceptions          = false,
                 HandleCatastrophicExceptions = false
             }
         }
     });
     HostManager            = Host.HostManager;
     AmbientContext.Current = new AmbientContext();
     RequestScope           = Host.Resolver.CreateRequestScope();
     HostManager.SetupCommunicationContext(Context = new InMemoryCommunicationContext());
 }
コード例 #18
0
 protected pipeline_building_context()
 {
     Context = new InMemoryCommunicationContext();
 }
コード例 #19
0
 public response_retry()
 {
     Env        = new InMemoryCommunicationContext();
     Middleware = new OpenRasta.Pipeline.ResponseRetryMiddleware();
 }
コード例 #20
0
        protected void setup()
        {
            Host = new InMemoryHost(startup: new StartupProperties
            {
                OpenRasta =
                {
                    Errors                           =
                    {
                        HandleAllExceptions          = false,
                        HandleCatastrophicExceptions = false
                    }
                }
            });

            Pipeline = null;
            _actions = new Dictionary <Type, Func <ICommunicationContext, Task <PipelineContinuation> > >();
            var manager = Host.HostManager;

            Resolver.AddDependencyInstance(typeof(IErrorCollector), Errors = new TestErrorCollector());
            Resolver.AddDependency <IPathManager, PathManager>();

            _ambientContext = new ContextScope(new AmbientContext());
            _requestScope   = Resolver.CreateRequestScope();
            manager.SetupCommunicationContext(Context = new WriteTrackingResponseCommunicationContext(InnerContext = new InMemoryCommunicationContext()));
        }