public async Task SwaggerUiDocs()
        {
            // Arrange
            HttpConfiguration config = new HttpConfiguration();
            TestServer        server = SwashbuckleHelper.CreateSwaggerServer(config, null, c =>
            {
                c.MobileAppUi(config);
            });

            await ValidateResource(server, "Microsoft.Azure.Mobile.Server.Swagger.o2c.html", "http://localhost/swagger/ui/o2c-html");
            await ValidateResource(server, "Microsoft.Azure.Mobile.Server.Swagger.swagger-ui.min.js", "http://localhost/swagger/ui/swagger-ui-min-js");

            Assert.Contains(typeof(SwaggerUiSecurityFilter), config.MessageHandlers.Select(h => h.GetType()));
        }
        public async Task AppServiceAuthentication_AddsAuthToAuthenticatedControllers()
        {
            // Arrange
            TestServer server = SwashbuckleHelper.CreateSwaggerServer(c =>
            {
                c.AppServiceAuthentication("http://mysite", "google");
            }, null);

            // Act
            HttpResponseMessage swaggerResponse = await server.HttpClient.GetAsync("http://localhost/swagger/docs/v1");

            var swagger = await swaggerResponse.Content.ReadAsAsync <JObject>();

            // Assert
            ValidateSecurity(swagger, "/api/Anonymous", "get", false);
            ValidateSecurity(swagger, "/api/Anonymous", "post", false);
            ValidateSecurity(swagger, "/api/Authenticated", "get", true);
            ValidateSecurity(swagger, "/api/Authenticated", "post", true);
            ValidateSecurity(swagger, "/api/MixedAuth", "get", false);
            ValidateSecurity(swagger, "/api/MixedAuth", "post", true);
        }
        public async Task AppServiceAuthentication_AddsSecurityDefinition()
        {
            // Arrange
            TestServer server = SwashbuckleHelper.CreateSwaggerServer(c =>
            {
                c.AppServiceAuthentication("http://mysite", "google");
            }, null);

            // Act
            HttpResponseMessage swaggerResponse = await server.HttpClient.GetAsync("http://localhost/swagger/docs/v1");

            var swagger = await swaggerResponse.Content.ReadAsAsync <JObject>();

            var googleDef = swagger["securityDefinitions"]["google"];

            // Assert
            Assert.Equal("oauth2", googleDef["type"]);
            Assert.Equal("OAuth2 Implicit Grant", googleDef["description"]);
            Assert.Equal("implicit", googleDef["flow"]);
            Assert.Equal("http://mysite/.auth/login/google", googleDef["authorizationUrl"]);
            Assert.Equal("{}", googleDef["scopes"].ToString());
        }
Beispiel #4
0
        public async Task SwaggerUiDocs()
        {
            // Arrange
            TestServer server = SwashbuckleHelper.CreateSwaggerServer(null, c =>
            {
                c.MobileAppUi();
            });

            string o2cExpected   = GetResourceString("Microsoft.Azure.Mobile.Server.Swagger.o2c.html");
            string oauthExpected = GetResourceString("Microsoft.Azure.Mobile.Server.Swagger.swagger-oauth.js");

            // Act
            var o2cResponse = await server.HttpClient.GetAsync("http://localhost/swagger/ui/o2c-html");

            var oauthResponse = await server.HttpClient.GetAsync("http://localhost/swagger/ui/lib/swagger-oauth-js");

            string o2c = await o2cResponse.Content.ReadAsStringAsync();

            string oauth = await oauthResponse.Content.ReadAsStringAsync();

            // Assert
            Assert.Equal(o2cExpected, o2c);
            Assert.Equal(oauthExpected, oauth);
        }