Ejemplo n.º 1
0
        protected override Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            var prefix = pathLocator.GetPath();

            CopyHeaders(prefix, httpContextAccessor.HttpContext.Request.Headers, request?.Headers);
            CopyHeaders(prefix, httpContextAccessor.HttpContext.Items, request?.Headers);

            return(base.SendAsync(request, cancellationToken));
        }
Ejemplo n.º 2
0
        public void CanCopyCookieValuesFromChildAppToShellWhenCookieHasSingleValue()
        {
            using (var childHttpResponseMessage = new HttpResponseMessage())
            {
                //Arrange
                var path = "path1";
                A.CallTo(() => pathLocator.GetPath()).Returns(path);
                childHttpResponseMessage.Headers.Add(HeaderNames.SetCookie, "v1=v1value");
                childHttpResponseMessage.Headers.Add(HeaderNames.Referer, "Referer1=Referer1Value");

                //Act
                cookieHttpResponseMessageHandler.Process(childHttpResponseMessage);

                //Assert
                var shellResponseHeaders = httpContextAccessor.HttpContext.Response.Headers;
                var setCookieHeader      = shellResponseHeaders[HeaderNames.SetCookie];
                Assert.Single(setCookieHeader);
                Assert.StartsWith(path, setCookieHeader[0], StringComparison.OrdinalIgnoreCase);
            }
        }
Ejemplo n.º 3
0
        protected override Task <HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            var prefix = pathLocator.GetPath();

            if (string.IsNullOrWhiteSpace(prefix))
            {
                prefix = "pages";
            }

            CopyHeaders(prefix, httpContextAccessor.HttpContext.Request.Headers, request?.Headers);
            CopyHeaders(prefix, httpContextAccessor.HttpContext.Items, request?.Headers);
            AddTokenHeaderFromCookie(httpContextAccessor.HttpContext, request);

            return(base.SendAsync(request, cancellationToken));
        }
Ejemplo n.º 4
0
        public async Task WhenShellAuthenticatedPassOnToken()
        {
            //Arrange
            var path1      = "path1";
            var path2      = "path2";
            var requestUrl = $"https://someurl.com/{path1}";

            //Create fakes
            pathLocator         = A.Fake <IPathLocator>();
            httpContextAccessor = A.Fake <IHttpContextAccessor>();
            compositeDataProtectionDataProvider = A.Fake <ICompositeDataProtectionDataProvider>();

            //Fake calls
            A.CallTo(() => pathLocator.GetPath()).Returns(path1);
            A.CallTo(() => compositeDataProtectionDataProvider.Unprotect(A <string> .Ignored)).ReturnsLazily(x => x.Arguments.First().ToString());
            A.CallTo(() => compositeDataProtectionDataProvider.Protect(A <string> .Ignored)).ReturnsLazily(x => x.Arguments.First().ToString());

            //Set some headers on the incoming request
            httpContextAccessor.HttpContext = new DefaultHttpContext {
                User = new ClaimsPrincipal(new ClaimsIdentity(new List <Claim> {
                    new Claim("bearer", "test")
                }, "mock"))
            };
            httpContextAccessor.HttpContext.Request.Headers.Add(HeaderNames.Cookie, $"{Constants.DfcSession}=sessionId1;{path1}v1=value1;{path1}v2=value2;{path2}v3=value3;{path2}v4=value4");
            httpContextAccessor.HttpContext.Session = new MockHttpSession();

            //Create a get request that is used to send data to the child app
            var httpRequestChildMessage = new HttpRequestMessage(HttpMethod.Get, requestUrl);

            //Create handlers and set the inner handler
            handler = new CookieDelegatingHandler(httpContextAccessor, pathLocator, compositeDataProtectionDataProvider)
            {
                InnerHandler = new StatusOkDelegatingHandler(),
            };

            //Act
            var invoker = new HttpMessageInvoker(handler);
            await invoker.SendAsync(httpRequestChildMessage, CancellationToken.None).ConfigureAwait(false);

            //Check that the values that are sent back are correct
            var headerValue = httpRequestChildMessage.Headers.Authorization;

            Assert.Equal("test", headerValue.Parameter);
            httpRequestChildMessage.Dispose();
            invoker.Dispose();
        }
Ejemplo n.º 5
0
        public async Task CanCopyHeadersFromShellToChildApp()
        {
            //Arrange
            var path1      = "path1";
            var path2      = "path2";
            var requestUrl = $"https://someurl.com/{path1}";

            //Create fakes
            pathLocator         = A.Fake <IPathLocator>();
            httpContextAccessor = A.Fake <IHttpContextAccessor>();
            compositeDataProtectionDataProvider = A.Fake <ICompositeDataProtectionDataProvider>();

            //Fake calls
            A.CallTo(() => pathLocator.GetPath()).Returns(path1);
            A.CallTo(() => compositeDataProtectionDataProvider.Unprotect(A <string> .Ignored)).ReturnsLazily(x => x.Arguments.First().ToString());
            A.CallTo(() => compositeDataProtectionDataProvider.Protect(A <string> .Ignored)).ReturnsLazily(x => x.Arguments.First().ToString());

            //Set some headers on the incoming request
            httpContextAccessor.HttpContext = new DefaultHttpContext();
            httpContextAccessor.HttpContext.Request.Headers.Add(HeaderNames.Cookie, $"{path1}v1=value1;{path1}v2=value2;{path2}v3=value3;{path2}v4=value4");

            //Create a get request that is used to send data to the child app
            var httpRequestChildMessage = new HttpRequestMessage(HttpMethod.Get, requestUrl);

            //Create handlers and set the inner handler
            handler = new CookieDelegatingHandler(httpContextAccessor, pathLocator, compositeDataProtectionDataProvider)
            {
                InnerHandler = new StatusOkDelegatingHandler(),
            };

            //Act
            var invoker = new HttpMessageInvoker(handler);
            await invoker.SendAsync(httpRequestChildMessage, CancellationToken.None).ConfigureAwait(false);

            //Check that the child app has the correct number of headers based on the incoming request
            Assert.Single(httpRequestChildMessage.Headers);

            //Check that the values that are sent back are correct
            var headerValue = httpRequestChildMessage.Headers.First().Value.ToList();

            Assert.Equal("v1=value1", headerValue.First());
            Assert.Equal("v2=value2", headerValue.Last());
            httpRequestChildMessage.Dispose();
            invoker.Dispose();
        }
Ejemplo n.º 6
0
        public void Process(HttpResponseMessage httpResponseMessage)
        {
            var prefix = pathLocator.GetPath();

            foreach (var header in httpResponseMessage?.Headers.Where(x => x.Key == HeaderNames.SetCookie))
            {
                foreach (var headerValue in header.Value)
                {
                    var cookieSettings      = setCookieParser.Parse(headerValue);
                    var cookieKeyWithPrefix = string.Concat(prefix, cookieSettings.Key);
                    httpContextAccessor.HttpContext.Response.Cookies.Append(cookieKeyWithPrefix, cookieSettings.Value, cookieSettings.CookieOptions);
                    if (!httpContextAccessor.HttpContext.Items.ContainsKey(cookieKeyWithPrefix))
                    {
                        httpContextAccessor.HttpContext.Items[cookieKeyWithPrefix] = cookieSettings.Value;
                    }
                }
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:ReactiveUIAroundMe.Portable.ViewModels.SuperAdminPageViewModel"/> class.
        /// </summary>
        /// <param name="storage">Storage.</param>
        /// <param name="scheduler">Scheduler.</param>
        /// <param name="signalRClient">Signal RC lient.</param>
        /// <param name="log">Log.</param>
        /// <param name="applicationStateHandler">Application state handler.</param>
        /// <param name="webServiceController">Web service controller.</param>
        public SuperAdminPageViewModel(ISQLiteStorage storage, IScheduler scheduler, ILogger log,
                                       ApplicationStateHandler applicationStateHandler, WebServiceController webServiceController, GoogleMapsWebServiceController googleMapsWebServiceController,
                                       IPathLocator pathLocator, IScreen hostScreen, ILocationManager locationManager)
            : base(storage, scheduler, log, applicationStateHandler, webServiceController, googleMapsWebServiceController, pathLocator,
                   hostScreen, locationManager)
        {
            _pathLocator = pathLocator;

            Title = "Super Admin";

            selection = (obj) =>
            {
                var parameters = (obj as TetrixViewModelBase)?.SelectParameters;

                object selectKey;
                parameters.TryGetValue("ViewModel", out selectKey);
                if (selectKey != null)
                {
                    HostScreen.Router.Navigate.Execute(new SuperAdminPageViewModel(Storage, Scheduler,
                                                                                   Log, ApplicationStateHandler, WebServiceController,
                                                                                   GoogleMapsWebServiceController, PathLocator, HostScreen, LocationManager));

                    var viewModelType = Type.GetType(string.Format("ReactiveUIAroundMe.Portable.ViewModels.{0}", selectKey));
                    var instance      = (ViewModelBase)Activator.CreateInstance(viewModelType,
                                                                                new object[] { Storage, Scheduler,
                                                                                               Log, ApplicationStateHandler, WebServiceController,
                                                                                               PathLocator, HostScreen });

                    HostScreen.Router.Navigate.Execute(instance);
                }
                ;

                return(Unit.Default);
            };

            InitSelectCommand((obj) => selection(obj));

            var tiles = _tileTiles.Select((title, index) =>
            {
                var tileModel = new TileViewModel(Storage, Scheduler, Log,
                                                  ApplicationStateHandler, WebServiceController, GoogleMapsWebServiceController, PathLocator, HostScreen, LocationManager);
                tileModel.Title       = _tileTiles[index];
                tileModel.BannerImage = _pathLocator.GetPath(_bannerImages[index], "jpg");
                tileModel.TileImage   = _pathLocator.GetPath("profile_image", "jpeg");

                // hack: for mac until wet selectable cells working for collection views
                tileModel.InitSelectionCommand((obj) => selection(obj));
                tileModel.SelectParameters = new Dictionary <string, object>()
                {
                    { "ViewModel", _tileNavigationViewModels[index] },
                };

                tileModel.UseXSpacing = true;
                tileModel.UseYSpacing = true;
                tileModel.Layout      = LayoutType.Fifth;
                tileModel.Position    = index;

                return(tileModel);
            });

            Cells.AddRange(tiles);
        }
        public void Process(HttpResponseMessage httpResponseMessage)
        {
            var headers = new Dictionary <string, int>();

            foreach (var header in httpResponseMessage?.Headers.Where(x => x.Key == HeaderNames.SetCookie))
            {
                foreach (var headerValue in header.Value)
                {
                    var cookieSettings      = setCookieParser.Parse(headerValue);
                    var cookieKey           = cookieSettings.Key;
                    var prefix              = headerRenamerService.Rename(cookieKey) ? pathLocator.GetPath() : string.Empty;
                    var cookieKeyWithPrefix = string.Concat(prefix, cookieKey);
                    var allowedHeaderCount  = headerCountService.Count(cookieKey);
                    var currentHeaderCount  = GetHeaderCount(headers, cookieKey);
                    var cookieValue         = cookieSettings.Value;
                    if (cookieSettings.Key == Constants.DfcSession)
                    {
                        cookieValue = compositeDataProtectionDataProvider.Protect(cookieValue);
                    }

                    if (currentHeaderCount < allowedHeaderCount)
                    {
                        RegisterHeader(headers, cookieKey);
                        httpContextAccessor.HttpContext.Response.Cookies.Append(cookieKeyWithPrefix, cookieValue, cookieSettings.CookieOptions);
                        AddToHttpContext(cookieKeyWithPrefix, cookieValue);
                    }
                }
            }
        }