public void UserIdCorrelationMiddleware_Inject_UsesExistingUserIdWhenPresent()
        {
            //Arrange
            var ctx = new OwinContext
            {
                Request =
                {
                    Scheme = LibOwin.Infrastructure.Constants.Https,
                    Path   = new PathString("/"),
                    Method = "GET",
                }
            };

            ctx.Request.Headers.Append(Constants.FabricHeaders.SubjectNameHeader, TestUser);

            //Act
            var pipeline = SubjectCorrelationMiddleware.Inject(_noOp);

            pipeline(ctx.Environment);

            //Assert
            var actualUserId = ctx.Environment[Constants.FabricHeaders.SubjectNameHeader];

            Assert.Equal(TestUser, actualUserId);
        }
        public void UserIdMiddleware_Inject_DoesNotAddUserIdWhenSubIsNotPresent()
        {
            var ctx = new OwinContext
            {
                Request =
                {
                    Scheme = LibOwin.Infrastructure.Constants.Https,
                    Path   = new PathString("/"),
                    Method = "GET",
                    User   = new TestPrincipal()
                }
            };

            var pipeline = SubjectCorrelationMiddleware.Inject(_noOp);

            pipeline(ctx.Environment);

            //Assert
            var actualUserId = ctx.Environment[Constants.FabricHeaders.SubjectNameHeader];

            Assert.Equal(UnknownUser, actualUserId);
        }
        public void UserIdMiddleware_Inject_UsesSubClaimWhenPresent()
        {
            var subClaim = "testuser";
            var ctx      = new OwinContext
            {
                Request =
                {
                    Scheme = LibOwin.Infrastructure.Constants.Https,
                    Path   = new PathString("/"),
                    Method = "GET",
                    User   = new TestPrincipal(new Claim(SubjectCorrelationMiddleware.SubClaim, subClaim))
                }
            };

            var pipeline = SubjectCorrelationMiddleware.Inject(_noOp);

            pipeline(ctx.Environment);

            //Assert
            var actualUserId = ctx.Environment[Constants.FabricHeaders.SubjectNameHeader];

            Assert.Equal(subClaim, actualUserId);
        }
        public void UserIdMiddleware_Inject_AddsUserIdFromContext()
        {
            //Arrange
            var ctx = new OwinContext
            {
                Request =
                {
                    Scheme = LibOwin.Infrastructure.Constants.Https,
                    Path   = new PathString("/"),
                    Method = "GET",
                    User   = new TestPrincipal(new Claim(SubjectCorrelationMiddleware.SubClaim, TestUser))
                }
            };

            //Act
            var pipeline = SubjectCorrelationMiddleware.Inject(_noOp);

            pipeline(ctx.Environment);

            //Assert
            var actualUserId = ctx.Environment[Constants.FabricHeaders.SubjectNameHeader];

            Assert.Equal(TestUser, actualUserId);
        }