Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests passing on debian 10 #1647

Merged
merged 4 commits into from
Apr 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ orbs:
jobs:
build:
docker:
- image: mijitt0m/ocelot-build:0.0.7
- image: mijitt0m/ocelot-build:0.0.9
steps:
- checkout
- run: dotnet tool restore && dotnet cake
release:
docker:
- image: mijitt0m/ocelot-build:0.0.7
- image: mijitt0m/ocelot-build:0.0.9
steps:
- checkout
- run: dotnet tool restore && dotnet cake --target=Release
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ ClientBin/
*.dbmdl
*.dbproj.schemaview
*.pfx
!idsrv3test.pfx
!mycert.pfx
*.publishsettings
node_modules/
orleans.codegen.cs
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ A quick list of Ocelot's capabilities for more information see the [documentatio

## How to install

Ocelot is designed to work with ASP.NET and it targets `net6.0`.
Ocelot is designed to work with ASP.NET and it targets `net7.0`.

Install Ocelot and it's dependencies using NuGet.

Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile.base
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine

RUN apk add bash icu-libs krb5-libs libgcc libintl libssl1.1 libstdc++ zlib
RUN apk add bash icu-libs krb5-libs libgcc libintl libssl1.1 libstdc++ zlib git openssh-client

RUN curl -L --output ./dotnet-install.sh https://dot.net/v1/dotnet-install.sh

Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile.build
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# call from ocelot repo root with
# docker build --platform linux/arm64 --build-arg OCELOT_COVERALLS_TOKEN=$OCELOT_COVERALLS_TOKEN -f ./docker/Dockerfile.build .
# docker build --platform linux/amd64 --build-arg OCELOT_COVERALLS_TOKEN=$OCELOT_COVERALLS_TOKEN -f ./docker/Dockerfile.build .
FROM mijitt0m/ocelot-build:0.0.7
FROM mijitt0m/ocelot-build:0.0.9

ARG OCELOT_COVERALLS_TOKEN

Expand Down
2 changes: 1 addition & 1 deletion docker/Dockerfile.release
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# call from ocelot repo root with
# docker build --platform linux/arm64 --build-arg OCELOT_COVERALLS_TOKEN=$OCELOT_COVERALLS_TOKEN --build-arg OCELOT_GITHUB_API_KEY=$OCELOT_GITHUB_API_KEY --build-arg OCELOT_COVERALLS_TOKEN=$OCELOT_COVERALLS_TOKEN -f ./docker/Dockerfile.build .
# docker build --platform linux/amd64 --build-arg OCELOT_COVERALLS_TOKEN=$OCELOT_COVERALLS_TOKEN --build-arg OCELOT_GITHUB_API_KEY=$OCELOT_GITHUB_API_KEY --build-arg OCELOT_COVERALLS_TOKEN=$OCELOT_COVERALLS_TOKEN -f ./docker/Dockerfile.build .
FROM mijitt0m/ocelot-build:0.0.7
FROM mijitt0m/ocelot-build:0.0.9

ARG OCELOT_COVERALLS_TOKEN
ARG OCELOT_NUTGET_API_KEY
Expand Down
2 changes: 1 addition & 1 deletion docker/build.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# this script build the ocelot docker file
version=0.0.7
version=0.0.9
docker build --platform linux/amd64 -t mijitt0m/ocelot-build -f Dockerfile.base .
echo $DOCKER_PASS | docker login -u $DOCKER_USER --password-stdin
docker tag mijitt0m/ocelot-build mijitt0m/ocelot-build:$version
Expand Down
11 changes: 11 additions & 0 deletions docs/building/tests.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,15 @@ Tests
The tests should all just run and work as part of the build process. You can of course also run them in visual studio.


Create SSL Cert for Testing
^^^^^^^^^^^^^^^^^^^^^^^^^^^

You can do this via openssl:

Install openssl package (if you are using Windows, download binaries here).

Generate private key: `openssl genrsa 2048 > private.pem`

Generate the self signed certificate: `openssl req -x509 -days 1000 -new -key private.pem -out public.pem`

If needed, create PFX: `openssl pkcs12 -export -in public.pem -inkey private.pem -out mycert.pfx`
3 changes: 2 additions & 1 deletion src/Ocelot/Requester/HttpClientBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public IHttpClient Create(DownstreamRoute downstreamRoute)

if (downstreamRoute.DangerousAcceptAnyServerCertificateValidator)
{
handler.ServerCertificateCustomValidationCallback = (request, certificate, chain, errors) => true;
handler.ServerCertificateCustomValidationCallback =
HttpClientHandler.DangerousAcceptAnyServerCertificateValidator;

_logger
.LogWarning($"You have ignored all SSL warnings by using DangerousAcceptAnyServerCertificateValidator for this DownstreamRoute, UpstreamPathTemplate: {downstreamRoute.UpstreamPathTemplate}, DownstreamPathTemplate: {downstreamRoute.DownstreamPathTemplate}");
Expand Down
32 changes: 21 additions & 11 deletions test/Ocelot.AcceptanceTests/HttpTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ namespace Ocelot.AcceptanceTests
using System.IO;
using System.Net;
using System.Net.Http;

using Configuration.File;

using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Server.Kestrel.Core;

using TestStack.BDDfy;

using Xunit;

public class HttpTests : IDisposable
Expand All @@ -38,7 +38,7 @@ public void should_return_response_200_when_using_http_one()
new()
{
DownstreamPathTemplate = "/{url}",
DownstreamScheme = "https",
DownstreamScheme = "http",
UpstreamPathTemplate = "/{url}",
UpstreamHttpMethod = new List<string> { "Get" },
DownstreamHostAndPorts = new List<FileHostAndPort>
Expand All @@ -51,7 +51,6 @@ public void should_return_response_200_when_using_http_one()
},
DownstreamHttpMethod = "POST",
DownstreamHttpVersion = "1.0",
DangerousAcceptAnyServerCertificateValidator = true
},
},
};
Expand All @@ -76,7 +75,7 @@ public void should_return_response_200_when_using_http_one_point_one()
new()
{
DownstreamPathTemplate = "/{url}",
DownstreamScheme = "https",
DownstreamScheme = "http",
UpstreamPathTemplate = "/{url}",
UpstreamHttpMethod = new List<string> { "Get" },
DownstreamHostAndPorts = new List<FileHostAndPort>
Expand All @@ -89,7 +88,6 @@ public void should_return_response_200_when_using_http_one_point_one()
},
DownstreamHttpMethod = "POST",
DownstreamHttpVersion = "1.1",
DangerousAcceptAnyServerCertificateValidator = true
},
},
};
Expand Down Expand Up @@ -135,7 +133,7 @@ public void should_return_response_200_when_using_http_two_point_zero()
const string expected = "here is some content";
var httpContent = new StringContent(expected);

this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}/", "/", port, HttpProtocols.Http2))
this.Given(x => x.GivenThereIsAServiceUsingHttpsRunningOn($"http://localhost:{port}/", "/", port, HttpProtocols.Http2))
.And(x => _steps.GivenThereIsAConfiguration(configuration))
.And(x => _steps.GivenOcelotIsRunning())
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/", httpContent))
Expand Down Expand Up @@ -185,6 +183,7 @@ public void should_return_response_502_when_using_http_one_to_talk_to_server_run
.BDDfy();
}

//TODO: does this test make any sense?
[Fact]
public void should_return_response_200_when_using_http_two_to_talk_to_server_running_http_one_point_one()
{
Expand All @@ -197,7 +196,7 @@ public void should_return_response_200_when_using_http_two_to_talk_to_server_run
new()
{
DownstreamPathTemplate = "/{url}",
DownstreamScheme = "https",
DownstreamScheme = "http",
UpstreamPathTemplate = "/{url}",
UpstreamHttpMethod = new List<string> { "Get" },
DownstreamHostAndPorts = new List<FileHostAndPort>
Expand All @@ -209,7 +208,7 @@ public void should_return_response_200_when_using_http_two_to_talk_to_server_run
},
},
DownstreamHttpMethod = "POST",
DownstreamHttpVersion = "2.0",
DownstreamHttpVersion = "1.1",
DangerousAcceptAnyServerCertificateValidator = true
},
},
Expand Down Expand Up @@ -238,6 +237,17 @@ private void GivenThereIsAServiceRunningOn(string baseUrl, string basePath, int
}, port, protocols);
}

private void GivenThereIsAServiceUsingHttpsRunningOn(string baseUrl, string basePath, int port, HttpProtocols protocols)
{
_serviceHandler.GivenThereIsAServiceRunningOnUsingHttps(baseUrl, basePath, async context =>
{
context.Response.StatusCode = 200;
var reader = new StreamReader(context.Request.Body);
var body = await reader.ReadToEndAsync();
await context.Response.WriteAsync(body);
}, port, protocols);
}

public void Dispose()
{
_serviceHandler.Dispose();
Expand Down
2 changes: 1 addition & 1 deletion test/Ocelot.AcceptanceTests/Ocelot.AcceptanceTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="idsrv3test.pfx">
<None Update="mycert.pfx">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
Expand Down
31 changes: 30 additions & 1 deletion test/Ocelot.AcceptanceTests/ServiceHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
using System.IO;
using System.Net;
using System.Threading.Tasks;
using System.Security.Authentication;

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Hosting;

public class ServiceHandler : IDisposable
{
Expand Down Expand Up @@ -58,7 +60,34 @@ public void GivenThereIsAServiceRunningOn(string baseUrl, string basePath, Reque
{
serverOptions.Listen(IPAddress.Loopback, port, listenOptions =>
{
listenOptions.UseHttps("idsrv3test.pfx", "idsrv3test");
listenOptions.Protocols = protocols;
});
})
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.Configure(app =>
{
app.UsePathBase(basePath);
app.Run(del);
})
.Build();

_builder.Start();
}

public void GivenThereIsAServiceRunningOnUsingHttps(string baseUrl, string basePath, RequestDelegate del, int port, HttpProtocols protocols)
{
_builder = new WebHostBuilder()
.UseUrls(baseUrl)
.UseKestrel()
.ConfigureKestrel(serverOptions =>
{
serverOptions.Listen(IPAddress.Loopback, port, listenOptions =>
{
listenOptions.UseHttps("mycert.pfx", "password", options =>
{
options.SslProtocols = SslProtocols.Tls12;
});
listenOptions.Protocols = protocols;
});
})
Expand Down
18 changes: 9 additions & 9 deletions test/Ocelot.AcceptanceTests/SslTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ namespace Ocelot.AcceptanceTests
{
using System;
using System.Collections.Generic;
using System.Net;

using Configuration.File;

using Microsoft.AspNetCore.Http;

using TestStack.BDDfy;

using System.Net;
using Configuration.File;
using Microsoft.AspNetCore.Http;
using TestStack.BDDfy;
using Xunit;

public class SslTests : IDisposable
Expand Down Expand Up @@ -99,7 +99,7 @@ public void should_not_dangerous_accept_any_server_certificate_validator()

private void GivenThereIsAServiceRunningOn(string baseUrl, string basePath, int statusCode, string responseBody, int port)
{
_serviceHandler.GivenThereIsAServiceRunningOn(baseUrl, basePath, "idsrv3test.pfx", "idsrv3test", port, async context =>
_serviceHandler.GivenThereIsAServiceRunningOn(baseUrl, basePath, "mycert.pfx", "password", port, async context =>
{
_downstreamPath = !string.IsNullOrEmpty(context.Request.PathBase.Value) ? context.Request.PathBase.Value : context.Request.Path.Value;

Expand Down
Binary file added test/Ocelot.AcceptanceTests/mycert.pfx
Binary file not shown.
4 changes: 2 additions & 2 deletions test/Ocelot.IntegrationTests/AdministrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -628,8 +628,8 @@ private void GivenAnotherOcelotIsRunning(string baseUrl)

private static void GivenIdentityServerSigningEnvironmentalVariablesAreSet()
{
Environment.SetEnvironmentVariable("OCELOT_CERTIFICATE", "idsrv3test.pfx");
Environment.SetEnvironmentVariable("OCELOT_CERTIFICATE_PASSWORD", "idsrv3test");
Environment.SetEnvironmentVariable("OCELOT_CERTIFICATE", "mycert.pfx");
Environment.SetEnvironmentVariable("OCELOT_CERTIFICATE_PASSWORD", "password");
}

private void WhenIGetUrlOnTheSecondOcelot(string url)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<CodeAnalysisRuleSet>..\..\codeanalysis.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<None Update="peers.json;appsettings.json;idsrv3test.pfx">
<None Update="peers.json;appsettings.json;mycert.pfx">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
Expand Down
Binary file removed test/Ocelot.IntegrationTests/idsrv3test.pfx
Binary file not shown.
Binary file added test/Ocelot.IntegrationTests/mycert.pfx
Binary file not shown.
2 changes: 1 addition & 1 deletion test/Ocelot.ManualTest/Ocelot.ManualTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
</None>
</ItemGroup>
<ItemGroup>
<None Update="ocelot.json;appsettings.json;idsrv3test.pfx">
<None Update="ocelot.json;appsettings.json;mycert.pfx">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
Expand Down
Binary file added test/Ocelot.ManualTest/mycert.pfx
Binary file not shown.
2 changes: 1 addition & 1 deletion test/Ocelot.UnitTests/Ocelot.UnitTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<None Update="appsettings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="idsrv3test.pfx">
<None Update="mycert.pfx">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
Expand Down
Binary file removed test/Ocelot.UnitTests/idsrv3test.pfx
Binary file not shown.
Binary file added test/Ocelot.UnitTests/mycert.pfx
Binary file not shown.