Skip to content

Commit 235fac5

Browse files
committed
Adding Proxy E2E tests
1 parent 866f12b commit 235fac5

File tree

3 files changed

+149
-0
lines changed

3 files changed

+149
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
{
2+
"proxies": {
3+
"FileExtensionCheck": {
4+
"matchCondition": {
5+
"methods": [
6+
"GET"
7+
],
8+
"route": "test.txt"
9+
},
10+
"responseOverrides": {
11+
"response.statusCode": "200",
12+
"response.headers.Content-Type": "text/plain",
13+
"response.body": "test"
14+
}
15+
},
16+
"RootCheck": {
17+
"matchCondition": {
18+
"methods": [
19+
"GET"
20+
],
21+
"route": "/"
22+
},
23+
"responseOverrides": {
24+
"response.headers.Content-Type": "text/plain",
25+
"response.body": "Root"
26+
}
27+
28+
},
29+
"LocalFunctionCall": {
30+
"matchCondition": {
31+
"methods": [
32+
"GET"
33+
],
34+
"route": "/myhttptrigger"
35+
},
36+
"backendUri": "https://localhost/api/Ping"
37+
},
38+
"LongRoute": {
39+
"matchCondition": {
40+
"route": "/test123412341234123412341234123412341234123412341234123412341234123412341234123421341234123423141234123412341234123412341234123412341234123412341234123412341234123412341234123412341234213423141234123412341234123412341234123412341234123412341234123412341234123412341234123412341234"
41+
},
42+
"responseOverrides": {
43+
"response.statusCode": "200"
44+
}
45+
}
46+
}
47+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the MIT License. See License.txt in the project root for license information.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Globalization;
7+
using System.Net.Http;
8+
using System.Net.Http.Headers;
9+
using System.Text;
10+
using System.Threading.Tasks;
11+
using Microsoft.ApplicationInsights;
12+
using Microsoft.ApplicationInsights.DataContracts;
13+
using Microsoft.ServiceBus;
14+
using Microsoft.ServiceBus.Messaging;
15+
using Newtonsoft.Json.Linq;
16+
using Xunit;
17+
18+
namespace WebJobs.Script.EndToEndTests
19+
{
20+
[Collection(Constants.FunctionAppCollectionName)]
21+
public class ProxyEndToEndTests
22+
{
23+
private readonly FunctionAppFixture _fixture;
24+
25+
public ProxyEndToEndTests(FunctionAppFixture fixture)
26+
{
27+
_fixture = fixture;
28+
}
29+
30+
[Fact]
31+
[TestTrace]
32+
public async Task FileExtension()
33+
{
34+
using (var client = CreateClient())
35+
{
36+
HttpResponseMessage response = await client.GetAsync($"test.txt");
37+
38+
string content = await response.Content.ReadAsStringAsync();
39+
_fixture.Assert.Equals("200", response.StatusCode.ToString("D"));
40+
_fixture.Assert.Equals("test", content);
41+
}
42+
}
43+
44+
[Fact]
45+
[TestTrace]
46+
public async Task RootCheck()
47+
{
48+
using (var client = CreateClient())
49+
{
50+
HttpResponseMessage response = await client.GetAsync("/");
51+
52+
string content = await response.Content.ReadAsStringAsync();
53+
_fixture.Assert.Equals("200", response.StatusCode.ToString("D"));
54+
_fixture.Assert.Equals("Root", content);
55+
}
56+
}
57+
58+
[Fact]
59+
[TestTrace]
60+
public async Task LocalFunctionCall()
61+
{
62+
using (var client = CreateClient())
63+
{
64+
HttpResponseMessage response = await client.GetAsync($"myhttptrigger?code={_fixture.FunctionDefaultKey}");
65+
66+
string content = await response.Content.ReadAsStringAsync();
67+
_fixture.Assert.Equals("200", response.StatusCode.ToString("D"));
68+
_fixture.Assert.Equals("Pong", content);
69+
}
70+
}
71+
72+
[Fact]
73+
[TestTrace]
74+
public async Task LongRoute()
75+
{
76+
var longRoute = "test123412341234123412341234123412341234123412341234123412341234123412341234123421341234123423141234123412341234123412341234123412341234123412341234123412341234123412341234123412341234213423141234123412341234123412341234123412341234123412341234123412341234123412341234123412341234";
77+
using (var client = CreateClient())
78+
{
79+
HttpResponseMessage response = await client.GetAsync(longRoute);
80+
81+
string content = await response.Content.ReadAsStringAsync();
82+
83+
// This is to make sure the url is greater than the default asp.net 260 characters.
84+
_fixture.Assert.True(longRoute.Length > 260);
85+
_fixture.Assert.Equals("200", response.StatusCode.ToString("D"));
86+
}
87+
}
88+
89+
public HttpClient CreateClient()
90+
{
91+
return new HttpClient
92+
{
93+
Timeout = TimeSpan.FromSeconds(60),
94+
BaseAddress = Settings.SiteBaseAddress
95+
};
96+
}
97+
}
98+
}

test/WebJobs.Script.Tests.E2E/WebJobs.Script.Tests.E2E.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,13 +99,17 @@
9999
<Compile Include="GeneralEndToEndTests.cs" />
100100
<Compile Include="KuduClient.cs" />
101101
<Compile Include="Properties\AssemblyInfo.cs" />
102+
<Compile Include="ProxyEndToEndTests.cs" />
102103
<Compile Include="Settings.cs" />
103104
<Compile Include="TelemetryContext.cs" />
104105
<Compile Include="TraceAttribute.cs" />
105106
<Compile Include="TrackedAssert.cs" />
106107
</ItemGroup>
107108
<ItemGroup>
108109
<None Include="app.config" />
110+
<None Include="Functions\wwwroot\proxies.json">
111+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
112+
</None>
109113
<None Include="Functions\wwwroot\ServiceBusNode\function.json">
110114
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
111115
</None>

0 commit comments

Comments
 (0)