Skip to content

Commit 312f1c6

Browse files
authored
tests passing on debian 10 (#1647)
* tests passing on debian 10 * how to generate test cert * updated build image to include git * updated build image to include openssh-client
1 parent 07263be commit 312f1c6

23 files changed

+87
-36
lines changed

.circleci/config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ orbs:
44
jobs:
55
build:
66
docker:
7-
- image: mijitt0m/ocelot-build:0.0.7
7+
- image: mijitt0m/ocelot-build:0.0.9
88
steps:
99
- checkout
1010
- run: dotnet tool restore && dotnet cake
1111
release:
1212
docker:
13-
- image: mijitt0m/ocelot-build:0.0.7
13+
- image: mijitt0m/ocelot-build:0.0.9
1414
steps:
1515
- checkout
1616
- run: dotnet tool restore && dotnet cake --target=Release

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ ClientBin/
183183
*.dbmdl
184184
*.dbproj.schemaview
185185
*.pfx
186-
!idsrv3test.pfx
186+
!mycert.pfx
187187
*.publishsettings
188188
node_modules/
189189
orleans.codegen.cs

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ A quick list of Ocelot's capabilities for more information see the [documentatio
4343

4444
## How to install
4545

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

4848
Install Ocelot and it's dependencies using NuGet.
4949

docker/Dockerfile.base

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM mcr.microsoft.com/dotnet/sdk:7.0-alpine
22

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

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

docker/Dockerfile.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# call from ocelot repo root with
22
# docker build --platform linux/arm64 --build-arg OCELOT_COVERALLS_TOKEN=$OCELOT_COVERALLS_TOKEN -f ./docker/Dockerfile.build .
33
# docker build --platform linux/amd64 --build-arg OCELOT_COVERALLS_TOKEN=$OCELOT_COVERALLS_TOKEN -f ./docker/Dockerfile.build .
4-
FROM mijitt0m/ocelot-build:0.0.7
4+
FROM mijitt0m/ocelot-build:0.0.9
55

66
ARG OCELOT_COVERALLS_TOKEN
77

docker/Dockerfile.release

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# call from ocelot repo root with
22
# 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 .
33
# 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 .
4-
FROM mijitt0m/ocelot-build:0.0.7
4+
FROM mijitt0m/ocelot-build:0.0.9
55

66
ARG OCELOT_COVERALLS_TOKEN
77
ARG OCELOT_NUTGET_API_KEY

docker/build.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# this script build the ocelot docker file
2-
version=0.0.7
2+
version=0.0.9
33
docker build --platform linux/amd64 -t mijitt0m/ocelot-build -f Dockerfile.base .
44
echo $DOCKER_PASS | docker login -u $DOCKER_USER --password-stdin
55
docker tag mijitt0m/ocelot-build mijitt0m/ocelot-build:$version

docs/building/tests.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,15 @@ Tests
44
The tests should all just run and work as part of the build process. You can of course also run them in visual studio.
55

66

7+
Create SSL Cert for Testing
8+
^^^^^^^^^^^^^^^^^^^^^^^^^^^
79

10+
You can do this via openssl:
11+
12+
Install openssl package (if you are using Windows, download binaries here).
13+
14+
Generate private key: `openssl genrsa 2048 > private.pem`
15+
16+
Generate the self signed certificate: `openssl req -x509 -days 1000 -new -key private.pem -out public.pem`
17+
18+
If needed, create PFX: `openssl pkcs12 -export -in public.pem -inkey private.pem -out mycert.pfx`

src/Ocelot/Requester/HttpClientBuilder.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ public IHttpClient Create(DownstreamRoute downstreamRoute)
4949

5050
if (downstreamRoute.DangerousAcceptAnyServerCertificateValidator)
5151
{
52-
handler.ServerCertificateCustomValidationCallback = (request, certificate, chain, errors) => true;
52+
handler.ServerCertificateCustomValidationCallback =
53+
HttpClientHandler.DangerousAcceptAnyServerCertificateValidator;
5354

5455
_logger
5556
.LogWarning($"You have ignored all SSL warnings by using DangerousAcceptAnyServerCertificateValidator for this DownstreamRoute, UpstreamPathTemplate: {downstreamRoute.UpstreamPathTemplate}, DownstreamPathTemplate: {downstreamRoute.DownstreamPathTemplate}");

test/Ocelot.AcceptanceTests/HttpTests.cs

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ namespace Ocelot.AcceptanceTests
55
using System.IO;
66
using System.Net;
77
using System.Net.Http;
8-
8+
99
using Configuration.File;
10-
10+
1111
using Microsoft.AspNetCore.Http;
1212
using Microsoft.AspNetCore.Server.Kestrel.Core;
13-
13+
1414
using TestStack.BDDfy;
15-
15+
1616
using Xunit;
1717

1818
public class HttpTests : IDisposable
@@ -38,7 +38,7 @@ public void should_return_response_200_when_using_http_one()
3838
new()
3939
{
4040
DownstreamPathTemplate = "/{url}",
41-
DownstreamScheme = "https",
41+
DownstreamScheme = "http",
4242
UpstreamPathTemplate = "/{url}",
4343
UpstreamHttpMethod = new List<string> { "Get" },
4444
DownstreamHostAndPorts = new List<FileHostAndPort>
@@ -51,7 +51,6 @@ public void should_return_response_200_when_using_http_one()
5151
},
5252
DownstreamHttpMethod = "POST",
5353
DownstreamHttpVersion = "1.0",
54-
DangerousAcceptAnyServerCertificateValidator = true
5554
},
5655
},
5756
};
@@ -76,7 +75,7 @@ public void should_return_response_200_when_using_http_one_point_one()
7675
new()
7776
{
7877
DownstreamPathTemplate = "/{url}",
79-
DownstreamScheme = "https",
78+
DownstreamScheme = "http",
8079
UpstreamPathTemplate = "/{url}",
8180
UpstreamHttpMethod = new List<string> { "Get" },
8281
DownstreamHostAndPorts = new List<FileHostAndPort>
@@ -89,7 +88,6 @@ public void should_return_response_200_when_using_http_one_point_one()
8988
},
9089
DownstreamHttpMethod = "POST",
9190
DownstreamHttpVersion = "1.1",
92-
DangerousAcceptAnyServerCertificateValidator = true
9391
},
9492
},
9593
};
@@ -135,7 +133,7 @@ public void should_return_response_200_when_using_http_two_point_zero()
135133
const string expected = "here is some content";
136134
var httpContent = new StringContent(expected);
137135

138-
this.Given(x => x.GivenThereIsAServiceRunningOn($"http://localhost:{port}/", "/", port, HttpProtocols.Http2))
136+
this.Given(x => x.GivenThereIsAServiceUsingHttpsRunningOn($"http://localhost:{port}/", "/", port, HttpProtocols.Http2))
139137
.And(x => _steps.GivenThereIsAConfiguration(configuration))
140138
.And(x => _steps.GivenOcelotIsRunning())
141139
.When(x => _steps.WhenIGetUrlOnTheApiGateway("/", httpContent))
@@ -185,6 +183,7 @@ public void should_return_response_502_when_using_http_one_to_talk_to_server_run
185183
.BDDfy();
186184
}
187185

186+
//TODO: does this test make any sense?
188187
[Fact]
189188
public void should_return_response_200_when_using_http_two_to_talk_to_server_running_http_one_point_one()
190189
{
@@ -197,7 +196,7 @@ public void should_return_response_200_when_using_http_two_to_talk_to_server_run
197196
new()
198197
{
199198
DownstreamPathTemplate = "/{url}",
200-
DownstreamScheme = "https",
199+
DownstreamScheme = "http",
201200
UpstreamPathTemplate = "/{url}",
202201
UpstreamHttpMethod = new List<string> { "Get" },
203202
DownstreamHostAndPorts = new List<FileHostAndPort>
@@ -209,7 +208,7 @@ public void should_return_response_200_when_using_http_two_to_talk_to_server_run
209208
},
210209
},
211210
DownstreamHttpMethod = "POST",
212-
DownstreamHttpVersion = "2.0",
211+
DownstreamHttpVersion = "1.1",
213212
DangerousAcceptAnyServerCertificateValidator = true
214213
},
215214
},
@@ -238,6 +237,17 @@ private void GivenThereIsAServiceRunningOn(string baseUrl, string basePath, int
238237
}, port, protocols);
239238
}
240239

240+
private void GivenThereIsAServiceUsingHttpsRunningOn(string baseUrl, string basePath, int port, HttpProtocols protocols)
241+
{
242+
_serviceHandler.GivenThereIsAServiceRunningOnUsingHttps(baseUrl, basePath, async context =>
243+
{
244+
context.Response.StatusCode = 200;
245+
var reader = new StreamReader(context.Request.Body);
246+
var body = await reader.ReadToEndAsync();
247+
await context.Response.WriteAsync(body);
248+
}, port, protocols);
249+
}
250+
241251
public void Dispose()
242252
{
243253
_serviceHandler.Dispose();

0 commit comments

Comments
 (0)