yavsc/test/yavscTests/Mandatory/Remoting.cs

114 lines
4 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
// */
using System;
2018-07-25 02:12:13 +02:00
using System.Collections.Generic;
2021-01-02 00:41:54 +00:00
using System.IO;
2018-08-02 12:28:13 +02:00
using System.Linq;
2018-07-25 02:12:13 +02:00
using System.Net;
2018-08-03 02:59:37 +02:00
using System.Text;
2018-07-25 02:12:13 +02:00
using System.Threading.Tasks;
2021-01-02 00:41:54 +00:00
using Microsoft.AspNet.Hosting;
using Microsoft.Extensions.PlatformAbstractions;
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;
using static OAuth.AspNet.AuthServer.Constants;
2018-07-15 00:29:06 +02:00
2018-07-20 02:27:53 +02:00
namespace test
2018-07-15 00:29:06 +02:00
{
[Collection("Yavsc Work In Progress")]
2021-01-04 00:11:27 +00:00
[Trait("regression", "oui")]
public class Remoting : BaseTestContext, IClassFixture<ServerSideFixture>
2018-07-15 00:29:06 +02:00
{
2021-03-10 01:41:31 +00:00
readonly RegiserAPI r;
public Remoting(ServerSideFixture serverFixture, ITestOutputHelper output)
2018-08-02 12:28:13 +02:00
: base(output, serverFixture)
2018-07-21 16:15:54 +02:00
{
2021-01-02 00:41:54 +00:00
r = new RegiserAPI(serverFixture, output);
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
(
string clientId,
2018-08-02 12:28:13 +02:00
string clientSecret,
string scope,
string authorizeUrl,
string redirectUrl,
string accessTokenUrl,
string login,
string pass
2018-07-25 02:12:13 +02:00
)
{
2018-08-02 12:28:13 +02:00
try
{
r.EnsureWeb();
2018-08-02 12:28:13 +02:00
var oauthor = new OAuthenticator(clientId, clientSecret, scope,
new Uri(authorizeUrl), new Uri(redirectUrl), new Uri(accessTokenUrl));
2021-01-02 00:41:54 +00:00
var query = new Dictionary<string, string>
{
[Parameters.Username] = Startup.Testing.ValidCreds[0].UserName,
[Parameters.Password] = Startup.Testing.ValidCreds[0].Password,
[Parameters.GrantType] = GrantTypes.Password
};
2018-08-02 12:28:13 +02:00
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]);
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)
{
if (login == "joe")
{
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
public static IEnumerable<object[]> GetLoginIntentData(int numTests)
{
2018-08-03 02:59:37 +02:00
var allData = new List<object[]>();
2021-01-02 00:41:54 +00:00
for (int iTest=0; iTest < numTests && iTest < Startup.Testing.ValidCreds.Length; iTest++)
{
var login = Startup.Testing.ValidCreds[iTest].UserName;
var pass = Startup.Testing.ValidCreds[iTest].Password;
allData.Add(new object[] { ServerSideFixture.ApiKey, "blouh", "profile",
"http://localhost:5000/authorize", "http://localhost:5000/oauth/success",
"http://localhost:5000/token",login, pass});
}
var valid = allData.Count;
for (int iTest=0; iTest + valid < numTests && iTest < Startup.Testing.InvalidCreds.Length; iTest++)
2018-08-02 12:28:13 +02:00
{
2021-01-02 00:41:54 +00:00
var login = Startup.Testing.InvalidCreds[iTest].UserName;
var pass = Startup.Testing.InvalidCreds[iTest].Password;
2018-08-02 12:28:13 +02:00
2018-08-03 02:59:37 +02:00
allData.Add(new object[] { ServerSideFixture.ApiKey, "blouh", "profile",
"http://localhost:5000/authorize", "http://localhost:5000/oauth/success",
2021-01-02 00:41:54 +00:00
"http://localhost:5000/token",login, 0 });
2018-08-03 02:59:37 +02:00
}
2018-08-02 12:28:13 +02:00
return allData.Take(numTests);
}
2018-07-15 00:29:06 +02:00
}
}