An Oauth client handler, from abstract

This commit is contained in:
2018-07-25 02:12:13 +02:00
parent 2c3d81b950
commit 3f153eb93a
18 changed files with 710 additions and 649 deletions

View File

@ -6,16 +6,24 @@ all: test
project.lock.json: project.json
dnu restore
$(BINTARGET): project.lock.json
../Yavsc/bin/$(CONFIGURATION)/dnx451/Yavsc.dll:
make -C ../Yavsc
../Yavsc.Abstract/bin/$(CONFIGURATION)/dnx451/Yavsc.Abstract.dll:
make -C ../Yavsc.Abstract
../Yavsc.Server/bin/$(CONFIGURATION)/dnx451/Yavsc.Server.dll:
make -C ../Yavsc.Server
$(BINTARGET): project.lock.json ../Yavsc/bin/$(CONFIGURATION)/dnx451/Yavsc.dll ../Yavsc.Abstract/bin/$(CONFIGURATION)/dnx451/Yavsc.Abstract.dll ../Yavsc.Server/bin/$(CONFIGURATION)/dnx451/Yavsc.Server.dll
dnu build --configuration $(CONFIGURATION)
breaking:
dnx test -class test.YavscWorkInProgress.GitClone
dnx test -trait noregres=no
test: $(BINTARGET)
ASPNET_ENV=Development dnx test -maxthreads 1
ASPNET_ENV=Development dnx test -maxthreads 1 -trait noregres=yes
.PHONY: test

View File

@ -7,7 +7,28 @@
"HomeViewName": "Home",
"FavIcon": "/favicon.ico",
"Icon": "/images/yavsc.png",
"GitRepository": "testingrepo"
"GitRepository": "testingrepo",
"Owner": {
"Name": "Paul",
"EMail": "paul@pschneider.fr",
"PostalAddress": {
"Street1": "2 Blv A. Briand",
"Street2": "Apt 284 - Bat V",
"PostalCode": "92150",
"City": "Suresnes",
"State": "France",
"Province": null
}
},
"Admin": {
"Name": "Paul",
"EMail": "contact@pschneider.fr"
}
},
"Smtp": {
"Host": "localhost",
"Port": 25,
"EnableSSL": false
},
"Logging": {
"IncludeScopes": true,

20
test/npm-debug.log Normal file
View File

@ -0,0 +1,20 @@
0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Programs\\nodejs\\node.exe',
1 verbose cli 'C:\\Programs\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli 'install' ]
2 info using npm@1.4.9
3 info using node@v8.11.3
4 error install Couldn't read dependencies
5 error package.json ENOENT: no such file or directory, open 'C:\Users\paul\Documents\GitHub\yavsc\test\package.json'
5 error package.json This is most likely not a problem with npm itself.
5 error package.json npm can't find a package.json file in your current directory.
6 error System Windows_NT 6.1.7601
7 error command "C:\\Programs\\nodejs\\node.exe" "C:\\Programs\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install"
8 error cwd C:\Users\paul\Documents\GitHub\yavsc\test
9 error node -v v8.11.3
10 error npm -v 1.4.9
11 error path C:\Users\paul\Documents\GitHub\yavsc\test\package.json
12 error syscall open
13 error code ENOPACKAGEJSON
14 error errno -4058
15 verbose exit [ -4058, true ]

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;
}
}
}
}