138 lines
4.5 KiB
C#
138 lines
4.5 KiB
C#
using System;
|
|
using Xunit;
|
|
using Newtonsoft.Json.Linq;
|
|
using FluentAssertions;
|
|
|
|
namespace raven_integration
|
|
{
|
|
|
|
public class Auth
|
|
{
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
[Fact]
|
|
public async void BadLoginShouldNotWork()
|
|
{
|
|
//Expect status code 401 and result:
|
|
// {{
|
|
// "error": {
|
|
// "code": "2003",
|
|
// "message": "Authentication failed"
|
|
// }
|
|
// }}
|
|
|
|
dynamic d = new JObject();
|
|
d.login = "BOGUS";
|
|
d.password = "ACCOUNT";
|
|
ApiResponse a = await Util.PostAsync("Auth", null, d.ToString());
|
|
Util.ValidateErrorCodeResponse(a, 2003, 401);
|
|
}
|
|
|
|
|
|
|
|
//NOTE: These tests are for Debug builds, they should still pass in a release build because none of the creds will work and it checks for 401 only
|
|
//but a true test of these JWT tokens is only in server debug mode
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
[Fact]
|
|
public async void JWTExpiredTokenShouldFail()
|
|
{
|
|
|
|
ApiResponse a = await Util.GetAsync("BuildMode");
|
|
var BuildMode = a.ObjectResponse["data"]["buildMode"].Value<string>();
|
|
if (BuildMode == "DEBUG")
|
|
{
|
|
a = await Util.GetAsync("Translation/picklist", await Util.GetTokenAsync("INTEGRATION_TEST", "EXPIRED"));//lowest level test user because there are no limits on this route except to be authenticated
|
|
Util.ValidateHTTPStatusCode(a, 401);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
[Fact]
|
|
public async void JWTWrongIssuerShouldFail()
|
|
{
|
|
ApiResponse a = await Util.GetAsync("BuildMode");
|
|
var BuildMode = a.ObjectResponse["data"]["buildMode"].Value<string>();
|
|
if (BuildMode == "DEBUG")
|
|
{
|
|
a = await Util.GetAsync("Translation/picklist", await Util.GetTokenAsync("INTEGRATION_TEST", "WRONG_ISSUER"));//lowest level test user because there are no limits on this route except to be authenticated
|
|
Util.ValidateHTTPStatusCode(a, 401);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
[Fact]
|
|
public async void JWTNoAlgorithmShouldFail()
|
|
{
|
|
ApiResponse a = await Util.GetAsync("BuildMode");
|
|
var BuildMode = a.ObjectResponse["data"]["buildMode"].Value<string>();
|
|
if (BuildMode == "DEBUG")
|
|
{
|
|
a = await Util.GetAsync("Translation/picklist", await Util.GetTokenAsync("INTEGRATION_TEST", "NO_ALGORITHM"));
|
|
Util.ValidateHTTPStatusCode(a, 401);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
[Fact]
|
|
public async void JWTBadSecretShouldFail()
|
|
{
|
|
ApiResponse a = await Util.GetAsync("BuildMode");
|
|
var BuildMode = a.ObjectResponse["data"]["buildMode"].Value<string>();
|
|
if (BuildMode == "DEBUG")
|
|
{
|
|
a = await Util.GetAsync("Translation/picklist", await Util.GetTokenAsync("INTEGRATION_TEST", "WRONG_SECRET"));
|
|
Util.ValidateHTTPStatusCode(a, 401);
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
[Fact]
|
|
public async void JWTTruncatedSignatureShouldFail()
|
|
{
|
|
ApiResponse a = await Util.GetAsync("BuildMode");
|
|
var BuildMode = a.ObjectResponse["data"]["buildMode"].Value<string>();
|
|
if (BuildMode == "DEBUG")
|
|
{
|
|
a = await Util.GetAsync("Translation/picklist", await Util.GetTokenAsync("INTEGRATION_TEST", "TRUNCATED_SIGNATURE"));
|
|
Util.ValidateHTTPStatusCode(a, 401);
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
[Fact]
|
|
public async void JWTTransposedSignatureShouldFail()
|
|
{
|
|
ApiResponse a = await Util.GetAsync("BuildMode");
|
|
var BuildMode = a.ObjectResponse["data"]["buildMode"].Value<string>();
|
|
if (BuildMode == "DEBUG")
|
|
{
|
|
a = await Util.GetAsync("Translation/picklist", await Util.GetTokenAsync("INTEGRATION_TEST", "TRANSPOSE_SIGNATURE"));
|
|
Util.ValidateHTTPStatusCode(a, 401);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
//==================================================
|
|
|
|
}//eoc
|
|
}//eons
|
|
|