mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-07-12 16:43:01 +01:00
Regression test for #2423
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.Headers;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using System;
|
||||
using System;
|
||||
using System.Net.Http.Headers;
|
||||
using System.Net.Mime;
|
||||
using System.Text;
|
||||
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Http.Headers;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
|
||||
using Tgstation.Server.Api.Models;
|
||||
using Tgstation.Server.Api.Models.Response;
|
||||
@@ -16,7 +18,7 @@ namespace Tgstation.Server.Api.Tests
|
||||
[TestClass]
|
||||
public sealed class TestApiHeaders
|
||||
{
|
||||
readonly ProductHeaderValue productHeaderValue = new ("Tgstation.Server.Api.Tests", "1.0.0");
|
||||
readonly ProductHeaderValue productHeaderValue = new("Tgstation.Server.Api.Tests", "1.0.0");
|
||||
|
||||
[TestMethod]
|
||||
public void TestConstruction()
|
||||
@@ -44,7 +46,8 @@ namespace Tgstation.Server.Api.Tests
|
||||
};
|
||||
|
||||
return new ApiHeaders(new RequestHeaders(headers), false, false);
|
||||
};
|
||||
}
|
||||
;
|
||||
|
||||
var header = TestHeader(BrowserHeader);
|
||||
Assert.AreEqual(BrowserHeader, header.RawUserAgent);
|
||||
@@ -56,5 +59,28 @@ namespace Tgstation.Server.Api.Tests
|
||||
|
||||
Assert.ThrowsExactly<HeadersException>(() => TestHeader(String.Empty));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestBasicAuthenticationDeserialization()
|
||||
{
|
||||
const string BrowserHeader = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36.";
|
||||
const string Password = "askdjf::SDokjdf**";
|
||||
const string Username = "deeznuts";
|
||||
|
||||
var authHeader = $"Basic {Convert.ToBase64String(Encoding.UTF8.GetBytes($"{Username}:{Password}"))}";
|
||||
var headers = new HeaderDictionary
|
||||
{
|
||||
{ "Accept", MediaTypeNames.Application.Json },
|
||||
{ "Api", "Tgstation.Server.Api/4.0.0.0" },
|
||||
{ "Authorization", authHeader },
|
||||
{ "User-Agent", BrowserHeader },
|
||||
};
|
||||
|
||||
var header = new ApiHeaders(new RequestHeaders(headers), false, false);
|
||||
|
||||
Assert.AreEqual(BrowserHeader, header.RawUserAgent);
|
||||
Assert.AreEqual(Username, header.Username);
|
||||
Assert.AreEqual(Password, header.Password);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user