This commit is contained in:
Javier Suárez Ruiz 2017-03-06 16:27:53 +01:00
commit 9181946438
17 changed files with 81 additions and 236 deletions

View File

@ -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 }

View File

@ -1,18 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" Sdk="Microsoft.Docker.Sdk">
<PropertyGroup Label="Globals">
<ProjectGuid>2ede831a-98f5-4f23-b2db-7e9dc935766a</ProjectGuid>
<DockerLaunchBrowser>True</DockerLaunchBrowser>
<DockerServiceUrl>http://localhost:5100</DockerServiceUrl>
<DockerServiceName>webmvc</DockerServiceName>
</PropertyGroup>
<ItemGroup>
<None Include="docker-compose-windows.override.yml">
<DependentUpon>docker-compose.yml</DependentUpon>
</None>
<None Include="docker-compose-windows.vs.debug.yml">
<DependentUpon>docker-compose.yml</DependentUpon>
</None>
<None Include="docker-compose-windows.yml" />
</ItemGroup>
</Project>

View File

@ -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"

View File

@ -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

View File

@ -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"]

View File

@ -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"]

View File

@ -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"]

View File

@ -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"]

View File

@ -109,15 +109,7 @@
app.UseCors("CorsPolicy"); app.UseCors("CorsPolicy");
var identityUrl = Configuration.GetValue<string>("IdentityUrl"); ConfigureAuth(app);
app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions
{
Authority = identityUrl.ToString(),
ScopeName = "orders",
RequireHttpsMetadata = false
});
app.UseMvcWithDefaultRoute(); app.UseMvcWithDefaultRoute();
@ -126,5 +118,16 @@
OrderingContextSeed.SeedAsync(app).Wait(); OrderingContextSeed.SeedAsync(app).Wait();
} }
protected virtual void ConfigureAuth(IApplicationBuilder app)
{
var identityUrl = Configuration.GetValue<string>("IdentityUrl");
app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions
{
Authority = identityUrl.ToString(),
ScopeName = "orders",
RequireHttpsMetadata = false
});
}
} }
} }

View File

@ -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"]

View File

@ -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"]

View File

@ -32,4 +32,10 @@
<PackageReference Include="xunit" Version="2.2.0-beta5-build3474" /> <PackageReference Include="xunit" Version="2.2.0-beta5-build3474" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<Content Update="settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project> </Project>

View File

@ -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);
}
}
}

View File

@ -11,7 +11,7 @@
{ {
var webHostBuilder = new WebHostBuilder(); var webHostBuilder = new WebHostBuilder();
webHostBuilder.UseContentRoot(Directory.GetCurrentDirectory()); webHostBuilder.UseContentRoot(Directory.GetCurrentDirectory());
webHostBuilder.UseStartup<Startup>(); webHostBuilder.UseStartup<OrderingTestsStartup>();
return new TestServer(webHostBuilder); return new TestServer(webHostBuilder);
} }

View File

@ -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<AutoAuthorizeMiddleware>();
}
else
{
base.ConfigureAuth(app);
}
}
}
}

View File

@ -1,3 +1,5 @@
{ {
"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",
"isTest": "true"
} }

View File

@ -39,8 +39,9 @@ namespace UnitTest.Account
var actionResult = accountController.SignIn(""); var actionResult = accountController.SignIn("");
//Assert //Assert
var redirectResult = Assert.IsType<RedirectResult>(actionResult); var redirectResult = Assert.IsType<RedirectToActionResult>(actionResult);
Assert.Equal(redirectResult.Url, "/"); Assert.Equal(redirectResult.ActionName, "Index");
Assert.Equal(redirectResult.ControllerName, "Catalog");
Assert.Equal(accountController.ViewData["access_token"], "fakeToken"); Assert.Equal(accountController.ViewData["access_token"], "fakeToken");
} }