yavsc/test/yavscTests/Mandatory/Remoting.cs

84 lines
2.7 KiB
C#
Raw Normal View History

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