yavsc/test/yavscTests/Mandatory/Remoting.cs

85 lines
2.7 KiB
C#

7 years ago
// // YavscWorkInProgress.cs
// /*
// paul 21/06/2018 10:11 20182018 6 21
// */
using System.Net;
5 months ago
using isnd.tests;
7 years ago
using Xunit;
7 years ago
using Xunit.Abstractions;
using Yavsc.Authentication;
7 years ago
5 years ago
namespace yavscTests
7 years ago
{
[Collection("Yavsc Work In Progress")]
5 years ago
[Trait("regression", "oui")]
5 months ago
public class Remoting : BaseTestContext, IClassFixture<WebServerFixture>
7 years ago
{
5 months ago
public Remoting(WebServerFixture serverFixture, ITestOutputHelper output)
7 years ago
: base(output, serverFixture)
7 years ago
{
5 months ago
7 years ago
}
7 years ago
[Theory]
7 years ago
[MemberData(nameof(GetLoginIntentData), parameters: 1)]
public async Task TestUserMayLogin
(
5 months ago
string userName,
string password
)
{
7 years ago
try
{
var serverUrl = _serverFixture.Addresses.FirstOrDefault();
5 months ago
String auth = _serverFixture.SiteSettings.Authority;
var oauthor = new OAuthenticator(_serverFixture.TestClientId, _serverFixture.TestClientSecret,
"profile",
new Uri(serverUrl), new Uri(serverUrl), new Uri(serverUrl+"/connect/token"));
5 years ago
var query = new Dictionary<string, string>
{
5 months ago
["Username"] = userName,
["Password"] = password,
5 months ago
["GrantType"] = "Password"
5 years ago
};
7 years ago
var result = await oauthor.RequestAccessTokenAsync(query);
Console.WriteLine(">> Got an output");
5 months ago
Console.WriteLine( "AccessToken " + result["AccessToken"]);
Console.WriteLine("TokenType " + result["TokenType"]);
Console.WriteLine("ExpiresIn " + result["ExpiresIn"]);
Console.WriteLine("RefreshToken : " + result["RefreshToken"]);
7 years ago
7 years ago
}
catch (Exception ex)
{
var webex = ex as WebException;
if (webex != null && webex.Status == (WebExceptionStatus)400)
{
5 months ago
if (_serverFixture?.TestingSetup?.ValidCreds.UserName == "lame-user")
7 years ago
{
Console.WriteLine("Bad pass joe!");
return;
7 years ago
}
}
throw;
}
7 years ago
}
7 years ago
5 months ago
public static IEnumerable<object[]> GetLoginIntentData(int countFakes = 0)
5 months ago
{
5 months ago
if (countFakes == 0)
return new object[][] { new object[] { "testuser", "test" } };
var fakUsers = new List<String[]>();
for (int i = 0; i < countFakes; i++)
{
fakUsers.Add(new String[] { "fakeTester" + i, "pass" + i });
}
return fakUsers;
5 months ago
}
7 years ago
}
}