2025-07-30 15:52:01 +01:00
|
|
|
|
using isnd.tests;
|
2018-07-21 16:15:54 +02:00
|
|
|
|
using Xunit.Abstractions;
|
2025-07-30 15:52:01 +01:00
|
|
|
|
using IdentityModel.Client;
|
2026-03-09 02:07:09 +00:00
|
|
|
|
using System.Net;
|
|
|
|
|
|
using System.Security.Cryptography.X509Certificates;
|
|
|
|
|
|
using System.Net.Security;
|
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
|
|
|
|
{
|
2025-07-16 00:47:50 +01:00
|
|
|
|
[Collection("Yavsc Server")]
|
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
|
|
|
|
|
2025-07-30 15:52:01 +01:00
|
|
|
|
|
|
|
|
|
|
[Fact]
|
|
|
|
|
|
public async Task ObtainServiceToken()
|
2026-03-09 02:07:09 +00:00
|
|
|
|
{
|
|
|
|
|
|
var serverUrl = _serverFixture.Addresses.FirstOrDefault(
|
|
|
|
|
|
u => u.StartsWith("https:")
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
String authority = _serverFixture.SiteSettings.Authority;
|
|
|
|
|
|
HttpClient client = NewHttpClient();
|
|
|
|
|
|
var disco = await client.GetDiscoveryDocumentAsync(authority);
|
|
|
|
|
|
if (disco.IsError) throw new Exception(disco.Error);
|
|
|
|
|
|
|
|
|
|
|
|
var response = await client.RequestClientCredentialsTokenAsync(new ClientCredentialsTokenRequest
|
|
|
|
|
|
{
|
|
|
|
|
|
Address = disco.TokenEndpoint,
|
|
|
|
|
|
ClientId = _serverFixture.TestClientId,
|
|
|
|
|
|
ClientSecret = _serverFixture.TestClientSecret,
|
|
|
|
|
|
Scope = "test",
|
|
|
|
|
|
GrantType = "client_credentials"
|
|
|
|
|
|
});
|
|
|
|
|
|
/*"mvc";
|
|
|
|
|
|
options.ClientSecret = "49C1A7E1-0C79-4A89-A3D6-A37998FB86B0";*/
|
|
|
|
|
|
if (response.IsError) throw new Exception(response.Error);
|
2025-07-15 19:43:41 +01:00
|
|
|
|
|
2026-03-09 02:07:09 +00:00
|
|
|
|
}
|
2025-07-15 17:35:14 +01:00
|
|
|
|
|
2026-03-09 02:07:09 +00:00
|
|
|
|
private static HttpClient NewHttpClient()
|
|
|
|
|
|
{
|
|
|
|
|
|
return new HttpClient(new BypassSslValidationHandler());
|
|
|
|
|
|
}
|
2025-07-16 00:47:50 +01:00
|
|
|
|
|
2026-03-09 02:07:09 +00:00
|
|
|
|
[Fact]
|
2025-07-30 15:52:01 +01:00
|
|
|
|
public async Task ObtainResourceOwnerPasswordToken()
|
|
|
|
|
|
{
|
|
|
|
|
|
var serverUrl = _serverFixture.Addresses.FirstOrDefault(
|
|
|
|
|
|
u => u.StartsWith("https:")
|
|
|
|
|
|
);
|
2021-01-02 00:41:54 +00:00
|
|
|
|
|
2025-07-30 15:52:01 +01:00
|
|
|
|
String authority = _serverFixture.SiteSettings.Authority;
|
2026-03-09 02:07:09 +00:00
|
|
|
|
var client = NewHttpClient();
|
2025-07-30 15:52:01 +01:00
|
|
|
|
var disco = await client.GetDiscoveryDocumentAsync(authority);
|
|
|
|
|
|
if (disco.IsError) throw new Exception(disco.Error);
|
2018-07-15 00:29:06 +02:00
|
|
|
|
|
2025-07-30 15:52:01 +01:00
|
|
|
|
var response = await client.RequestPasswordTokenAsync(new PasswordTokenRequest
|
|
|
|
|
|
{
|
|
|
|
|
|
Address = disco.TokenEndpoint,
|
|
|
|
|
|
|
2026-03-09 02:07:09 +00:00
|
|
|
|
ClientId = _serverFixture.TestClientId,
|
|
|
|
|
|
ClientSecret = _serverFixture.TestClientSecret,
|
2025-07-30 15:52:01 +01:00
|
|
|
|
|
|
|
|
|
|
UserName = _serverFixture.TestingUserName,
|
|
|
|
|
|
Password = _serverFixture.TestingUserPassword,
|
|
|
|
|
|
|
2026-03-09 02:07:09 +00:00
|
|
|
|
Scope = "test",
|
2025-07-30 15:52:01 +01:00
|
|
|
|
|
|
|
|
|
|
Parameters =
|
2018-08-02 12:28:13 +02:00
|
|
|
|
{
|
2025-07-30 15:52:01 +01:00
|
|
|
|
{ "acr_values", "tenant:custom_account_store1 foo bar quux" }
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
if (response.IsError) throw new Exception(response.Error);
|
|
|
|
|
|
|
2018-07-15 00:29:06 +02:00
|
|
|
|
}
|
2018-08-02 12:28:13 +02:00
|
|
|
|
|
2025-07-16 00:47:50 +01:00
|
|
|
|
public static IEnumerable<object[]> GetLoginIntentData()
|
2025-07-13 18:13:04 +01:00
|
|
|
|
{
|
2025-07-16 00:47:50 +01:00
|
|
|
|
return new object[][] { new object[] { "testuser", "test" } };
|
2025-07-13 18:13:04 +01:00
|
|
|
|
}
|
2025-07-30 15:52:01 +01:00
|
|
|
|
|
2018-07-15 00:29:06 +02:00
|
|
|
|
}
|
2026-03-09 02:07:09 +00:00
|
|
|
|
|
|
|
|
|
|
internal class BypassSslValidationHandler : HttpClientHandler
|
|
|
|
|
|
{
|
|
|
|
|
|
public BypassSslValidationHandler()
|
|
|
|
|
|
{
|
|
|
|
|
|
// Override validation for this handler only
|
|
|
|
|
|
ServerCertificateCustomValidationCallback = ValidateCertificate;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private bool ValidateCertificate(
|
|
|
|
|
|
HttpRequestMessage request,
|
|
|
|
|
|
X509Certificate2 certificate,
|
|
|
|
|
|
X509Chain chain,
|
|
|
|
|
|
SslPolicyErrors errors)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Accept all certificates (bypass validation)
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2018-07-15 00:29:06 +02:00
|
|
|
|
}
|