diff --git a/test/Ocelot.AcceptanceTests/Steps.cs b/test/Ocelot.AcceptanceTests/Steps.cs index 7aba9c48..fb853fbb 100644 --- a/test/Ocelot.AcceptanceTests/Steps.cs +++ b/test/Ocelot.AcceptanceTests/Steps.cs @@ -19,7 +19,6 @@ using Newtonsoft.Json; using Ocelot.Configuration.File; using Ocelot.Configuration.Repository; using Ocelot.DependencyInjection; -using Ocelot.ManualTest; using Ocelot.Middleware; using Ocelot.ServiceDiscovery; using Shouldly; @@ -382,4 +381,42 @@ namespace Ocelot.AcceptanceTests _response.Headers.GetValues(RequestIdKey).First().ShouldBe(expected); } } + + public class Startup + { + public Startup(IHostingEnvironment env) + { + var builder = new ConfigurationBuilder() + .SetBasePath(env.ContentRootPath) + .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) + .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) + .AddJsonFile("configuration.json") + .AddEnvironmentVariables(); + + Configuration = builder.Build(); + } + + public IConfigurationRoot Configuration { get; } + + public void ConfigureServices(IServiceCollection services) + { + Action settings = (x) => + { + x.WithMicrosoftLogging(log => + { + log.AddConsole(LogLevel.Debug); + }) + .WithDictionaryHandle(); + }; + + services.AddOcelot(Configuration, settings); + } + + public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) + { + loggerFactory.AddConsole(Configuration.GetSection("Logging")); + + app.UseOcelot().Wait(); + } + } } diff --git a/test/Ocelot.IntegrationTests/AdministrationTests.cs b/test/Ocelot.IntegrationTests/AdministrationTests.cs index e6fbcb0f..7cc88ed8 100644 --- a/test/Ocelot.IntegrationTests/AdministrationTests.cs +++ b/test/Ocelot.IntegrationTests/AdministrationTests.cs @@ -9,7 +9,6 @@ using Microsoft.Extensions.DependencyInjection; using Newtonsoft.Json; using Ocelot.Cache; using Ocelot.Configuration.File; -using Ocelot.ManualTest; using Shouldly; using TestStack.BDDfy; using Xunit; diff --git a/test/Ocelot.IntegrationTests/Startup.cs b/test/Ocelot.IntegrationTests/Startup.cs new file mode 100644 index 00000000..1b67ff96 --- /dev/null +++ b/test/Ocelot.IntegrationTests/Startup.cs @@ -0,0 +1,51 @@ +using System; +using CacheManager.Core; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Ocelot.DependencyInjection; +using Ocelot.Middleware; +using ConfigurationBuilder = Microsoft.Extensions.Configuration.ConfigurationBuilder; + +namespace Ocelot.IntegrationTests +{ + public class Startup + { + public Startup(IHostingEnvironment env) + { + var builder = new ConfigurationBuilder() + .SetBasePath(env.ContentRootPath) + .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) + .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true) + .AddJsonFile("configuration.json") + .AddEnvironmentVariables(); + + Configuration = builder.Build(); + } + + public IConfigurationRoot Configuration { get; } + + public void ConfigureServices(IServiceCollection services) + { + Action settings = (x) => + { + x.WithMicrosoftLogging(log => + { + log.AddConsole(LogLevel.Debug); + }) + .WithDictionaryHandle(); + }; + + services.AddOcelot(Configuration, settings); + } + + public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) + { + loggerFactory.AddConsole(Configuration.GetSection("Logging")); + + app.UseOcelot().Wait(); + } + } +} \ No newline at end of file diff --git a/test/Ocelot.IntegrationTests/ThreadSafeHeadersTests.cs b/test/Ocelot.IntegrationTests/ThreadSafeHeadersTests.cs index 2922d92c..301d21d6 100644 --- a/test/Ocelot.IntegrationTests/ThreadSafeHeadersTests.cs +++ b/test/Ocelot.IntegrationTests/ThreadSafeHeadersTests.cs @@ -1,15 +1,12 @@ using System; using System.Collections.Generic; using System.IO; -using System.Net; using System.Net.Http; -using System.Net.Http.Headers; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.DependencyInjection; using Newtonsoft.Json; using Ocelot.Configuration.File; -using Ocelot.ManualTest; using Shouldly; using TestStack.BDDfy; using Xunit; diff --git a/test/Ocelot.ManualTest/Ocelot.postman_collection.json b/test/Ocelot.ManualTest/Ocelot.postman_collection.json index eef5f5e8..d8598539 100644 --- a/test/Ocelot.ManualTest/Ocelot.postman_collection.json +++ b/test/Ocelot.ManualTest/Ocelot.postman_collection.json @@ -10,175 +10,362 @@ "e8825dc3-4137-99a7-0000-ef5786610dc3", "fddfc4fa-5114-69e3-4744-203ed71a526b", "c45d30d7-d9c4-fa05-8110-d6e769bb6ff9", - "4684c2fa-f38c-c193-5f55-bf563a1978c6" + "4684c2fa-f38c-c193-5f55-bf563a1978c6", + "37bfa9f1-fe29-6a68-e558-66d125d2c96f", + "5f308240-79e3-cf74-7a6b-fe462f0d54f1", + "178f16da-c61b-c881-1c33-9d64a56851a4" ], "folders": [], - "timestamp": 1477767328599, + "folders_order": [], + "timestamp": 0, "owner": "212120", "public": false, "requests": [ { + "folder": null, "id": "09af8dda-a9cb-20d2-5ee3-0a3023773a1a", - "headers": "", - "url": "http://localhost:5000/comments?postId=1", - "pathVariables": {}, - "preRequestScript": null, - "method": "GET", - "collectionId": "4dbde9fe-89f5-be35-bb9f-d3b438e16375", - "data": null, - "dataMode": "params", "name": "GET http://localhost:5000/comments?postId=1", - "description": "", - "descriptionFormat": "html", - "time": 1477768105592, - "version": 2, - "responses": [], - "tests": null, - "currentHelper": "normal", - "helperAttributes": {} - }, - { - "id": "4684c2fa-f38c-c193-5f55-bf563a1978c6", - "headers": "", - "url": "http://localhost:5000/posts/1", - "pathVariables": {}, - "preRequestScript": null, - "method": "DELETE", - "collectionId": "4dbde9fe-89f5-be35-bb9f-d3b438e16375", - "data": null, "dataMode": "params", - "name": "DELETE http://localhost:5000/posts/1", - "description": "", + "data": null, + "rawModeData": null, "descriptionFormat": "html", - "time": 1477768404376, - "version": 2, - "responses": [], - "tests": null, - "currentHelper": "normal", - "helperAttributes": {} - }, - { - "id": "a1c95935-ed18-d5dc-bcb8-a3db8ba1934f", + "description": "", "headers": "", - "url": "http://localhost:5000/posts", - "pathVariables": {}, - "preRequestScript": null, "method": "GET", - "collectionId": "4dbde9fe-89f5-be35-bb9f-d3b438e16375", - "data": null, - "dataMode": "params", - "name": "GET http://localhost:5000/posts", - "description": "", - "descriptionFormat": "html", - "time": 1477768007806, - "version": 2, - "responses": [], + "pathVariables": {}, + "url": "http://localhost:5000/comments?postId=1", + "preRequestScript": null, "tests": null, "currentHelper": "normal", - "helperAttributes": {} + "helperAttributes": "{}", + "queryParams": [], + "headerData": [], + "pathVariableData": [], + "responses": [], + "collectionId": "4dbde9fe-89f5-be35-bb9f-d3b438e16375" }, { - "id": "c4494401-3985-a5bf-71fb-6e4171384ac6", - "headers": "", - "url": "http://localhost:5000/posts/1/comments", - "pathVariables": {}, + "id": "178f16da-c61b-c881-1c33-9d64a56851a4", + "headers": "Authorization: Bearer {{AccessToken}}\n", + "headerData": [ + { + "key": "Authorization", + "value": "Bearer {{AccessToken}}", + "enabled": true, + "description": "" + } + ], + "url": "http://localhost:5000/administration/configuration", + "folder": null, + "queryParams": [], "preRequestScript": null, + "pathVariables": {}, + "pathVariableData": [], "method": "GET", - "collectionId": "4dbde9fe-89f5-be35-bb9f-d3b438e16375", "data": null, "dataMode": "params", - "name": "GET http://localhost:5000/posts/1/comments", - "description": "", - "descriptionFormat": "html", - "time": 1477768043524, - "version": 2, - "responses": [], "tests": null, "currentHelper": "normal", - "helperAttributes": {} - }, - { - "id": "c45d30d7-d9c4-fa05-8110-d6e769bb6ff9", - "headers": "", - "url": "http://localhost:5000/posts/1", - "pathVariables": {}, - "preRequestScript": null, - "method": "PATCH", + "helperAttributes": "{}", + "time": 1508849878025, + "name": "GET http://localhost:5000/admin/configuration", + "description": "", "collectionId": "4dbde9fe-89f5-be35-bb9f-d3b438e16375", - "data": [], - "dataMode": "raw", - "name": "PATCH http://localhost:5000/posts/1", - "description": "", - "descriptionFormat": "html", - "time": 1477768379775, - "version": 2, "responses": [], - "tests": null, - "currentHelper": "normal", - "helperAttributes": {}, - "rawModeData": "{\n \"title\": \"gfdgsgsdgsdfgsdfgdfg\",\n}" + "isFromCollection": true, + "collectionRequestId": "178f16da-c61b-c881-1c33-9d64a56851a4", + "rawModeData": null, + "descriptionFormat": null }, { - "id": "e8825dc3-4137-99a7-0000-ef5786610dc3", + "id": "37bfa9f1-fe29-6a68-e558-66d125d2c96f", "headers": "", - "url": "http://localhost:5000/posts", - "pathVariables": {}, + "headerData": [], + "url": "http://localhost:5000/administration/connect/token", + "folder": null, + "queryParams": [], "preRequestScript": null, + "pathVariables": {}, + "pathVariableData": [], "method": "POST", - "collectionId": "4dbde9fe-89f5-be35-bb9f-d3b438e16375", - "data": [], - "dataMode": "raw", - "name": "POST http://localhost:5000/posts/1", - "description": "", - "descriptionFormat": "html", - "time": 1477768186023, - "version": 2, - "responses": [], - "tests": null, + "data": [ + { + "key": "client_id", + "value": "admin", + "type": "text", + "enabled": true + }, + { + "key": "client_secret", + "value": "secret", + "type": "text", + "enabled": true + }, + { + "key": "scope", + "value": "admin", + "type": "text", + "enabled": true + }, + { + "key": "username", + "value": "admin", + "type": "text", + "enabled": true + }, + { + "key": "password", + "value": "secret", + "type": "text", + "enabled": true + }, + { + "key": "grant_type", + "value": "password", + "type": "text", + "enabled": true + } + ], + "dataMode": "params", + "tests": "var jsonData = JSON.parse(responseBody);\npostman.setGlobalVariable(\"AccessToken\", jsonData.access_token);\npostman.setGlobalVariable(\"RefreshToken\", jsonData.refresh_token);", "currentHelper": "normal", - "helperAttributes": {}, - "rawModeData": "{\n \"userId\": 1,\n \"title\": \"test\",\n \"body\": \"test\"\n}" + "helperAttributes": "{}", + "time": 1506359585080, + "name": "POST http://localhost:5000/admin/connect/token copy", + "description": "", + "collectionId": "4dbde9fe-89f5-be35-bb9f-d3b438e16375", + "responses": [], + "isFromCollection": true, + "collectionRequestId": "37bfa9f1-fe29-6a68-e558-66d125d2c96f", + "rawModeData": null, + "descriptionFormat": null }, { - "id": "ea0ed57a-2cb9-8acc-47dd-006b8db2f1b2", + "folder": null, + "id": "4684c2fa-f38c-c193-5f55-bf563a1978c6", + "name": "DELETE http://localhost:5000/posts/1", + "dataMode": "params", + "data": null, + "rawModeData": null, + "descriptionFormat": "html", + "description": "", "headers": "", - "url": "http://localhost:5000/posts/1", + "method": "DELETE", "pathVariables": {}, + "url": "http://localhost:5000/posts/1", "preRequestScript": null, + "tests": null, + "currentHelper": "normal", + "helperAttributes": "{}", + "queryParams": [], + "headerData": [], + "pathVariableData": [], + "responses": [], + "collectionId": "4dbde9fe-89f5-be35-bb9f-d3b438e16375" + }, + { + "id": "5f308240-79e3-cf74-7a6b-fe462f0d54f1", + "headers": "Authorization: Bearer {{AccessToken}}\n", + "headerData": [ + { + "key": "Authorization", + "value": "Bearer {{AccessToken}}", + "description": "", + "enabled": true + } + ], + "url": "http://localhost:5000/administration/.well-known/openid-configuration", + "folder": null, + "queryParams": [], + "preRequestScript": null, + "pathVariables": {}, + "pathVariableData": [], "method": "GET", - "collectionId": "4dbde9fe-89f5-be35-bb9f-d3b438e16375", "data": null, "dataMode": "params", - "name": "GET http://localhost:5000/posts/1", - "description": "", - "descriptionFormat": "html", - "time": 1477768023989, - "version": 2, - "responses": [], - "tests": null, - "currentHelper": "normal", - "helperAttributes": {} - }, - { - "id": "fddfc4fa-5114-69e3-4744-203ed71a526b", - "headers": "", - "url": "http://localhost:5000/posts/1", - "pathVariables": {}, - "preRequestScript": null, - "method": "PUT", - "collectionId": "4dbde9fe-89f5-be35-bb9f-d3b438e16375", - "data": [], - "dataMode": "raw", - "name": "PUT http://localhost:5000/posts/1", - "description": "", - "descriptionFormat": "html", - "time": 1477768307036, - "version": 2, - "responses": [], "tests": null, "currentHelper": "normal", "helperAttributes": {}, - "rawModeData": "{\n \"userId\": 1,\n \"title\": \"test\",\n \"body\": \"test\"\n}" + "time": 1508849923518, + "name": "GET http://localhost:5000/admin/.well-known/openid-configuration", + "description": "", + "collectionId": "4dbde9fe-89f5-be35-bb9f-d3b438e16375", + "responses": [] + }, + { + "folder": null, + "id": "a1c95935-ed18-d5dc-bcb8-a3db8ba1934f", + "name": "GET http://localhost:5000/posts", + "dataMode": "params", + "data": [ + { + "key": "client_id", + "value": "admin", + "type": "text", + "enabled": true + }, + { + "key": "client_secret", + "value": "secret", + "type": "text", + "enabled": true + }, + { + "key": "scope", + "value": "admin", + "type": "text", + "enabled": true + }, + { + "key": "username", + "value": "admin", + "type": "text", + "enabled": true + }, + { + "key": "password", + "value": "admin", + "type": "text", + "enabled": true + }, + { + "key": "grant_type", + "value": "password", + "type": "text", + "enabled": true + } + ], + "rawModeData": null, + "descriptionFormat": "html", + "description": "", + "headers": "", + "method": "POST", + "pathVariables": {}, + "url": "http://localhost:5000/admin/configuration", + "preRequestScript": null, + "tests": null, + "currentHelper": "normal", + "helperAttributes": "{}", + "queryParams": [], + "headerData": [], + "pathVariableData": [], + "responses": [], + "collectionId": "4dbde9fe-89f5-be35-bb9f-d3b438e16375" + }, + { + "folder": null, + "id": "c4494401-3985-a5bf-71fb-6e4171384ac6", + "name": "GET http://localhost:5000/posts/1/comments", + "dataMode": "params", + "data": null, + "rawModeData": null, + "descriptionFormat": "html", + "description": "", + "headers": "", + "method": "GET", + "pathVariables": {}, + "url": "http://localhost:5000/posts/1/comments", + "preRequestScript": null, + "tests": null, + "currentHelper": "normal", + "helperAttributes": "{}", + "queryParams": [], + "headerData": [], + "pathVariableData": [], + "responses": [], + "collectionId": "4dbde9fe-89f5-be35-bb9f-d3b438e16375" + }, + { + "folder": null, + "id": "c45d30d7-d9c4-fa05-8110-d6e769bb6ff9", + "name": "PATCH http://localhost:5000/posts/1", + "dataMode": "raw", + "data": [], + "rawModeData": "{\n \"title\": \"gfdgsgsdgsdfgsdfgdfg\",\n}", + "descriptionFormat": "html", + "description": "", + "headers": "", + "method": "PATCH", + "pathVariables": {}, + "url": "http://localhost:5000/posts/1", + "preRequestScript": null, + "tests": null, + "currentHelper": "normal", + "helperAttributes": "{}", + "queryParams": [], + "headerData": [], + "pathVariableData": [], + "responses": [], + "collectionId": "4dbde9fe-89f5-be35-bb9f-d3b438e16375" + }, + { + "folder": null, + "id": "e8825dc3-4137-99a7-0000-ef5786610dc3", + "name": "POST http://localhost:5000/posts/1", + "dataMode": "raw", + "data": [], + "rawModeData": "{\n \"userId\": 1,\n \"title\": \"test\",\n \"body\": \"test\"\n}", + "descriptionFormat": "html", + "description": "", + "headers": "", + "method": "POST", + "pathVariables": {}, + "url": "http://localhost:5000/posts", + "preRequestScript": null, + "tests": null, + "currentHelper": "normal", + "helperAttributes": "{}", + "queryParams": [], + "headerData": [], + "pathVariableData": [], + "responses": [], + "collectionId": "4dbde9fe-89f5-be35-bb9f-d3b438e16375" + }, + { + "folder": null, + "id": "ea0ed57a-2cb9-8acc-47dd-006b8db2f1b2", + "name": "GET http://localhost:5000/posts/1", + "dataMode": "params", + "data": null, + "rawModeData": null, + "descriptionFormat": "html", + "description": "", + "headers": "", + "method": "GET", + "pathVariables": {}, + "url": "http://localhost:5000/posts/1", + "preRequestScript": null, + "tests": null, + "currentHelper": "normal", + "helperAttributes": "{}", + "queryParams": [], + "headerData": [], + "pathVariableData": [], + "responses": [], + "collectionId": "4dbde9fe-89f5-be35-bb9f-d3b438e16375" + }, + { + "folder": null, + "id": "fddfc4fa-5114-69e3-4744-203ed71a526b", + "name": "PUT http://localhost:5000/posts/1", + "dataMode": "raw", + "data": [], + "rawModeData": "{\n \"userId\": 1,\n \"title\": \"test\",\n \"body\": \"test\"\n}", + "descriptionFormat": "html", + "description": "", + "headers": "", + "method": "PUT", + "pathVariables": {}, + "url": "http://localhost:5000/posts/1", + "preRequestScript": null, + "tests": null, + "currentHelper": "normal", + "helperAttributes": "{}", + "queryParams": [], + "headerData": [], + "pathVariableData": [], + "responses": [], + "collectionId": "4dbde9fe-89f5-be35-bb9f-d3b438e16375" } ] } \ No newline at end of file diff --git a/test/Ocelot.ManualTest/Startup.cs b/test/Ocelot.ManualTest/Startup.cs index 1ecda12e..cd5be1c4 100644 --- a/test/Ocelot.ManualTest/Startup.cs +++ b/test/Ocelot.ManualTest/Startup.cs @@ -33,11 +33,18 @@ namespace Ocelot.ManualTest { x.WithMicrosoftLogging(log => { - //log.AddConsole(LogLevel.Debug); + log.AddConsole(LogLevel.Debug); }) .WithDictionaryHandle(); }; + services.AddAuthentication() + .AddJwtBearer("TestKey", x => + { + x.Authority = "test"; + x.Audience = "test"; + }); + services.AddOcelot(Configuration, settings); } diff --git a/test/Ocelot.ManualTest/configuration.json b/test/Ocelot.ManualTest/configuration.json index 83dc9f66..a063fe76 100644 --- a/test/Ocelot.ManualTest/configuration.json +++ b/test/Ocelot.ManualTest/configuration.json @@ -13,17 +13,11 @@ "TimeoutValue": 5000 }, "AuthenticationOptions": { - "Provider": "IdentityServer", + "AuthenticationProviderKey": "TestKey", "AllowedScopes": [ "openid", "offline_access" - ], - "IdentityServerConfig": { - "ProviderRootUrl": "http://localhost:52888", - "ApiName": "api", - "ApiSecret": "secret", - "RequireHttps": false - } + ] }, "AddHeadersToRequest": { "CustomerId": "Claims[CustomerId] > value",