Skip to content
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
33 changes: 33 additions & 0 deletions tests/WebServerE2ETests/PostPutController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Net;
using nanoFramework.WebServer;

namespace WebServerE2ETests
{
class PostPutController
{
[Method("POST")]
[Route("post")]
public void Post(WebServerEventArgs e)
{
byte[] buff = new byte[e.Context.Request.InputStream.Length];
e.Context.Request.InputStream.Read(buff, 0, buff.Length);
var txt = e.Context.Request.ContentType.Contains("text") ? System.Text.Encoding.UTF8.GetString(buff, 0, buff.Length) : BitConverter.ToString(buff);
WebServer.OutPutStream(e.Context.Response, $"POST: {txt}");
}

[Method("PUT")]
[Route("put")]
public void Put(WebServerEventArgs e)
{
byte[] buff = new byte[e.Context.Request.InputStream.Length];
e.Context.Request.InputStream.Read(buff, 0, buff.Length);
var txt = e.Context.Request.ContentType.Contains("text") ? System.Text.Encoding.UTF8.GetString(buff, 0, buff.Length) : BitConverter.ToString(buff);
WebServer.OutPutStream(e.Context.Response, $"PUT: {txt}");
}

}
}
2 changes: 1 addition & 1 deletion tests/WebServerE2ETests/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static void Main()
}

Debug.WriteLine($"Connected with wifi credentials. IP Address: {GetCurrentIPAddress()}");
_server = new WebServer(80, HttpProtocol.Http, new Type[] { typeof(SimpleRouteController), typeof(AuthController), typeof(MixedController) });
_server = new WebServer(80, HttpProtocol.Http, new Type[] { typeof(SimpleRouteController), typeof(AuthController), typeof(MixedController), typeof(PostPutController) });
// To test authentication with various scenarios
_server.ApiKey = "ATopSecretAPIKey1234";
_server.Credential = new NetworkCredential("topuser", "topPassword");
Expand Down
1 change: 1 addition & 0 deletions tests/WebServerE2ETests/WebServerE2ETests.nfproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<ItemGroup>
<Compile Include="MixedController.cs" />
<Compile Include="AuthController.cs" />
<Compile Include="PostPutController.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SimpleRouteController.cs" />
Expand Down
65 changes: 65 additions & 0 deletions tests/WebServerE2ETests/requests.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# This file is a collection of requests that can be executed with the REST Client extension for Visual Studio Code
# https://marketplace.visualstudio.com/items?itemName=humao.rest-client
# adjust your host here
@host=192.168.1.86:80

###

POST http://{{host}}/post?someparams=1&others=2 HTTP/1.1
Content-Type: text/plain

This is a test with post

###

PUT http://{{host}}/put HTTP/1.1
Content-Type: text/plain

This is another test with put

###

GET http://{{host}}/get?someparams=1&others=2 HTTP/1.1

###

# This request will fail with 401 Unauthorized
GET http://{{host}}/authbasic HTTP/1.1

###

# this one will succeed
GET http://topuser:topPassword@{{host}}/authbasic HTTP/1.1

###

# This request will fail with 401 Unauthorized
GET http://{{host}}/authapi HTTP/1.1

###

# this one will succeed
GET http://{{host}}/authapi HTTP/1.1
ApiKey: superKey1234

###

# This request will fail with 401 Unauthorized
GET http://{{host}}/authdefaultapi HTTP/1.1

###

# this one will succeed
GET http://{{host}}/authdefaultapi HTTP/1.1
ApiKey: ATopSecretAPIKey1234


###

# this one will succeed with the public route
GET http://{{host}}/authapikeybasicandpublic HTTP/1.1

###

# this one will succeed with user 3
GET http://user3:password@{{host}}/authapikeybasicandpublic HTTP/1.1