An Oauth client handler, from abstract

This commit is contained in:
Paul Schneider 2018-07-25 02:12:13 +02:00
commit fca6b46c92
18 changed files with 710 additions and 649 deletions

View file

@ -7,6 +7,8 @@ using Yavsc.Helpers;
namespace test
{
[Trait("noregres", "yes")]
public class YavscDnxUnitTests
{
[Fact]
@ -43,7 +45,7 @@ namespace test
public static Stream GetStream(StreamReader reader)
{
var procStart = new ProcessStartInfo("/usr/bin/nodejs", "node_modules/ansi-to-html/bin/ansi-to-html");
var procStart = new ProcessStartInfo("node", "node_modules/ansi-to-html/bin/ansi-to-html");
procStart.UseShellExecute = false;
procStart.RedirectStandardInput = true;
procStart.RedirectStandardOutput = true;

View file

@ -20,6 +20,8 @@ using Yavsc.Helpers;
using Microsoft.Data.Entity;
using Xunit.Abstractions;
using System.IO;
using Yavsc.Lib;
using System.Linq;
namespace test
{
@ -35,33 +37,30 @@ namespace test
}
[Collection("Yavsc mandatory success story")]
public class YavscMandatory: BaseTestContext
[Trait("noregres", "yes")]
public class YavscMandatory: BaseTestContext, IClassFixture<ServerSideFixture>
{
private readonly ITestOutputHelper output;
public YavscMandatory(ITestOutputHelper output)
private readonly ITestOutputHelper _output;
ServerSideFixture _serverFixture;
public YavscMandatory(ITestOutputHelper output, ServerSideFixture serverFixture)
{
this.output = output;
this._output = output;
this._serverFixture = serverFixture;
}
[Fact]
void TestStartNodeJsansitohtml()
public void GitClone()
{
var procStart = new ProcessStartInfo("env", "/usr/bin/nodejs node_modules/ansi-to-html/bin/ansi-to-html");
procStart.UseShellExecute = false;
procStart.RedirectStandardInput = true;
procStart.RedirectStandardOutput = true;
procStart.RedirectStandardError = true;
var proc = Process.Start(procStart);
var dbc = _serverFixture._app.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;
proc.StandardInput.WriteLine("\x001b[30mblack\x1b[37mwhite");
proc.StandardInput.Close();
while (!proc.StandardOutput.EndOfStream)
{
output.WriteLine(proc.StandardOutput.ReadLine());
}
var firstProject = dbc.Projects.Include(p=>p.Repository).FirstOrDefault();
Assert.NotNull (firstProject);
var clone = new GitClone(_serverFixture._siteSetup.GitRepository);
clone.Launch(firstProject);
}
// actually uses node's ansi-to-html
[Fact]
void AnsiToHtml()
{
@ -74,7 +73,7 @@ namespace test
using (var reader = new StreamReader(encoded))
{
var txt = reader.ReadToEnd();
output.WriteLine(txt);
_output.WriteLine(txt);
}
}
@ -109,8 +108,8 @@ namespace test
public void AConfigurationRoot()
{
var builder = new ConfigurationBuilder();
builder.AddJsonFile(Path.Combine(testprojectAssetPath, "appsettings.json"), false);
builder.AddJsonFile(Path.Combine(testprojectAssetPath, "appsettings.Development.json"), true);
builder.AddJsonFile( "appsettings.json", false);
builder.AddJsonFile( "appsettings.Development.json", true);
configurationRoot = builder.Build();
}

View file

@ -3,7 +3,10 @@
// paul 21/06/2018 10:11 20182018 6 21
// */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Builder.Internal;
using Microsoft.Data.Entity;
@ -14,15 +17,19 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Localization;
using Microsoft.Extensions.OptionsModel;
using Microsoft.Extensions.PlatformAbstractions;
using Newtonsoft.Json;
using Xunit;
using Xunit.Abstractions;
using Yavsc;
using Yavsc.Authentication;
using Yavsc.Lib;
using Yavsc.Models;
using static OAuth.AspNet.AuthServer.Constants;
namespace test
{
[Collection("Yavsc Work In Progress")]
[Trait("noregres", "no")]
public class YavscWorkInProgress : BaseTestContext, IClassFixture<ServerSideFixture>
{
@ -34,17 +41,59 @@ namespace test
_serverFixture = serverFixture;
}
[Fact]
public void GitClone()
[Theory]
[InlineData("d9be5e97-c19d-42e4-b444-0e65863b19e1","blouh","profile",
"http://localhost:5000/authorize",
"http://localhost:5000/oauth/success",
"http://localhost:5000/token",
"joe",
"badpass"
)]
public async Task TestUserMayLogin
(
string clientId,
string clientSecret,
string scope,
string authorizeUrl,
string redirectUrl,
string accessTokenUrl,
string login,
string pass
)
{
var dbc = _serverFixture._app.Services.GetService(typeof(ApplicationDbContext)) as ApplicationDbContext;
try {
var r = new Uri(redirectUrl);
var oauthor =new OAuthenticator( clientId, clientSecret, scope,
new Uri( authorizeUrl) , new Uri(redirectUrl) , new Uri(accessTokenUrl));
var query = new Dictionary<string,string>();
query[Parameters.Username]=login;
query[Parameters.Password]=pass;
query[Parameters.ClientId]=clientId;
query[Parameters.ClientSecret]=clientSecret;
query[Parameters.Scope]=scope;
query[Parameters.GrantType]=GrantTypes.Password;
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]);
var firstProject = dbc.Projects.Include(p=>p.Repository).FirstOrDefault();
Assert.NotNull (firstProject);
var clone = new GitClone(_serverFixture._siteSetup.GitRepository);
clone.Launch(firstProject);
}
catch (Exception ex)
{
var webex = ex as WebException;
if (webex!=null && webex.Status == (WebExceptionStatus)400)
{
if (login == "joe") {
Console.WriteLine("Bad pass joe!");
return;
}
}
throw;
}
}
}
}