yavsc/test/yavscTests/Mandatory/Remoting.cs

104 lines
3.4 KiB
C#

7 years ago
// // YavscWorkInProgress.cs
// /*
// paul 21/06/2018 10:11 20182018 6 21
// */
using System;
using System.Collections.Generic;
5 years ago
using System.IO;
7 years ago
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
5 years ago
using Microsoft.Extensions.OptionsModel;
5 years ago
using Microsoft.Extensions.PlatformAbstractions;
7 years ago
using Xunit;
7 years ago
using Xunit.Abstractions;
using Yavsc.Authentication;
using static OAuth.AspNet.AuthServer.Constants;
7 years ago
5 years ago
namespace yavscTests
7 years ago
{
[Collection("Yavsc Work In Progress")]
5 years ago
[Trait("regression", "oui")]
public class Remoting : BaseTestContext, IClassFixture<ServerSideFixture>
7 years ago
{
5 years ago
readonly RegiserAPI r;
public Remoting(ServerSideFixture serverFixture, ITestOutputHelper output)
7 years ago
: base(output, serverFixture)
7 years ago
{
5 years ago
r = new RegiserAPI(serverFixture, output);
7 years ago
}
7 years ago
[Theory]
7 years ago
[MemberData(nameof(GetLoginIntentData), parameters: 1)]
public async Task TestUserMayLogin
(
string clientId,
7 years ago
string clientSecret,
string scope,
string authorizeUrl,
string redirectUrl,
5 years ago
string accessTokenUrl
)
{
7 years ago
try
{
r.EnsureWeb();
7 years ago
var oauthor = new OAuthenticator(clientId, clientSecret, scope,
new Uri(authorizeUrl), new Uri(redirectUrl), new Uri(accessTokenUrl));
5 years ago
var query = new Dictionary<string, string>
{
5 years ago
[Parameters.Username] = Startup.TestingSetup.ValidCreds.UserName,
[Parameters.Password] = Startup.TestingSetup.ValidCreds.Password,
5 years ago
[Parameters.GrantType] = GrantTypes.Password
};
7 years ago
var result = await oauthor.RequestAccessTokenAsync(query);
Console.WriteLine(">> Got an output");
Console.WriteLine(Parameters.AccessToken + ": " + result[Parameters.AccessToken]);
Console.WriteLine(Parameters.TokenType + ": " + result[Parameters.TokenType]);
Console.WriteLine(Parameters.ExpiresIn + ": " + result[Parameters.ExpiresIn]);
Console.WriteLine(Parameters.RefreshToken + ": " + result[Parameters.RefreshToken]);
7 years ago
7 years ago
}
catch (Exception ex)
{
var webex = ex as WebException;
if (webex != null && webex.Status == (WebExceptionStatus)400)
{
5 years ago
if (Startup.TestingSetup.ValidCreds.UserName == "lame-user")
7 years ago
{
Console.WriteLine("Bad pass joe!");
return;
7 years ago
}
}
throw;
}
7 years ago
}
7 years ago
public static IEnumerable<object[]> GetLoginIntentData(int numTests)
{
var allData = new List<object[]>();
5 years ago
5 years ago
allData.Add(new object[] { "blouh", "profile",
"http://localhost:5000/authorize", "http://localhost:5000/oauth/success",
"http://localhost:5000/token", "http://localhost:5000/authorize"});
7 years ago
5 years ago
allData.Add(new object[] { "blouh", "profile",
"http://localhost:5000/authorize", "http://localhost:5000/oauth/success",
"http://localhost:5000/token", "http://localhost:5000/authorize"});
return allData.Take(numTests);;
7 years ago
}
7 years ago
}
}