Files
yavsc/test/yavscTests/Mandatory/Remoting.cs
Paul Schneider a9b809f5e5
Some checks failed
Dotnet build and test / log-the-inputs (push) Failing after 1s
Dotnet build and test / build (push) Failing after 1s
Refactoring
The main server owns the migrations, it's the server part,
it's simpler.

It's Yavsc, not one of its lib.
2025-07-15 20:17:39 +01:00

85 lines
2.7 KiB
C#

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