yavsc/test/yavscTests/Mandatory/Remoting.cs

94 lines
2.8 KiB
C#

4 months ago
using isnd.tests;
7 years ago
using Xunit.Abstractions;
4 months ago
using IdentityModel.Client;
7 years ago
5 years ago
namespace yavscTests
7 years ago
{
5 months ago
[Collection("Yavsc Server")]
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]
5 months ago
[MemberData(nameof(GetLoginIntentData))]
public async Task TestUserMayLogin
(
5 months ago
string userName,
string password
)
{
4 months ago
}
[Fact]
public async Task ObtainServiceToken()
{
var serverUrl = _serverFixture.Addresses.FirstOrDefault(
u => u.StartsWith("https:")
);
String authority = _serverFixture.SiteSettings.Authority;
var client = new HttpClient();
var disco = await client.GetDiscoveryDocumentAsync(authority);
if (disco.IsError) throw new Exception(disco.Error);
var response = await client.RequestClientCredentialsTokenAsync(new ClientCredentialsTokenRequest
7 years ago
{
4 months ago
Address = disco.TokenEndpoint,
4 months ago
ClientId = "m2m.client", // _serverFixture.TestClientId,
ClientSecret = "511536EF-F270-4058-80CA-1C89C192F69A" //_serverFixture.TestClientSecret,
});
/*"mvc";
options.ClientSecret = "49C1A7E1-0C79-4A89-A3D6-A37998FB86B0";*/
if (response.IsError) throw new Exception(response.Error);
5 months ago
4 months ago
}
5 months ago
4 months ago
[Fact]
public async Task ObtainResourceOwnerPasswordToken()
{
var serverUrl = _serverFixture.Addresses.FirstOrDefault(
u => u.StartsWith("https:")
);
5 years ago
4 months ago
String authority = _serverFixture.SiteSettings.Authority;
var client = new HttpClient();
var disco = await client.GetDiscoveryDocumentAsync(authority);
if (disco.IsError) throw new Exception(disco.Error);
7 years ago
4 months ago
var response = await client.RequestPasswordTokenAsync(new PasswordTokenRequest
{
Address = disco.TokenEndpoint,
ClientId = "m2m.client",
ClientSecret = "511536EF-F270-4058-80CA-1C89C192F69A",
UserName = _serverFixture.TestingUserName,
Password = _serverFixture.TestingUserPassword,
Scope = "scope1",
Parameters =
7 years ago
{
4 months ago
{ "acr_values", "tenant:custom_account_store1 foo bar quux" }
}
});
if (response.IsError) throw new Exception(response.Error);
7 years ago
}
7 years ago
5 months ago
public static IEnumerable<object[]> GetLoginIntentData()
5 months ago
{
5 months ago
return new object[][] { new object[] { "testuser", "test" } };
5 months ago
}
4 months ago
7 years ago
}
}