Skip to content
Draft

Proxy #202

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
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,6 @@ ClientBin/
*.dbmdl
*.dbproj.schemaview
*.jfm
*.pfx
*.publishsettings
orleans.codegen.cs

Expand Down Expand Up @@ -321,5 +320,5 @@ ASALocalRun/
*.binlog

# NVidia Nsight GPU debugger configuration file
*.nvuser
.DS_Store
*.nvuser
.DS_Store
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" PrivateAssets="All" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<PackageReference Include="NUnit3TestAdapter" Version="3.10.0" />
<PackageReference Include="Shouldly" Version="3.0.1" />
<PackageReference Include="System.Runtime.InteropServices.RuntimeInformation" Version="4.3.0" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OpenRasta.DI.Windsor\OpenRasta.DI.Windsor.csproj" />
Expand Down
1 change: 1 addition & 0 deletions src/OpenRasta.DI.Windsor/OpenRasta.DI.Windsor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Castle.Windsor" Version="4.1.1" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OpenRasta\OpenRasta.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<PackageReference Include="NUnit" Version="3.10.1" />
<PackageReference Include="NUnit3TestAdapter" Version="3.10.0" />
<PackageReference Include="Shouldly" Version="3.0.1" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" PrivateAssets="All" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\OpenRasta\OpenRasta.csproj" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<Reference Include="System.Configuration" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Owin" Version="2.1.1" />
<PackageReference Include="Microsoft.AspNetCore.Hosting.Abstractions" Version="2.1.1" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OpenRasta\OpenRasta.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Owin" Version="1.0.0" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\OpenRasta\OpenRasta.csproj" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\OpenRasta\OpenRasta.csproj" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" PrivateAssets="All" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<ItemGroup>
<ProjectReference Include="..\OpenRasta.Codecs.Newtonsoft.Json\OpenRasta.Codecs.Newtonsoft.Json.csproj" />
<ProjectReference Include="..\OpenRasta\OpenRasta.csproj" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" PrivateAssets="All" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net461'">
<Reference Include="System.Net.Http" />
Expand Down
1 change: 1 addition & 0 deletions src/OpenRasta.Tests.Unit/OpenRasta.Tests.Unit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
<PackageReference Include="NUnit" Version="3.10.1" />
<PackageReference Include="NUnit3TestAdapter" Version="3.10.0" />
<PackageReference Include="Shouldly" Version="3.0.1" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" PrivateAssets="All" />
</ItemGroup>
</Project>
1 change: 1 addition & 0 deletions src/OpenRasta/OpenRasta.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" PrivateAssets="All" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="System.CodeDom" Version="4.5.0" />
Expand Down
69 changes: 69 additions & 0 deletions src/Tests/Plugins.ReverseProxy/get_with_danger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using System;
using System.IO;
using System.Net;
using System.Net.Http;
using System.Security.Cryptography.X509Certificates;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Shouldly;
using Tests.Plugins.ReverseProxy.Implementation;
using Xunit;

namespace Tests.Plugins.ReverseProxy
{
public class get_with_danger : IDisposable
{
readonly HttpClient client;
readonly IWebHost webHost;

public get_with_danger()
{
this.webHost = new WebHostBuilder()
.Configure(builder => builder.Run(ctx => ctx.Response.WriteAsync("Danger!")))
.UseKestrel(options =>
{
options.Listen(IPAddress.Any,
5050,
listenOptions =>
{
var certificate = new X509Certificate2(Path.Combine(Directory.GetCurrentDirectory(), "Plugins.ReverseProxy", "testCert.pfx"), "testPassword");
listenOptions.UseHttps(certificate);
});
}).Build();

this.webHost.Start();

this.client = new HttpClient(new HttpClientHandler { ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator });
}

[Fact]
public async Task test_name()
{
var response = await this.client.GetAsync("https://localhost:5050/");
var content = await response.Content.ReadAsStringAsync();
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
Assert.Equal("Danger!", content);
}

[Fact]
public async Task test_name2()
{
using (var response = await new ProxyServer()
.FromServer(port => $"http://127.0.0.1:{port}/proxy")
.ToServer(port => "https://google.com")
.UseKestrel()
.GetAsync("/"))
{
response.Message.StatusCode.ShouldBe(HttpStatusCode.BadGateway);
}
}

public void Dispose()
{
this.client?.Dispose();
this.webHost?.Dispose();
}
}
}
Binary file added src/Tests/Plugins.ReverseProxy/testCert.pfx
Binary file not shown.
3 changes: 3 additions & 0 deletions src/Tests/Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,7 @@
<ItemGroup>
<Folder Include="Plugins.Caching\attributes\client" />
</ItemGroup>
<ItemGroup>
<Content Include="Plugins.ReverseProxy\testCert.pfx" CopyToOutputDirectory="Always" CopyToPublishDirectory="Always" />
</ItemGroup>
</Project>