Add test for issue #826

This commit is contained in:
Jordan Brown
2019-01-11 15:04:20 -05:00
parent d6bdc400b3
commit d1a45281d7
2 changed files with 30 additions and 1 deletions
@@ -1,4 +1,6 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Headers;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Net.Http.Headers;
@@ -19,5 +21,31 @@ namespace Tgstation.Server.Api.Tests
Assert.ThrowsException<ArgumentNullException>(() => new ApiHeaders(productHeaderValue, null));
var headers = new ApiHeaders(productHeaderValue, String.Empty);
}
[TestMethod]
public void TestUserAgentsAreValid()
{
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 ConformantHeader = "TGSClient/3.2.1.4";
ApiHeaders TestHeader(string userAgent)
{
var headers = new HeaderDictionary();
headers.Add("Accept", ApiHeaders.ApplicationJson);
headers.Add("Api", "Tgstation.Server.Api/4.0.0.0");
headers.Add("Authorization", "Bearer asdfasdf");
headers.Add("User-Agent", userAgent);
return new ApiHeaders(new RequestHeaders(headers));
};
var header = TestHeader(BrowserHeader);
Assert.AreEqual(BrowserHeader, header.RawUserAgent);
Assert.IsNull(header.UserAgent);
header = TestHeader(ConformantHeader);
Assert.AreEqual(ConformantHeader, header.RawUserAgent);
Assert.IsNotNull(header.UserAgent);
}
}
}
@@ -9,6 +9,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="MSTest.TestAdapter" Version="1.3.2" />
<PackageReference Include="MSTest.TestFramework" Version="1.3.2" />