public void UseMobileAppAuthentication_ConfiguresServiceAuthentication_WhenAuthEnabled()
        {
            // Arrange
            MobileAppConfiguration configOptions = new MobileAppConfiguration();
            this.config.SetMobileAppConfiguration(configOptions);
            MobileAppAuthenticationOptions options = null;
            this.appBuilderMock.Setup(a => a.Properties)
                .Returns(new Dictionary<string, object>
                { 
                    { "integratedpipeline.StageMarker", (Action<IAppBuilder, string>)((app, stageName) => { }) }
                });
            this.appBuilderMock.Setup(p => p.Use(It.IsAny<object>(), It.IsAny<object[]>()))
                .Callback<object, object[]>((mockObject, mockArgs) =>
                {
                    options = (MobileAppAuthenticationOptions)mockArgs[1];
                })
                .Returns(this.appBuilder)
                .Verifiable();

            // Act
            this.appBuilder.UseAppServiceAuthentication(this.config, AppServiceAuthenticationMode.LocalOnly);

            // Assert
            // We expect three pieces of middleware to be added
            this.appBuilderMock.Verify(p => p.Use(It.IsAny<object>(), It.IsAny<object[]>()), Times.Once);
            Assert.Equal("MobileApp", options.AuthenticationType);
        }
Beispiel #2
0
        /// <summary>
        /// </summary>
        /// <param name="config"></param>
        /// <returns></returns>
        public static MobileAppConfiguration AddTables(this MobileAppConfiguration config)
        {
            MobileAppTableConfiguration tableConfig = new MobileAppTableConfiguration().MapTableControllers();

            AddTables(config, tableConfig);
            return(config);
        }
        public void UseMobileAppAuthentication_ConfiguresServiceAuthentication_WhenAuthEnabled()
        {
            // Arrange
            MobileAppConfiguration configOptions = new MobileAppConfiguration();

            this.config.SetMobileAppConfiguration(configOptions);
            MobileAppAuthenticationOptions options = null;

            this.appBuilderMock.Setup(a => a.Properties)
            .Returns(new Dictionary <string, object>
            {
                { "integratedpipeline.StageMarker", (Action <IAppBuilder, string>)((app, stageName) => { }) }
            });
            this.appBuilderMock.Setup(p => p.Use(It.IsAny <object>(), It.IsAny <object[]>()))
            .Callback <object, object[]>((mockObject, mockArgs) =>
            {
                options = (MobileAppAuthenticationOptions)mockArgs[1];
            })
            .Returns(this.appBuilder)
            .Verifiable();

            // Act
            this.appBuilder.UseMobileAppAuthentication(this.config);

            // Assert
            // We expect three pieces of middleware to be added
            this.appBuilderMock.Verify(p => p.Use(It.IsAny <object>(), It.IsAny <object[]>()), Times.Once);
            Assert.Equal("Service", options.Realm);
            Assert.Equal("MobileApp", options.AuthenticationType);
        }
        public void ApplyTo_Throws_IfCalledTwiceOnSameConfig()
        {
            var mobileAppConfig = new MobileAppConfiguration();
            var config = new HttpConfiguration();
            mobileAppConfig.ApplyTo(config);

            Assert.Throws<InvalidOperationException>(() => mobileAppConfig.ApplyTo(config));
        }
        /// <summary>
        /// Registers a <see cref="Microsoft.Azure.Mobile.Server.Config.MobileAppConfiguration"/> with the current <see cref="System.Web.Http.HttpConfiguration" />.
        /// </summary>
        /// <param name="config">The current <see cref="System.Web.Http.HttpConfiguration"/>.</param>
        /// <param name="options">The instance to register.</param>
        public static void SetMobileAppConfiguration(this HttpConfiguration config, MobileAppConfiguration options)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            config.Properties[MobileAppOptionsKey] = options;
        }
Beispiel #6
0
        public void ApplyTo_Throws_IfCalledTwiceOnSameConfig()
        {
            var mobileAppConfig = new MobileAppConfiguration();
            var config          = new HttpConfiguration();

            mobileAppConfig.ApplyTo(config);

            Assert.Throws <InvalidOperationException>(() => mobileAppConfig.ApplyTo(config));
        }
Beispiel #7
0
        public static MobileAppConfiguration AddTables(this MobileAppConfiguration config, MobileAppTableConfiguration tableConfig)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            config.RegisterConfigProvider(new TableMobileAppConfigProvider(tableConfig));
            return(config);
        }
        public static MobileAppConfiguration AddPushNotifications(this MobileAppConfiguration options)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            options.RegisterConfigProvider(new NotificationsExtensionConfigProvider());
            return(options);
        }
Beispiel #9
0
        public static MobileAppConfiguration MapLegacyCrossDomainController(this MobileAppConfiguration options, IEnumerable <string> origins)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            options.RegisterConfigProvider(new CrossDomainExtensionConfigProvider(origins));
            return(options);
        }
Beispiel #10
0
        public static MobileAppConfiguration AddMobileAppHomeController(this MobileAppConfiguration options)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            options.RegisterConfigProvider(new HomeExtensionConfigProvider());
            return(options);
        }
        public void SetMobileAppConfiguration_Roundtrips()
        {
            // Arrange
            HttpConfiguration config = new HttpConfiguration();
            MobileAppConfiguration options = new MobileAppConfiguration();

            // Act
            config.SetMobileAppConfiguration(options);
            MobileAppConfiguration actual = config.GetMobileAppConfiguration();

            // Assert
            Assert.Same(options, actual);
        }
Beispiel #12
0
        /// <summary>
        /// </summary>
        /// <param name="config"></param>
        /// <returns></returns>
        public static MobileAppConfiguration AddTablesWithEntityFramework(this MobileAppConfiguration config)
        {
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }

            config.AddTables(
                new MobileAppTableConfiguration()
                .MapTableControllers()
                .AddEntityFramework());

            return(config);
        }
Beispiel #13
0
        public static MobileAppConfiguration UseDefaultConfiguration(this MobileAppConfiguration options)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            return(options.AddTables(
                       new MobileAppTableConfiguration()
                       .MapTableControllers()
                       .AddEntityFramework())
                   .MapApiControllers()
                   .AddMobileAppHomeController());
        }
Beispiel #14
0
        public static MobileAppConfiguration WithTableControllerConfigProvider(this MobileAppConfiguration options, ITableControllerConfigProvider tableConfigProvider)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            if (tableConfigProvider == null)
            {
                throw new ArgumentNullException("tableConfigProvider");
            }

            options.RegisterConfigProvider(new TableMobileAppExtensionConfig(tableConfigProvider));
            return(options);
        }
        public void AddBaseRouteExclusion_DoesNotThrow_IfDuplicateItemAdded()
        {
            // Act
            var mobileAppConfig = new MobileAppConfiguration();

            mobileAppConfig.AddBaseRouteExclusion("MobileApp");
            mobileAppConfig.AddBaseRouteExclusion("MobileApp");
            mobileAppConfig.AddBaseRouteExclusion("mobileapp");

            // Assert
            Assert.Equal(1, mobileAppConfig.BaseRouteConstraints.Count);

            // verify that comparisons are case-insensitive
            Assert.True(mobileAppConfig.BaseRouteConstraints.Contains("MobileApp"));
            Assert.True(mobileAppConfig.BaseRouteConstraints.Contains("mobileapp"));
            Assert.True(mobileAppConfig.BaseRouteConstraints.Contains("MOBILEAPP"));
        }
        public static void Register(HttpConfiguration config)
        {
            // Web API configuration and services
            // Configure Web API to use only bearer token authentication.
            config.SuppressDefaultHostAuthentication();
            config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));

            // Web API routes
            config.MapHttpAttributeRoutes();

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );

            var maConfig = new MobileAppConfiguration();

            maConfig.ApplyTo(config);
        }
        public void UseMobileAppAuthentication_ConfiguresServiceAuthentication_WhenAuthEnabled()
        {
            // Arrange
            MobileAppConfiguration configOptions = new MobileAppConfiguration();
            this.config.SetMobileAppConfiguration(configOptions);
            AppServiceAuthenticationOptions options = new AppServiceAuthenticationOptions();

            this.appBuilderMock.Setup(p => p.Use(It.IsAny<object>(), It.IsAny<object[]>()))
                .Callback<object, object[]>((mockObject, mockArgs) =>
                {
                    options = (AppServiceAuthenticationOptions)mockArgs[1];
                })
                .Returns(this.appBuilder)
                .Verifiable();

            // Act
            this.appBuilder.UseAppServiceAuthentication(options);

            // Assert
            this.appBuilderMock.Verify(p => p.Use(It.IsAny<object>(), It.IsAny<object[]>()), Times.Once);
            Assert.Equal("MobileApp", options.AuthenticationType);
        }
Beispiel #18
0
        public void UseMobileAppAuthentication_ConfiguresServiceAuthentication_WhenAuthEnabled()
        {
            // Arrange
            MobileAppConfiguration configOptions = new MobileAppConfiguration();

            this.config.SetMobileAppConfiguration(configOptions);
            AppServiceAuthenticationOptions options = new AppServiceAuthenticationOptions();

            this.appBuilderMock.Setup(p => p.Use(It.IsAny <object>(), It.IsAny <object[]>()))
            .Callback <object, object[]>((mockObject, mockArgs) =>
            {
                options = (AppServiceAuthenticationOptions)mockArgs[1];
            })
            .Returns(this.appBuilder)
            .Verifiable();

            // Act
            this.appBuilder.UseAppServiceAuthentication(options);

            // Assert
            this.appBuilderMock.Verify(p => p.Use(It.IsAny <object>(), It.IsAny <object[]>()), Times.Once);
            Assert.Equal("MobileApp", options.AuthenticationType);
        }
        public void MapApiControllers_AppliesControllerExclusions()
        {
            // Arrange
            var typeList = new[]
            {
                typeof(Mobile1Controller),
                typeof(Mobile2Controller),
                typeof(Mobile3Controller)
            };

            HttpConfiguration config = new HttpConfiguration();

            SetupMockControllerList(config, typeList);

            // Act
            var mobileAppConfig = new MobileAppConfiguration()
                                  .MapApiControllers();

            mobileAppConfig.AddBaseRouteExclusion("Mobile2");
            // verify comparisons are case-insensitive
            mobileAppConfig.AddBaseRouteExclusion("MOBILE3");
            mobileAppConfig.ApplyTo(config);

            // Assert
            Assert.Equal(1, config.Routes.Count);

            var route = config.Routes[0];

            Assert.Equal("api/{controller}/{id}", route.RouteTemplate);
            Assert.Equal(1, route.Constraints.Count);
            var constraint = route.Constraints["controller"] as SetRouteConstraint <string>;

            Assert.NotNull(constraint);
            Assert.Equal(false, constraint.Excluded);
            Assert.Equal(new[] { "Mobile1" }, constraint.Set);
        }
        public void SetMobileAppConfigOptions_Roundtrips()
        {
            // Arrange
            MobileAppConfiguration options = new MobileAppConfiguration();

            // Act
            this.config.SetMobileAppConfiguration(options);
            MobileAppConfiguration actual = this.config.GetMobileAppConfiguration();

            // Assert
            Assert.Same(options, actual);
        }
        public void MapApiControllers_AppliesControllerExclusions()
        {
            // Arrange
            var typeList = new[]
            {
                typeof(Mobile1Controller),
                typeof(Mobile2Controller),
                typeof(Mobile3Controller)
            };

            HttpConfiguration config = new HttpConfiguration();
            SetupMockControllerList(config, typeList);

            // Act
            var mobileAppConfig = new MobileAppConfiguration()
                .MapApiControllers();

            mobileAppConfig.AddBaseRouteExclusion("Mobile2");
            // verify comparisons are case-insensitive
            mobileAppConfig.AddBaseRouteExclusion("MOBILE3");
            mobileAppConfig.ApplyTo(config);

            // Assert
            Assert.Equal(1, config.Routes.Count);

            var route = config.Routes[0];
            Assert.Equal("api/{controller}/{id}", route.RouteTemplate);
            Assert.Equal(1, route.Constraints.Count);
            var constraint = route.Constraints["controller"] as SetRouteConstraint<string>;
            Assert.NotNull(constraint);
            Assert.Equal(false, constraint.Excluded);
            Assert.Equal(new[] { "Mobile1" }, constraint.Set);
        }
        public void AddBaseRouteExclusion_DoesNotThrow_IfDuplicateItemAdded()
        {
            // Act
            var mobileAppConfig = new MobileAppConfiguration();
            mobileAppConfig.AddBaseRouteExclusion("MobileApp");
            mobileAppConfig.AddBaseRouteExclusion("MobileApp");
            mobileAppConfig.AddBaseRouteExclusion("mobileapp");

            // Assert
            Assert.Equal(1, mobileAppConfig.BaseRouteConstraints.Count);

            // verify that comparisons are case-insensitive
            Assert.True(mobileAppConfig.BaseRouteConstraints.Contains("MobileApp"));
            Assert.True(mobileAppConfig.BaseRouteConstraints.Contains("mobileapp"));
            Assert.True(mobileAppConfig.BaseRouteConstraints.Contains("MOBILEAPP"));
        }
        private TestServer CreateTestServer(IEnumerable<string> origins)
        {
            HttpConfiguration config = new HttpConfiguration();
            MobileAppConfiguration mobileConfig = new MobileAppConfiguration();
            CrossDomainController.Reset();

            if (origins == null)
            {
                mobileConfig = mobileConfig.MapLegacyCrossDomainController();
            }
            else
            {
                mobileConfig = mobileConfig.MapLegacyCrossDomainController(origins);
            }

            mobileConfig.ApplyTo(config);

            return TestServer.Create(appBuilder =>
            {
                appBuilder.UseWebApi(config);
            });
        }