public void WhenAppIdParamIsSet_ThenAppIdIsSetFromParams()
        {
            // Arrange
            Guid masterAppId = Guid.NewGuid();

            WebHealthVaultConfiguration webHealthVaultConfiguration = new WebHealthVaultConfiguration {
                MasterApplicationId = masterAppId
            };

            Ioc.Container.Configure(c => c.ExportInstance(webHealthVaultConfiguration).As <WebHealthVaultConfiguration>());

            Uri uri = new Uri("http://www.bing.com", UriKind.Absolute);

            // Create a dictionary - we are not setting app id as part of the parameters
            Dictionary <string, object> parameters = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase)
            {
                { "Appid", "test-id" }
            };
            ShellUrlBuilder urlBuilder = new ShellUrlBuilder(
                shellUri: uri,
                target: "Action",
                applicationPath: "/Test",
                parameters: parameters);

            // Act
            urlBuilder.EnsureAppId();

            // Assert
            Assert.AreEqual("test-id", parameters["appid"]);
        }
Esempio n. 2
0
        private static void RegisterConfiguration(DependencyInjectionContainer container)
        {
            WebHealthVaultConfiguration configuration = WebConfigurationReader.GetConfiguration();

            container.Configure(c => c.ExportInstance(configuration).As <WebHealthVaultConfiguration>());
            container.Configure(c => c.ExportInstance(configuration).As <HealthVaultConfiguration>());
        }
        public async Task WhenTokenAndInstanceId()
        {
            // Arrange
            IServiceLocator serviceLocator = Substitute.For <IServiceLocator>();

            WebHealthVaultConfiguration webHealthVaultConfiguration = Substitute.For <WebHealthVaultConfiguration>();
            ICookieDataManager          cookieDataManager           = Substitute.For <ICookieDataManager>();

            serviceLocator.GetInstance <WebHealthVaultConfiguration>().Returns(webHealthVaultConfiguration);
            serviceLocator.GetInstance <ICookieDataManager>().Returns(cookieDataManager);

            WebHealthVaultConnection webHealthVaultConnection = Substitute.For <WebHealthVaultConnection>(serviceLocator);

            Ioc.Container.Configure(c => c.ExportInstance(webHealthVaultConnection).As <IWebHealthVaultConnection>());

            IPersonClient mockedPersonClient = Substitute.For <IPersonClient>();

            mockedPersonClient.GetPersonInfoAsync().Returns(Task.FromResult(new PersonInfo()));

            Ioc.Container.Configure(c => c.ExportInstance(mockedPersonClient).As <IPersonClient>());

            // Act
            IWebConnectionInfoProvider webConnectionInfoProvider = new WebConnectionInfoProvider(serviceLocator);
            WebConnectionInfo          webConnectionInfo         = await webConnectionInfoProvider.CreateWebConnectionInfoAsync("someToken", "1");

            // Assert
            Assert.AreEqual("someToken", webConnectionInfo.UserAuthToken);
        }
Esempio n. 4
0
        public async Task WhenCreateOfflineConnection_WithOfflinePersonId()
        {
            // Arrange
            WebHealthVaultConfiguration configuration = new WebHealthVaultConfiguration
            {
                DefaultHealthVaultShellUrl = new Uri("http://www.bing.com"),
                DefaultHealthVaultUrl      = new Uri("http://www.bing.com")
            };

            IServiceLocator serviceLocator = Substitute.For <IServiceLocator>();

            serviceLocator.GetInstance <WebHealthVaultConfiguration>().Returns(configuration);

            IOfflineHealthVaultConnection mokcedOfflineHealthVaultConnection = Substitute.For <OfflineHealthVaultConnection>(serviceLocator);

            Ioc.Container.Configure(c => c.ExportInstance(mokcedOfflineHealthVaultConnection).As <IOfflineHealthVaultConnection>());

            WebHealthVaultFactory factory = new WebHealthVaultFactory();
            string offlinePersonId        = Guid.NewGuid().ToString();

            // Act
            IOfflineHealthVaultConnection offlineHealthVaultConnection = await factory.CreateOfflineConnectionInternalAsync(
                offlinePersonId : offlinePersonId);

            // Assert
            Assert.AreEqual(offlinePersonId, offlineHealthVaultConnection.OfflinePersonId.ToString());

            // Assert that default service instance is created and is set to default shell url from web configuration
            Assert.AreEqual(configuration.DefaultHealthVaultShellUrl, ((OfflineHealthVaultConnection)offlineHealthVaultConnection).ServiceInstance.ShellUrl);
        }
Esempio n. 5
0
        /// <summary>
        /// Redirects unauthorized users to sign in
        /// </summary>
        /// <param name="filterContext">The authorization context</param>
        protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
        {
            WebHealthVaultConfiguration webHealthVaultConfiguration = Ioc.Get <WebHealthVaultConfiguration>();

            filterContext.Result = AuthProvider.SignIn(
                filterContext,
                new { ismra = webHealthVaultConfiguration.IsMultiRecordApp });
        }
Esempio n. 6
0
        /// <summary>
        /// Gets the URL of the page corresponding to the action.
        /// </summary>
        ///
        /// <remarks>
        /// This property corresponds to the "HV_Action*" configuration values when reading from web.config.
        /// Returns null in case Action is not specified in web.config.
        /// </remarks>
        public static Uri TryGetActionUrl(this WebHealthVaultConfiguration config, string action)
        {
            Uri actionUri;

            Dictionary <string, Uri> actionPageUrls = config.ActionPageUrls;

            actionPageUrls.TryGetValue(action, out actionUri);

            return(actionUri);
        }
Esempio n. 7
0
        /// <summary>
        /// Gets the URL of the HealthVault Shell authentication page.
        /// </summary>
        ///
        /// <remarks>
        /// When reading from web.config, this property uses the "HV_ShellUrl" configuration value to construct the
        /// redirector URL with a target of "AUTH".
        /// </remarks>
        ///
        public static Uri HealthVaultShellAuthenticationUrl(this WebHealthVaultConfiguration config)
        {
            var redirect = new ShellRedirectParameters(config.DefaultHealthVaultShellUrl.OriginalString)
            {
                TargetLocation = s_authTarget,
                ApplicationId  = config.MasterApplicationId,
            };

            return(redirect.ConstructRedirectUrl());
        }
        private static void MockConfiguration(IServiceLocator serviceLocator)
        {
            WebHealthVaultConfiguration webHealthVaultConfiguration =
                new WebHealthVaultConfiguration
            {
                UseAspSession = false,
                CookieName    = "Test"
            };

            serviceLocator.GetInstance <WebHealthVaultConfiguration>().Returns(webHealthVaultConfiguration);
        }
Esempio n. 9
0
        public async Task WhenUserIdentityHasWebConnectionInfo()
        {
            // Arrange
            var webConnectionInfo = new WebConnectionInfo
            {
                ServiceInstanceId = "1",
                PersonInfo        = new PersonInfo(),
                SessionCredential = new SessionCredential(),
                UserAuthToken     = "some"
            };

            // Mock HealthVaultIdentityProvider
            IHealthVaultIdentityProvider healthVaultIdentityProvider = Substitute.For <IHealthVaultIdentityProvider>();

            healthVaultIdentityProvider.TryGetIdentity().Returns(new HealthVaultIdentity
            {
                WebConnectionInfo = webConnectionInfo
            });
            Ioc.Container.Configure(c => c.ExportInstance(healthVaultIdentityProvider).As <IHealthVaultIdentityProvider>());

            // Mock HealthVaultConnection
            WebHealthVaultConfiguration webHealthVaultConfiguration = new WebHealthVaultConfiguration();

            webHealthVaultConfiguration.DefaultHealthVaultUrl      = new Uri("http://www.bing.com");
            webHealthVaultConfiguration.DefaultHealthVaultShellUrl = new Uri("http://www.bing.com");

            IServiceLocator serviceLocator = Substitute.For <IServiceLocator>();

            serviceLocator.GetInstance <WebHealthVaultConfiguration>().Returns(webHealthVaultConfiguration);
            serviceLocator.GetInstance <IHealthWebRequestClient>().Returns(Substitute.For <IHealthWebRequestClient>());
            serviceLocator
            .GetInstance <IHealthServiceResponseParser>()
            .Returns(Substitute.For <IHealthServiceResponseParser>());

            WebHealthVaultConnection webHealthVaultConnection = Substitute.For <WebHealthVaultConnection>(serviceLocator);

            Ioc.Container.Configure(c => c.ExportInstance(webHealthVaultConnection).As <IWebHealthVaultConnection>());

            // Mock ServiceInstanceProvider
            IServiceInstanceProvider serviceInstanceProvider = Substitute.For <IServiceInstanceProvider>();

            serviceInstanceProvider
            .GetHealthServiceInstanceAsync(Arg.Any <string>())
            .Returns(Task.FromResult(new HealthServiceInstance()));
            Ioc.Container.Configure(c => c.ExportInstance(serviceInstanceProvider).As <IServiceInstanceProvider>());

            WebHealthVaultFactory factory = new WebHealthVaultFactory();

            // Act
            IWebHealthVaultConnection resultWebHealthVaultConnection = await factory.CreateWebConnectionInternalAsync();

            // Assert
            Assert.AreEqual(webConnectionInfo.UserAuthToken, resultWebHealthVaultConnection.UserAuthToken);
        }
        public WebSessionCredentialClient(
            IServiceLocator serviceLocator,
            IConnectionInternal connection,
            ICertificateInfoProvider certificateInfoProvider)
        {
            _serviceLocator         = serviceLocator;
            Connection              = connection;
            CertificateInfoProvider = certificateInfoProvider;

            _webHealthVaultConfiguration = serviceLocator.GetInstance <WebHealthVaultConfiguration>();
        }
        protected WebHealthVaultConnectionBase(
            IServiceLocator serviceLocator)
            : base(serviceLocator)
        {
            webHealthVaultConfiguration = ServiceLocator.GetInstance <WebHealthVaultConfiguration>();

            ServiceInstance = new HealthServiceInstance
            {
                HealthServiceUrl = UrlUtilities.GetFullPlatformUrl(webHealthVaultConfiguration.DefaultHealthVaultUrl),
                ShellUrl         = webHealthVaultConfiguration.DefaultHealthVaultShellUrl
            };
        }
Esempio n. 12
0
        public WebConnectionInfoProvider(IServiceLocator serviceLocator)
        {
            _serviceLocator = serviceLocator;

            _webHealthVaultConfiguration = serviceLocator.GetInstance <WebHealthVaultConfiguration>();
            _cookieDataManager           = serviceLocator.GetInstance <ICookieDataManager>();

            _useSession = _webHealthVaultConfiguration.UseAspSession;
            _cookieName = _webHealthVaultConfiguration.CookieName;

            _serializerSettings = new JsonSerializerSettings();
            _serializerSettings.Converters.Add(new WebConnectionInfoConverter());
        }
Esempio n. 13
0
        public ShellUrlBuilder(
            Uri shellUri,
            string target,
            string applicationPath,
            IDictionary <string, object> parameters)
        {
            _shellUri        = shellUri ?? throw new ArgumentNullException(nameof(shellUri));
            _target          = target;
            _applicationPath = applicationPath;
            _parameters      = parameters;

            _webHealthVaultConfiguration = Ioc.Get <WebHealthVaultConfiguration>();
        }
        internal async Task ResetConnectionLeaseTimeOutAsync(WebConnectionInfo webConnectionInfo)
        {
            IServiceInstanceProvider serviceInstanceProvider = Ioc.Get <IServiceInstanceProvider>();
            HealthServiceInstance    serviceInstance         = await serviceInstanceProvider.GetHealthServiceInstanceAsync(webConnectionInfo.ServiceInstanceId);

            WebHealthVaultConfiguration webHealthVaultConfiguration = Ioc.Get <WebHealthVaultConfiguration>();
            var serviceInstanceHealthServiceUrl = serviceInstance.HealthServiceUrl;

            // Set socket to be refreshed in case the end point has been changed based on the healthvault service instance
            if (!webHealthVaultConfiguration.DefaultHealthVaultUrl.Equals(serviceInstanceHealthServiceUrl))
            {
                SetConnectionLeaseTimeOut(serviceInstanceHealthServiceUrl);
            }
        }
        public CertificateInfoProvider(WebHealthVaultConfiguration configuration)
        {
            _configuration = configuration;
            _applicationId = configuration.MasterApplicationId;

            _storeLocation = configuration.CertStore;
            _certSubject   = "CN=" + GetApplicationCertificateSubject();

            _x509Certificate2 = GetApplicationCertificate();

            Thumbprint = _x509Certificate2.Thumbprint;

            PrivateKey = (RSACryptoServiceProvider)_x509Certificate2.PrivateKey;
        }
Esempio n. 16
0
        public void WhenSpecificActionRequested_ThenActionUrlSetInConfigurationIsReturned()
        {
            // Arrange
            IServiceLocator serviceLocator = Substitute.For <IServiceLocator>();

            WebHealthVaultConfiguration webHealthVaultConfiguration = new WebHealthVaultConfiguration
            {
                ActionPageUrls = new Dictionary <string, Uri> {
                    { "Test", new Uri("/Test", UriKind.Relative) }
                }
            };

            serviceLocator.GetInstance <WebHealthVaultConfiguration>().Returns(webHealthVaultConfiguration);

            ActionRedirectHelper actionRedirectHelper = new ActionRedirectHelper(serviceLocator);

            // Act
            string targetLocation = actionRedirectHelper.TryGetTargetLocation("Test", null);

            // Assert
            Assert.AreEqual("/Test", targetLocation);
        }
Esempio n. 17
0
        public async Task WhenCreateOfflineConnection_WithOfflinePersonIdAndInstanceId()
        {
            // Arrange
            WebHealthVaultConfiguration configuration = new WebHealthVaultConfiguration
            {
                DefaultHealthVaultShellUrl = new Uri("http://www.bing.com"),
                DefaultHealthVaultUrl      = new Uri("http://www.bing.com")
            };

            IServiceLocator serviceLocator = Substitute.For <IServiceLocator>();

            serviceLocator.GetInstance <WebHealthVaultConfiguration>().Returns(configuration);

            IOfflineHealthVaultConnection mokcedOfflineHealthVaultConnection = Substitute.For <OfflineHealthVaultConnection>(serviceLocator);

            Ioc.Container.Configure(c => c.ExportInstance(mokcedOfflineHealthVaultConnection).As <IOfflineHealthVaultConnection>());

            WebHealthVaultFactory factory = new WebHealthVaultFactory();
            string offlinePersonId        = Guid.NewGuid().ToString();

            IServiceInstanceProvider serviceInstanceProvider = Substitute.For <IServiceInstanceProvider>();

            serviceInstanceProvider.GetHealthServiceInstanceAsync(Arg.Any <string>())
            .Returns(new HealthServiceInstance {
                Name = "Test"
            });
            Ioc.Container.Configure(c => c.ExportInstance(serviceInstanceProvider).As <IServiceInstanceProvider>());

            string instanceId = Guid.NewGuid().ToString();

            // Act
            IOfflineHealthVaultConnection offlineHealthVaultConnection = await factory.CreateOfflineConnectionInternalAsync(
                offlinePersonId : offlinePersonId,
                instanceId : instanceId);

            // Assert
            Assert.AreEqual(offlinePersonId, offlineHealthVaultConnection.OfflinePersonId.ToString());
            Assert.AreEqual("Test", ((OfflineHealthVaultConnection)offlineHealthVaultConnection).ServiceInstance.Name);
        }
        public void WhenRedirectOverrideNotSetInConfiguration_ThenParamaeterOverrideIsNotSet()
        {
            // Arrange
            WebHealthVaultConfiguration webHealthVaultConfiguration = new WebHealthVaultConfiguration();

            Ioc.Container.Configure(c => c.ExportInstance(webHealthVaultConfiguration).As <WebHealthVaultConfiguration>());

            Uri uri = new Uri("http://www.bing.com/redirect.aspx?actionqs=test", UriKind.Absolute);

            // Create a dictionary - we are not setting app id as part of the parameters
            Dictionary <string, object> parameters = new Dictionary <string, object>();
            ShellUrlBuilder             urlBuilder = new ShellUrlBuilder(
                shellUri: uri,
                target: "Action",
                applicationPath: "/Test",
                parameters: parameters);

            // Act
            urlBuilder.EnsureRedirect();

            // Assert
            Assert.IsFalse(parameters.ContainsKey("redirect"));
        }
        public void WhenActionQsAreNotInParams_ThenActionsQsPopulatedFromPathAndQuery()
        {
            // Arrange
            WebHealthVaultConfiguration webHealthVaultConfiguration = new WebHealthVaultConfiguration();

            Ioc.Container.Configure(c => c.ExportInstance(webHealthVaultConfiguration).As <WebHealthVaultConfiguration>());

            Uri uri = new Uri("http://www.bing.com/redirect.aspx?actionqs=test", UriKind.Absolute);

            // Create a dictionary - we are not setting app id as part of the parameters
            Dictionary <string, object> parameters = new Dictionary <string, object>();
            ShellUrlBuilder             urlBuilder = new ShellUrlBuilder(
                shellUri: uri,
                target: "Action",
                applicationPath: "/Test",
                parameters: parameters);

            // Act
            urlBuilder.EnsureAppQs();

            // Assert
            Assert.AreEqual("/redirect.aspx?actionqs=test", parameters["actionqs"]);
        }
Esempio n. 20
0
        /// <summary>
        /// Handles exceptions from HealthVault
        /// </summary>
        /// <param name="filterContext">The exception context</param>
        /// <remarks>
        /// If a user is already signed in, but their session expires, this application may not
        /// realize this until the HealthVault service throws an exception. This handles those cases
        /// by redirecting the user to HealthVault Shell to re-sign in.
        /// </remarks>
        public void OnException(ExceptionContext filterContext)
        {
            if (filterContext == null)
            {
                throw new ArgumentNullException(nameof(filterContext));
            }

            if (filterContext.ExceptionHandled)
            {
                return;
            }

            if (filterContext.Exception is HealthServiceCredentialTokenExpiredException ||
                filterContext.Exception is HealthServiceInvalidPersonException)
            {
                WebHealthVaultConfiguration webHealthVaultConfiguration = Ioc.Get <WebHealthVaultConfiguration>();

                filterContext.Result = AuthProvider.SignIn(
                    filterContext,
                    new { ismra = webHealthVaultConfiguration.IsMultiRecordApp });
                filterContext.ExceptionHandled = true;
            }
        }
Esempio n. 21
0
 /// <summary>
 /// Gets the URL to/from which BLOBs get streamed, for
 /// the configured default instance of the HealthVault web-service.
 /// </summary>
 ///
 /// <remarks>
 ///  When reading from web.config, this property corresponds to the "HealthVaultUrl" configuration
 /// value with the path modified to the appropriate handler.
 /// </remarks>
 public static Uri BlobStreamUrl(this WebHealthVaultConfiguration config) => config.DefaultHealthVaultUrl?.ReplacePath(Urls.BlobStreamUrlSuffix);
Esempio n. 22
0
 /// <summary>
 /// Gets the HealthVault client service URL for
 /// the configured default instance of the HealthVault web-service,
 /// from the application or web configuration file.
 /// </summary>
 ///
 /// <remarks>
 ///  When reading from web.config, this property corresponds to the "HV_HealthVaultUrl" configuration
 /// value with the path modified to the appropriate handler.
 /// </remarks>
 public static Uri HealthClientServiceUrl(this WebHealthVaultConfiguration config) => config.DefaultHealthVaultUrl?.Append(Urls.HealthClientServiceSuffix);
Esempio n. 23
0
 /// <summary>
 /// Gets the HealthVault type schema root URL for
 /// the configured default instance of the HealthVault web-service.
 /// </summary>
 ///
 /// <remarks>
 /// This property corresponds to the "HV_HealthServiceUrl" configuration value when reading from web.config.
 /// </remarks>
 ///
 public static Uri HealthVaultTypeSchemaUrl(this WebHealthVaultConfiguration config) => new Uri(config.DefaultHealthVaultUrl, Urls.TypeSchemaSuffix);
 public ActionRedirectHelper(IServiceLocator serviceLocator)
 {
     _webHealthVaultConfiguration = serviceLocator.GetInstance <WebHealthVaultConfiguration>();
 }
Esempio n. 25
0
 /// <summary>
 /// Shell redirector url, derived from web config.
 /// </summary>
 ///
 public static Uri ShellRedirectorUrl(this WebHealthVaultConfiguration config) => config.DefaultHealthVaultShellUrl?.Append(ConfigDefaults.ShellRedirectorLocation);