From 1e4513b5c9768fab619f8412155cfbd3bcbcbf01 Mon Sep 17 00:00:00 2001 From: dsanz Date: Mon, 6 Mar 2017 11:31:02 +0100 Subject: [PATCH 1/4] Fix unit test. --- test/Services/UnitTest/Account/AccountControllerTest.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/Services/UnitTest/Account/AccountControllerTest.cs b/test/Services/UnitTest/Account/AccountControllerTest.cs index 82ecb9519..8542cca0e 100644 --- a/test/Services/UnitTest/Account/AccountControllerTest.cs +++ b/test/Services/UnitTest/Account/AccountControllerTest.cs @@ -39,8 +39,9 @@ namespace UnitTest.Account var actionResult = accountController.SignIn(""); //Assert - var redirectResult = Assert.IsType(actionResult); - Assert.Equal(redirectResult.Url, "/"); + var redirectResult = Assert.IsType(actionResult); + Assert.Equal(redirectResult.ActionName, "Index"); + Assert.Equal(redirectResult.ControllerName, "Catalog"); Assert.Equal(accountController.ViewData["access_token"], "fakeToken"); } From 0fc35d7b4e93a9c03e1c72866f904b72c57004c5 Mon Sep 17 00:00:00 2001 From: dsanz Date: Mon, 6 Mar 2017 11:59:59 +0100 Subject: [PATCH 2/4] Add missing config file for ordering integration tests --- test/Services/FunctionalTests/FunctionalTests.csproj | 6 ++++++ test/Services/FunctionalTests/settings.json | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/test/Services/FunctionalTests/FunctionalTests.csproj b/test/Services/FunctionalTests/FunctionalTests.csproj index 662e1c698..266e08112 100644 --- a/test/Services/FunctionalTests/FunctionalTests.csproj +++ b/test/Services/FunctionalTests/FunctionalTests.csproj @@ -32,4 +32,10 @@ + + + PreserveNewest + + + diff --git a/test/Services/FunctionalTests/settings.json b/test/Services/FunctionalTests/settings.json index a95b8262f..8d56435f4 100644 --- a/test/Services/FunctionalTests/settings.json +++ b/test/Services/FunctionalTests/settings.json @@ -1,3 +1,4 @@ { - "ConnectionString": "Server=tcp:127.0.0.1,5433;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word;" + "ConnectionString": "Server=tcp:127.0.0.1,5433;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word;", + "IdentityUrl": "http://localhost:5105" } From c38e0782651e65da9044d86cdb64b671a8296d5e Mon Sep 17 00:00:00 2001 From: etomas Date: Mon, 6 Mar 2017 15:00:41 +0100 Subject: [PATCH 3/4] Deleting windows container files as they are not still supported --- _docker/redis/Dockerfile.nanowin | 28 -------- docker-compose-windows.dcproj | 18 ----- docker-compose-windows.override.yml | 69 ------------------ docker-compose-windows.yml | 71 ------------------- .../Basket/Basket.API/Dockerfile.nanowin | 6 -- .../Catalog/Catalog.API/Dockerfile.nanowin | 6 -- .../Identity/Identity.API/Dockerfile.nanowin | 6 -- .../Ordering/Ordering.API/Dockerfile.nanowin | 6 -- src/Web/WebMVC/Dockerfile.nanowin | 6 -- src/Web/WebSPA/Dockerfile.nanowin | 6 -- 10 files changed, 222 deletions(-) delete mode 100644 _docker/redis/Dockerfile.nanowin delete mode 100644 docker-compose-windows.dcproj delete mode 100644 docker-compose-windows.override.yml delete mode 100644 docker-compose-windows.yml delete mode 100644 src/Services/Basket/Basket.API/Dockerfile.nanowin delete mode 100644 src/Services/Catalog/Catalog.API/Dockerfile.nanowin delete mode 100644 src/Services/Identity/Identity.API/Dockerfile.nanowin delete mode 100644 src/Services/Ordering/Ordering.API/Dockerfile.nanowin delete mode 100644 src/Web/WebMVC/Dockerfile.nanowin delete mode 100644 src/Web/WebSPA/Dockerfile.nanowin diff --git a/_docker/redis/Dockerfile.nanowin b/_docker/redis/Dockerfile.nanowin deleted file mode 100644 index 6a36d1947..000000000 --- a/_docker/redis/Dockerfile.nanowin +++ /dev/null @@ -1,28 +0,0 @@ -# The MSI installs a service which is hard to override, so let's use a zip file. - -FROM microsoft/windowsservercore -MAINTAINER alexellis2@gmail.com - -SHELL ["powershell"] -RUN $ErrorActionPreference = 'Stop'; \ - wget https://github.com/MSOpenTech/redis/releases/download/win-3.2.100/Redis-x64-3.2.100.zip -OutFile Redis-x64-3.2.100.zip ; \ - Expand-Archive Redis-x64-3.2.100.zip -dest 'C:\\Program Files\\Redis\\' ; \ - Remove-Item Redis-x64-3.2.100.zip -Force - -RUN setx PATH '%PATH%;C:\\Program Files\\Redis\\' -WORKDIR 'C:\\Program Files\\Redis\\' - - - -RUN Get-Content redis.windows.conf | Where { $_ -notmatch 'bind 127.0.0.1' } | Set-Content redis.openport.conf ; \ - Get-Content redis.openport.conf | Where { $_ -notmatch 'protected-mode yes' } | Set-Content redis.unprotected.conf ; \ - Add-Content redis.unprotected.conf 'protected-mode no' ; \ - Add-Content redis.unprotected.conf 'bind 0.0.0.0' ; \ - Get-Content redis.unprotected.conf - -EXPOSE 6379 - -# Define our command to be run when launching the container -CMD .\\redis-server.exe .\\redis.unprotected.conf --port 6379 ; \ - Write-Host Redis Started... ; \ - while ($true) { Start-Sleep -Seconds 3600 } diff --git a/docker-compose-windows.dcproj b/docker-compose-windows.dcproj deleted file mode 100644 index 89b2fef3e..000000000 --- a/docker-compose-windows.dcproj +++ /dev/null @@ -1,18 +0,0 @@ - - - - 2ede831a-98f5-4f23-b2db-7e9dc935766a - True - http://localhost:5100 - webmvc - - - - docker-compose.yml - - - docker-compose.yml - - - - \ No newline at end of file diff --git a/docker-compose-windows.override.yml b/docker-compose-windows.override.yml deleted file mode 100644 index b6f9bb870..000000000 --- a/docker-compose-windows.override.yml +++ /dev/null @@ -1,69 +0,0 @@ -version: '2.1' - -services: - - basket.api: - environment: - - ASPNETCORE_ENVIRONMENT=Development - - ConnectionString=basket.data - #- identityUrl=http://13.88.8.119:5105 #Remote: VM Needs to have public access at 5105. - - identityUrl=http://identity.api:5105 #Local: You need to open your local dev-machine firewall at range 5100-5105. at range 5100-5105. - ports: - - "5103:5103" - - catalog.api: - environment: - - ASPNETCORE_ENVIRONMENT=Development - - ConnectionString=Server=sql.data;Database=Microsoft.eShopOnContainers.Services.CatalogDb;User Id=sa;Password=Pass@word - #- ExternalCatalogBaseUrl=http://13.88.8.119:5101 #Remote: VM Needs to have public access at 5105. - - ExternalCatalogBaseUrl=http://localhost:5101 #Local: You need to open your local dev-machine firewall at range 5100-5105. at range 5100-5105. - ports: - - "5101:5101" - - identity.api: - environment: - - ASPNETCORE_ENVIRONMENT=Development - - SpaClient=http://localhost:5104 - - ConnectionStrings__DefaultConnection=Server=sql.data;Database=Microsoft.eShopOnContainers.Service.IdentityDb;User Id=sa;Password=Pass@word - #- MvcClient=http://13.88.8.119:5100 #Remote: VM Needs to have public access at 5105. - - MvcClient=http://localhost:5100 #Local: You need to open your local dev-machine firewall at range 5100-5105. - ports: - - "5105:5105" - - ordering.api: - environment: - - ASPNETCORE_ENVIRONMENT=Development - - ConnectionString=Server=sql.data;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word - #- identityUrl=http://13.88.8.119:5105 #Remote: VM Needs to have public access at 5105. - - identityUrl=http://identity.api:5105 #Local: You need to open your local dev-machine firewall at range 5100-5105. at range 5100-5105. - ports: - - "5102:5102" - - webspa: - environment: - - ASPNETCORE_ENVIRONMENT=Development - - CatalogUrl=http://localhost:5101 - - OrderingUrl=http://localhost:5102 - #- IdentityUrl=http://13.88.8.119:5105 #Remote: VM Needs to have public access at 5105. - - IdentityUrl=http://localhost:5105 #Local: You need to open your local dev-machine firewall at range 5100-5105. at range 5100-5105. - - BasketUrl=http://localhost:5103 - ports: - - "5104:5104" - - webmvc: - environment: - - ASPNETCORE_ENVIRONMENT=Development - - CatalogUrl=http://catalog.api:5101 - - OrderingUrl=http://ordering.api:5102 - #- IdentityUrl=http://13.88.8.119:5105 #Remote: VM Needs to have public access at 5105. - - IdentityUrl=http://10.0.75.1:5105 #Local: You need to open your local dev-machine firewall at range 5100-5105. at range 5100-5105. - - BasketUrl=http://basket.api:5103 - ports: - - "5100:5100" - - sql.data: - environment: - - SA_PASSWORD=Pass@word - - ACCEPT_EULA=Y - ports: - - "5433:1433" \ No newline at end of file diff --git a/docker-compose-windows.yml b/docker-compose-windows.yml deleted file mode 100644 index 3c4675466..000000000 --- a/docker-compose-windows.yml +++ /dev/null @@ -1,71 +0,0 @@ -version: '2.1' - -services: - basket.api: - image: eshop/basket.api - build: - context: ./src/Services/Basket/Basket.API - dockerfile: Dockerfile.nanowin - depends_on: - - basket.data - - identity.api - - catalog.api: - image: eshop/catalog.api - build: - context: ./src/Services/Catalog/Catalog.API - dockerfile: Dockerfile.nanowin - depends_on: - - sql.data - - identity.api: - image: eshop/identity.api - build: - context: ./src/Services/Identity/Identity.API - dockerfile: Dockerfile.nanowin - depends_on: - - sql.data - - ordering.api: - image: eshop/ordering.api - build: - context: ./src/Services/Ordering/Ordering.API - dockerfile: Dockerfile.nanowin - depends_on: - - sql.data - - webspa: - image: eshop/webspa - build: - context: ./src/Web/WebSPA - dockerfile: Dockerfile.nanowin - depends_on: - - identity.api - - basket.api - - webmvc: - image: eshop/webmvc - build: - context: ./src/Web/WebMVC - dockerfile: Dockerfile.nanowin - depends_on: - - catalog.api - - ordering.api - - identity.api - - basket.api - - sql.data: - image: microsoft/mssql-server-windows - - basket.data: - image: eshop/redis - build: - context: ./_docker/redis - dockerfile: Dockerfile.nanowin - ports: - - "6379:6379" -networks: - default: - external: - name: nat - diff --git a/src/Services/Basket/Basket.API/Dockerfile.nanowin b/src/Services/Basket/Basket.API/Dockerfile.nanowin deleted file mode 100644 index 41127e339..000000000 --- a/src/Services/Basket/Basket.API/Dockerfile.nanowin +++ /dev/null @@ -1,6 +0,0 @@ -FROM microsoft/dotnet:1.1-runtime-nanoserver -ARG source -WORKDIR /app -EXPOSE 80 -COPY ${source:-obj/Docker/publish} . -ENTRYPOINT ["dotnet", "Basket.API.dll"] diff --git a/src/Services/Catalog/Catalog.API/Dockerfile.nanowin b/src/Services/Catalog/Catalog.API/Dockerfile.nanowin deleted file mode 100644 index 5aad21ad1..000000000 --- a/src/Services/Catalog/Catalog.API/Dockerfile.nanowin +++ /dev/null @@ -1,6 +0,0 @@ -FROM microsoft/dotnet:1.1-runtime-nanoserver -ARG source -WORKDIR /app -EXPOSE 80 -COPY ${source:-obj/Docker/publish} . -ENTRYPOINT ["dotnet", "Catalog.API.dll"] diff --git a/src/Services/Identity/Identity.API/Dockerfile.nanowin b/src/Services/Identity/Identity.API/Dockerfile.nanowin deleted file mode 100644 index 01f5eb8c5..000000000 --- a/src/Services/Identity/Identity.API/Dockerfile.nanowin +++ /dev/null @@ -1,6 +0,0 @@ -FROM microsoft/dotnet:1.1-runtime-nanoserver -ARG source -WORKDIR /app -EXPOSE 80 -COPY ${source:-obj/Docker/publish} . -ENTRYPOINT ["dotnet", "Identity.API.dll"] diff --git a/src/Services/Ordering/Ordering.API/Dockerfile.nanowin b/src/Services/Ordering/Ordering.API/Dockerfile.nanowin deleted file mode 100644 index 85b1f46b4..000000000 --- a/src/Services/Ordering/Ordering.API/Dockerfile.nanowin +++ /dev/null @@ -1,6 +0,0 @@ -FROM microsoft/dotnet:1.1-runtime-nanoserver -ARG source -WORKDIR /app -EXPOSE 80 -COPY ${source:-obj/Docker/publish} . -ENTRYPOINT ["dotnet", "Ordering.API.dll"] diff --git a/src/Web/WebMVC/Dockerfile.nanowin b/src/Web/WebMVC/Dockerfile.nanowin deleted file mode 100644 index fe622e8de..000000000 --- a/src/Web/WebMVC/Dockerfile.nanowin +++ /dev/null @@ -1,6 +0,0 @@ -FROM microsoft/dotnet:1.1-runtime-nanoserver -ARG source -WORKDIR /app -EXPOSE 80 -COPY ${source:-obj/Docker/publish} . -ENTRYPOINT ["dotnet", "WebMVC.dll"] diff --git a/src/Web/WebSPA/Dockerfile.nanowin b/src/Web/WebSPA/Dockerfile.nanowin deleted file mode 100644 index 8c784ca6e..000000000 --- a/src/Web/WebSPA/Dockerfile.nanowin +++ /dev/null @@ -1,6 +0,0 @@ -FROM microsoft/dotnet:1.1-runtime-nanoserver -ARG source -WORKDIR /app -EXPOSE 80 -COPY ${source:-obj/Docker/publish} . -ENTRYPOINT ["dotnet", "WebSPA.dll"] From 52bddc51a236fdf2f480cb5b8e0b48d9eaa13d4d Mon Sep 17 00:00:00 2001 From: dsanz Date: Mon, 6 Mar 2017 16:06:32 +0100 Subject: [PATCH 4/4] Update integration tests to work with authentication in the Order.Api --- src/Services/Ordering/Ordering.API/Startup.cs | 21 ++++++++------ .../Middleware/AutoAuthorizeMiddleware.cs | 26 +++++++++++++++++ .../Services/Ordering/OrderingScenarioBase.cs | 4 +-- .../Services/Ordering/OrderingTestsStartup.cs | 29 +++++++++++++++++++ test/Services/FunctionalTests/settings.json | 3 +- 5 files changed, 71 insertions(+), 12 deletions(-) create mode 100644 test/Services/FunctionalTests/Middleware/AutoAuthorizeMiddleware.cs create mode 100644 test/Services/FunctionalTests/Services/Ordering/OrderingTestsStartup.cs diff --git a/src/Services/Ordering/Ordering.API/Startup.cs b/src/Services/Ordering/Ordering.API/Startup.cs index 0f75b6370..f1d58be1d 100644 --- a/src/Services/Ordering/Ordering.API/Startup.cs +++ b/src/Services/Ordering/Ordering.API/Startup.cs @@ -109,15 +109,7 @@ app.UseCors("CorsPolicy"); - var identityUrl = Configuration.GetValue("IdentityUrl"); - - app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions - { - Authority = identityUrl.ToString(), - ScopeName = "orders", - RequireHttpsMetadata = false - }); - + ConfigureAuth(app); app.UseMvcWithDefaultRoute(); @@ -126,5 +118,16 @@ OrderingContextSeed.SeedAsync(app).Wait(); } + + protected virtual void ConfigureAuth(IApplicationBuilder app) + { + var identityUrl = Configuration.GetValue("IdentityUrl"); + app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions + { + Authority = identityUrl.ToString(), + ScopeName = "orders", + RequireHttpsMetadata = false + }); + } } } diff --git a/test/Services/FunctionalTests/Middleware/AutoAuthorizeMiddleware.cs b/test/Services/FunctionalTests/Middleware/AutoAuthorizeMiddleware.cs new file mode 100644 index 000000000..72248e29d --- /dev/null +++ b/test/Services/FunctionalTests/Middleware/AutoAuthorizeMiddleware.cs @@ -0,0 +1,26 @@ +using Microsoft.AspNetCore.Http; +using System; +using System.Collections.Generic; +using System.Security.Claims; +using System.Text; +using System.Threading.Tasks; + +namespace FunctionalTests.Middleware +{ + class AutoAuthorizeMiddleware + { + private readonly RequestDelegate _next; + public AutoAuthorizeMiddleware(RequestDelegate rd) + { + _next = rd; + } + + public async Task Invoke(HttpContext httpContext) + { + var identity = new ClaimsIdentity(); + identity.AddClaim(new Claim("sub", "1234")); + httpContext.User.AddIdentity(identity); + await _next.Invoke(httpContext); + } + } +} diff --git a/test/Services/FunctionalTests/Services/Ordering/OrderingScenarioBase.cs b/test/Services/FunctionalTests/Services/Ordering/OrderingScenarioBase.cs index ee069ffc4..bf267d5f7 100644 --- a/test/Services/FunctionalTests/Services/Ordering/OrderingScenarioBase.cs +++ b/test/Services/FunctionalTests/Services/Ordering/OrderingScenarioBase.cs @@ -9,9 +9,9 @@ { public TestServer CreateServer() { - var webHostBuilder = new WebHostBuilder(); + var webHostBuilder = new WebHostBuilder(); webHostBuilder.UseContentRoot(Directory.GetCurrentDirectory()); - webHostBuilder.UseStartup(); + webHostBuilder.UseStartup(); return new TestServer(webHostBuilder); } diff --git a/test/Services/FunctionalTests/Services/Ordering/OrderingTestsStartup.cs b/test/Services/FunctionalTests/Services/Ordering/OrderingTestsStartup.cs new file mode 100644 index 000000000..02237113f --- /dev/null +++ b/test/Services/FunctionalTests/Services/Ordering/OrderingTestsStartup.cs @@ -0,0 +1,29 @@ +using Microsoft.eShopOnContainers.Services.Ordering.API; +using System; +using System.Collections.Generic; +using System.Text; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Builder; +using FunctionalTests.Middleware; + +namespace FunctionalTests.Services.Ordering +{ + public class OrderingTestsStartup : Startup + { + public OrderingTestsStartup(IHostingEnvironment env) : base(env) + { + } + + protected override void ConfigureAuth(IApplicationBuilder app) + { + if (Configuration["isTest"] == bool.TrueString.ToLowerInvariant()) + { + app.UseMiddleware(); + } + else + { + base.ConfigureAuth(app); + } + } + } +} diff --git a/test/Services/FunctionalTests/settings.json b/test/Services/FunctionalTests/settings.json index 8d56435f4..3b6023956 100644 --- a/test/Services/FunctionalTests/settings.json +++ b/test/Services/FunctionalTests/settings.json @@ -1,4 +1,5 @@ { "ConnectionString": "Server=tcp:127.0.0.1,5433;Database=Microsoft.eShopOnContainers.Services.OrderingDb;User Id=sa;Password=Pass@word;", - "IdentityUrl": "http://localhost:5105" + "IdentityUrl": "http://localhost:5105", + "isTest": "true" }