Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
olivier-spinelli committed Jul 3, 2024
2 parents 1a92b37 + a3af2d3 commit 852e84b
Show file tree
Hide file tree
Showing 14 changed files with 58 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CK.DB.Auth.AuthScope" Version="20.0.0" />
<PackageReference Include="CK.DB.Auth.AuthScope" Version="21.0.0" />
<ProjectReference Include="..\CK.DB.User.UserGitLab\CK.DB.User.UserGitLab.csproj" />
</ItemGroup>
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion CK.DB.User.UserGitLab/CK.DB.User.UserGitLab.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CK.DB.Auth" Version="20.0.0" />
<PackageReference Include="CK.DB.Auth" Version="21.0.0" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="**\*.sql;**\*.tql;**\*.y4" Exclude="bin\**;obj\**;@(EmbeddedResource)" />
Expand Down
7 changes: 0 additions & 7 deletions CK.DB.User.UserGitLab/Package.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,5 @@ public class Package : SqlPackage
void StObjConstruct( Actor.Package actorPackage, Auth.Package authPackage )
{
}

/// <summary>
/// Gets the user GitLab table.
/// </summary>
[InjectObject]
public UserGitLabTable UserGitLabTable { get; protected set; }

}
}
2 changes: 1 addition & 1 deletion CK.DB.User.UserGitLab/UserGitLabTable.Sync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public LoginResult LoginUser( ISqlCallContext ctx, IUserGitLabInfo info, bool ac
/// <param name="ctx">The call context to use.</param>
/// <param name="googleAccountId">The google account identifier.</param>
/// <returns>A <see cref="IdentifiedUserInfo{T}"/> or null if not found.</returns>
public IdentifiedUserInfo<IUserGitLabInfo> FindKnownUserInfo( ISqlCallContext ctx, string googleAccountId )
public IdentifiedUserInfo<IUserGitLabInfo>? FindKnownUserInfo( ISqlCallContext ctx, string googleAccountId )
{
using( var c = CreateReaderCommand( googleAccountId ) )
{
Expand Down
16 changes: 11 additions & 5 deletions CK.DB.User.UserGitLab/UserGitLabTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Threading.Tasks;
using System.Threading;
using CK.DB.Auth;
using System.Diagnostics.CodeAnalysis;

namespace CK.DB.User.UserGitLab
{
Expand All @@ -17,6 +18,7 @@ namespace CK.DB.User.UserGitLab
[SqlObjectItem( "transform:sUserDestroy" )]
public abstract partial class UserGitLabTable : SqlTable, IGenericAuthenticationProvider<IUserGitLabInfo>
{
[AllowNull]
IPocoFactory<IUserGitLabInfo> _infoFactory;

/// <summary>
Expand All @@ -29,6 +31,10 @@ void StObjConstruct( IPocoFactory<IUserGitLabInfo> infoFactory )
_infoFactory = infoFactory;
}

public bool CanCreatePayload => true;

object IGenericAuthenticationProvider.CreatePayload() => _infoFactory.Create();

IUserGitLabInfo IGenericAuthenticationProvider<IUserGitLabInfo>.CreatePayload() => _infoFactory.Create();

/// <summary>
Expand All @@ -49,7 +55,7 @@ void StObjConstruct( IPocoFactory<IUserGitLabInfo> infoFactory )
/// <param name="mode">Optionnaly configures Create, Update only or WithLogin behavior.</param>
/// <param name="cancellationToken">Optional cancellation token.</param>
/// <returns>The result.</returns>
public async Task<UCLResult> CreateOrUpdateGitLabUserAsync( ISqlCallContext ctx, int actorId, int userId, IUserGitLabInfo info, UCLMode mode = UCLMode.CreateOrUpdate, CancellationToken cancellationToken = default( CancellationToken ) )
public async Task<UCLResult> CreateOrUpdateGitLabUserAsync( ISqlCallContext ctx, int actorId, int userId, IUserGitLabInfo info, UCLMode mode = UCLMode.CreateOrUpdate, CancellationToken cancellationToken = default )
{
var r = await GitLabUserUCLAsync( ctx, actorId, userId, info, mode, cancellationToken ).ConfigureAwait( false );
return r;
Expand All @@ -65,7 +71,7 @@ void StObjConstruct( IPocoFactory<IUserGitLabInfo> infoFactory )
/// <param name="actualLogin">Set it to false to avoid login side-effect (such as updating the LastLoginTime) on success.</param>
/// <param name="cancellationToken">Optional cancellation token.</param>
/// <returns>The <see cref="LoginResult"/>.</returns>
public async Task<LoginResult> LoginUserAsync( ISqlCallContext ctx, IUserGitLabInfo info, bool actualLogin = true, CancellationToken cancellationToken = default( CancellationToken ) )
public async Task<LoginResult> LoginUserAsync( ISqlCallContext ctx, IUserGitLabInfo info, bool actualLogin = true, CancellationToken cancellationToken = default )
{
var mode = actualLogin
? UCLMode.UpdateOnly | UCLMode.WithActualLogin
Expand All @@ -83,7 +89,7 @@ void StObjConstruct( IPocoFactory<IUserGitLabInfo> infoFactory )
/// <param name="cancellationToken">Optional cancellation token.</param>
/// <returns>The awaitable.</returns>
[SqlProcedure( "sUserGitLabDestroy" )]
public abstract Task DestroyGitLabUserAsync( ISqlCallContext ctx, int actorId, int userId, CancellationToken cancellationToken = default( CancellationToken ) );
public abstract Task DestroyGitLabUserAsync( ISqlCallContext ctx, int actorId, int userId, CancellationToken cancellationToken = default );

/// <summary>
/// Raw call to manage GitLabUser. Since this should not be used directly, it is protected.
Expand Down Expand Up @@ -201,12 +207,12 @@ Task<LoginResult> IGenericAuthenticationProvider.LoginUserAsync( ISqlCallContext
return LoginUserAsync( ctx, info, actualLogin, cancellationToken );
}

void IGenericAuthenticationProvider.DestroyUser( ISqlCallContext ctx, int actorId, int userId, string schemeSuffix )
void IGenericAuthenticationProvider.DestroyUser( ISqlCallContext ctx, int actorId, int userId, string? schemeSuffix )
{
DestroyGitLabUser( ctx, actorId, userId );
}

Task IGenericAuthenticationProvider.DestroyUserAsync( ISqlCallContext ctx, int actorId, int userId, string schemeSuffix, CancellationToken cancellationToken )
Task IGenericAuthenticationProvider.DestroyUserAsync( ISqlCallContext ctx, int actorId, int userId, string? schemeSuffix, CancellationToken cancellationToken )
{
return DestroyGitLabUserAsync( ctx, actorId, userId, cancellationToken );
}
Expand Down
3 changes: 1 addition & 2 deletions CodeCakeBuilder/CodeCakeBuilder.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@
<SignAssembly>false</SignAssembly>
<GenerateDocumentationFile>false</GenerateDocumentationFile>
<ManagePackageVersionsCentrally>false</ManagePackageVersionsCentrally>
<Nullable>annotations</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CK.Core" Version="17.0.1" />
<PackageReference Include="CK.Core" Version="19.0.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="NuGet.Credentials" Version="6.7.0" />
Expand Down
2 changes: 1 addition & 1 deletion CodeCakeBuilder/CodeCakeBuilderKeyVault.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
-- Keys below can be removed if needed.
NUGET_ORG_PUSH_API_KEY
AZURE_FEED_SIGNATURE_OPENSOURCE_PAT
> 5S3ecmPwl/c9VctnmLWjjvQHYwI/VKCZfWeIYJUdnFW7JpVRxKdqDcb1n7yh4K4/1oNN+5EY9BDGoDiu9N/vp3Ftq8gXpaotPvjh2sJKQQk6khZxpgT6K2XR7SLmtzLM3p28I9KUTCvJWCWuO8xdt25yhfMA+mbbOOxX6HglKBaRsymD1kNUZgVASITLOqMaRki92RIGV4UfLOVQ0iSESUBAmUIJeVYgnkx9ODT48Ug=
> 5S3ecmPwl/c9VctnmLWjjvQHYwI/VKCZfWeIYJUdnFUNgXTvXkgODUD/JLFWzLFmTr20JFNZ69PBFnFQFzddU7HNmKJgH8/d5a+xiLCTloPQRhpR7l3ipO0EYeiMWAMSuurtruyxfj3+Di0uLAoGHj6O6NyxMBbH9OT8KYvVjtwv8JdgF42H/czM4ljmXiyL6fY9pg2NtJnaWL39dza4dnpH74YN2zwpWuxsUVIzGsQ=
5 changes: 5 additions & 0 deletions CodeCakeBuilder/dotnet/Build.NuGetHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ void IPackageSourceProvider.AddPackageSource( PackageSource source )
{
throw new NotSupportedException( "Should not be called in this scenario." );
}

public IReadOnlyList<PackageSource> LoadAuditSources()
{
throw new NotSupportedException( "Should not be called in this scenario." );
}
}

static NuGetHelper()
Expand Down
6 changes: 4 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@
<Copyright>Copyright Signature-Code 2007-$([System.DateTime]::UtcNow.ToString("yyyy"))</Copyright>
<!--Removes annoying Pack warning: The package version ... uses SemVer 2.0.0 or components of SemVer 1.0.0 that are not supported on legacy clients...-->
<NoWarn>NU5105</NoWarn>
<!--Considering .net6 'global using' to be an opt-in (simply reproduce this with 'false' in the csproj if needed).-->
<!--Considering .net6 'global using' to be an opt-in (simply reproduce this with 'enable' in the csproj if needed).-->
<ImplicitUsings>disable</ImplicitUsings>
<!--Nullable Reference Type should always be used!-->
<Nullable>enable</Nullable>
<PackageIcon>PackageIcon.png</PackageIcon>
<AssemblyOriginatorKeyFile>$(SolutionDir)Common/SharedKey.snk</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
Expand All @@ -60,7 +62,7 @@
<!--</GenerateDocumentation>-->
<!--<Analyzers>: This analyzer provides very welcome guidelines about async and threading issues.-->
<ItemGroup Condition=" '$(MSBuildProjectName)' != 'CodeCakeBuilder' ">
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.7.30" PrivateAssets="All" IncludeAssets="runtime;build;native;contentfiles;analyzers" />
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.10.48" PrivateAssets="All" IncludeAssets="runtime;build;native;contentfiles;analyzers" />
</ItemGroup>
<!--</Analyzers>-->
<!--<ReproducibleBuilds>-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
<IsPackable>True</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CK.DB.Auth.AuthScope.Tests" Version="20.0.0" />
<PackageReference Include="CK.DB.Auth.AuthScope.Tests" Version="21.0.0" />
<ProjectReference Include="..\..\CK.DB.User.UserGitLab.AuthScope\CK.DB.User.UserGitLab.AuthScope.csproj" />
<ProjectReference Include="..\CK.DB.User.UserGitLab.Tests\CK.DB.User.UserGitLab.Tests.csproj" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ public class UserGitLabAuthScopeTests
{

[Test]
public async Task non_user_google_ScopeSet_is_null()
public async Task non_user_google_ScopeSet_is_null_Async()
{
var user = TestHelper.StObjMap.StObjs.Obtain<UserTable>();
var p = TestHelper.StObjMap.StObjs.Obtain<Package>();
Throw.DebugAssert( user != null && p != null );
using( var ctx = new SqlStandardCallContext() )
{
var id = await user.CreateUserAsync( ctx, 1, Guid.NewGuid().ToString() );
Expand All @@ -30,11 +31,12 @@ public async Task non_user_google_ScopeSet_is_null()
}

[Test]
public async Task setting_default_scopes_impact_new_users()
public async Task setting_default_scopes_impact_new_users_Async()
{
var user = TestHelper.StObjMap.StObjs.Obtain<UserTable>();
var p = TestHelper.StObjMap.StObjs.Obtain<Package>();
var factory = TestHelper.StObjMap.StObjs.Obtain<IPocoFactory<IUserGitLabInfo>>();
Throw.DebugAssert( user != null && p != null && factory != null );
using( var ctx = new SqlStandardCallContext() )
{
AuthScopeSet original = await p.ReadDefaultScopeSetAsync( ctx );
Expand All @@ -48,6 +50,7 @@ public async Task setting_default_scopes_impact_new_users()
userInfo.GitLabAccountId = Guid.NewGuid().ToString();
await p.UserGitLabTable.CreateOrUpdateGitLabUserAsync( ctx, 1, id, userInfo );
var info = await p.UserGitLabTable.FindKnownUserInfoAsync( ctx, userInfo.GitLabAccountId );
Throw.DebugAssert( info != null );
AuthScopeSet userSet = await p.ReadScopeSetAsync( ctx, info.UserId );
userSet.ToString().Should().Be( original.ToString() );
}
Expand All @@ -65,10 +68,11 @@ public async Task setting_default_scopes_impact_new_users()

{
int id = await user.CreateUserAsync( ctx, 1, Guid.NewGuid().ToString() );
IUserGitLabInfo userInfo = p.UserGitLabTable.CreateUserInfo<IUserGitLabInfo>();
IUserGitLabInfo? userInfo = p.UserGitLabTable.CreateUserInfo<IUserGitLabInfo>();
userInfo.GitLabAccountId = Guid.NewGuid().ToString();
await p.UserGitLabTable.CreateOrUpdateGitLabUserAsync( ctx, 1, id, userInfo, UCLMode.CreateOnly | UCLMode.UpdateOnly );
userInfo = (IUserGitLabInfo)(await p.UserGitLabTable.FindKnownUserInfoAsync( ctx, userInfo.GitLabAccountId )).Info;
userInfo = (IUserGitLabInfo?)(await p.UserGitLabTable.FindKnownUserInfoAsync( ctx, userInfo.GitLabAccountId ))?.Info;
Throw.DebugAssert( userInfo != null );
AuthScopeSet userSet = await p.ReadScopeSetAsync( ctx, id );
userSet.ToString().Should().Contain( "[W]thing" )
.And.Contain( "[W]other" )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\CK.DB.User.UserGitLab\CK.DB.User.UserGitLab.csproj" />
<PackageReference Include="CK.DB.Auth.Tests" Version="20.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="CK.DB.Auth.Tests" Version="21.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
</ItemGroup>
</Project>
35 changes: 20 additions & 15 deletions Tests/CK.DB.User.UserGitLab.Tests/UserGitLabTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ public class UserGitLabTests
[Test]
public void create_GitLab_user_and_check_read_info_object_method()
{
var u = TestHelper.StObjMap.StObjs.Obtain<UserGitLabTable>();
var user = TestHelper.StObjMap.StObjs.Obtain<UserTable>();
var p = TestHelper.StObjMap.StObjs.Obtain<UserGitLabTable>();
var infoFactory = TestHelper.StObjMap.StObjs.Obtain<IPocoFactory<IUserGitLabInfo>>();
Throw.DebugAssert( user != null && p != null && infoFactory != null );
using( var ctx = new SqlStandardCallContext() )
{
var userName = Guid.NewGuid().ToString();
Expand All @@ -30,25 +31,26 @@ public void create_GitLab_user_and_check_read_info_object_method()

var info = infoFactory.Create();
info.GitLabAccountId = googleAccountId;
var created = u.CreateOrUpdateGitLabUser( ctx, 1, userId, info );
var created = p.CreateOrUpdateGitLabUser( ctx, 1, userId, info );
created.OperationResult.Should().Be( UCResult.Created );
var info2 = u.FindKnownUserInfo( ctx, googleAccountId );

var info2 = p.FindKnownUserInfo( ctx, googleAccountId );
Throw.DebugAssert( info2 != null );
info2.UserId.Should().Be( userId );
info2.Info.GitLabAccountId.Should().Be( googleAccountId );

u.FindKnownUserInfo( ctx, Guid.NewGuid().ToString() ).Should().BeNull();
p.FindKnownUserInfo( ctx, Guid.NewGuid().ToString() ).Should().BeNull();
user.DestroyUser( ctx, 1, userId );
u.FindKnownUserInfo( ctx, googleAccountId ).Should().BeNull();
p.FindKnownUserInfo( ctx, googleAccountId ).Should().BeNull();
}
}

[Test]
public async Task create_GitLab_user_and_check_read_info_object_method_async()
public async Task create_GitLab_user_and_check_read_info_object_method_Async()
{
var u = TestHelper.StObjMap.StObjs.Obtain<UserGitLabTable>();
var user = TestHelper.StObjMap.StObjs.Obtain<UserTable>();
var p = TestHelper.StObjMap.StObjs.Obtain<UserGitLabTable>();
var infoFactory = TestHelper.StObjMap.StObjs.Obtain<IPocoFactory<IUserGitLabInfo>>();
Throw.DebugAssert( user != null && p != null && infoFactory != null );
using( var ctx = new SqlStandardCallContext() )
{
var userName = Guid.NewGuid().ToString();
Expand All @@ -57,16 +59,16 @@ public async Task create_GitLab_user_and_check_read_info_object_method_async()

var info = infoFactory.Create();
info.GitLabAccountId = googleAccountId;
var created = await u.CreateOrUpdateGitLabUserAsync( ctx, 1, userId, info );
var created = await p.CreateOrUpdateGitLabUserAsync( ctx, 1, userId, info );
created.OperationResult.Should().Be( UCResult.Created );
var info2 = await u.FindKnownUserInfoAsync( ctx, googleAccountId );

var info2 = await p.FindKnownUserInfoAsync( ctx, googleAccountId );
Throw.DebugAssert( info2 != null );
info2.UserId.Should().Be( userId );
info2.Info.GitLabAccountId.Should().Be( googleAccountId );

(await u.FindKnownUserInfoAsync( ctx, Guid.NewGuid().ToString() )).Should().BeNull();
(await p.FindKnownUserInfoAsync( ctx, Guid.NewGuid().ToString() )).Should().BeNull();
await user.DestroyUserAsync( ctx, 1, userId );
(await u.FindKnownUserInfoAsync( ctx, googleAccountId )).Should().BeNull();
(await p.FindKnownUserInfoAsync( ctx, googleAccountId )).Should().BeNull();
}
}

Expand All @@ -81,20 +83,21 @@ public void vUserAuthProvider_reflects_the_user_GitLab_authentication()
{
var u = TestHelper.StObjMap.StObjs.Obtain<UserGitLabTable>();
var user = TestHelper.StObjMap.StObjs.Obtain<UserTable>();
Throw.DebugAssert( u != null && user != null );
using( var ctx = new SqlStandardCallContext() )
{
string userName = "GitLab auth - " + Guid.NewGuid().ToString();
var googleAccountId = Guid.NewGuid().ToString( "N" );
var idU = user.CreateUser( ctx, 1, userName );
u.Database.ExecuteReader( $"select * from CK.vUserAuthProvider where UserId={idU} and Scheme='GitLab'" )
u.Database.ExecuteReader( $"select * from CK.vUserAuthProvider where UserId={idU} and Scheme='GitLab'" )!
.Rows.Should().BeEmpty();
var info = u.CreateUserInfo<IUserGitLabInfo>();
info.GitLabAccountId = googleAccountId;
u.CreateOrUpdateGitLabUser( ctx, 1, idU, info );
u.Database.ExecuteScalar( $"select count(*) from CK.vUserAuthProvider where UserId={idU} and Scheme='GitLab'" )
.Should().Be( 1 );
u.DestroyGitLabUser( ctx, 1, idU );
u.Database.ExecuteReader( $"select * from CK.vUserAuthProvider where UserId={idU} and Scheme='GitLab'" )
u.Database.ExecuteReader( $"select * from CK.vUserAuthProvider where UserId={idU} and Scheme='GitLab'" )!
.Rows.Should().BeEmpty();
}
}
Expand All @@ -105,6 +108,7 @@ public void standard_generic_tests_for_GitLab_provider()
var auth = TestHelper.StObjMap.StObjs.Obtain<Auth.Package>();
// With IUserGitLabInfo POCO.
var f = TestHelper.StObjMap.StObjs.Obtain<IPocoFactory<IUserGitLabInfo>>();
Throw.DebugAssert( auth != null && f != null );
CK.DB.Auth.Tests.AuthTests.StandardTestForGenericAuthenticationProvider(
auth,
"GitLab",
Expand Down Expand Up @@ -136,6 +140,7 @@ public async Task standard_generic_tests_for_GitLab_provider_Async()
{
var auth = TestHelper.StObjMap.StObjs.Obtain<Auth.Package>();
var f = TestHelper.StObjMap.StObjs.Obtain<IPocoFactory<IUserGitLabInfo>>();
Throw.DebugAssert( auth != null && f != null );
await Auth.Tests.AuthTests.StandardTestForGenericAuthenticationProviderAsync(
auth,
"GitLab",
Expand Down
Loading

0 comments on commit 852e84b

Please sign in to comment.