Skip to content

Commit

Permalink
provider/vk-id: fix tests for VK ID provider
Browse files Browse the repository at this point in the history
  • Loading branch information
HScokies committed Nov 4, 2024
1 parent 366b909 commit 96f572f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
26 changes: 24 additions & 2 deletions test/AspNet.Security.OAuth.Providers.Tests/VkId/VkIdTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
* for more information concerning the license and the contributors participating to this project.
*/

using Microsoft.AspNetCore.DataProtection;
using NSubstitute;

namespace AspNet.Security.OAuth.VkId;

public class VkIdTests : OAuthTests<VkIdAuthenticationOptions>
Expand All @@ -19,14 +22,33 @@ public VkIdTests(ITestOutputHelper outputHelper)

protected internal override void RegisterAuthentication(AuthenticationBuilder builder)
{
builder.AddVkId(options => ConfigureDefaults(builder, options));
var dataProtector = (IDataProtector)DataProtectionProvider.Create("test");
var fakeDataProtector = Substitute.For<IDataProtector>();

fakeDataProtector.Protect(Arg.Any<byte[]>())
.Returns(x => dataProtector.Protect(x.Arg<byte[]>()));
fakeDataProtector.Unprotect(Arg.Is<byte[]>(x => !x.SequenceEqual(Array.Empty<byte>())))
.Returns(x => dataProtector.Unprotect(x.Arg<byte[]>()));

// Use fake DP with empty AuthenticationProperties for ExchangeCodeAsync state validation
fakeDataProtector.Unprotect(Arg.Is<byte[]>(x => x.SequenceEqual(Array.Empty<byte>())))
.Returns([1, 0, 0, 0, 0, 0, 0, 0]);

builder.AddVkId(
options =>
{
ConfigureDefaults(builder, options);
options.StateDataFormat = new PropertiesDataFormat(fakeDataProtector);
});
}

[Theory]
[InlineData(ClaimTypes.NameIdentifier, "1234567890")]
[InlineData(ClaimTypes.GivenName, "Ivan")]
[InlineData(ClaimTypes.Surname, "Ivanov")]
[InlineData(VkIdAuthenticationConstants.Claims.Avatar, "https://pp.userapi.com/60tZWMo4SmwcploUVl9XEt8ufnTTvDUmQ6Bj1g/mmv1pcj63C4.png")]
[InlineData(
VkIdAuthenticationConstants.Claims.Avatar,
"https://pp.userapi.com/60tZWMo4SmwcploUVl9XEt8ufnTTvDUmQ6Bj1g/mmv1pcj63C4.png")]
[InlineData(ClaimTypes.Gender, "2")]
[InlineData(VkIdAuthenticationConstants.Claims.IsVerified, "False")]
[InlineData(ClaimTypes.DateOfBirth, "01.01.2000")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"id_token": "XXXXX",
"expires_in": 0,
"user_id": 1234567890,
"state": "CfDJ8Pr-vgGKYEFCgHueyh17vWJ8_XXJHbV5XtKOAW1PZ7cddgZQNE8Jlv7QL7wa3fdIFbUxtxqp9lfe4volp6-TBWPj1SNU0VUO5SjY3jwDPgRfgxcbPlSk3yzYriW9bgrZ3B3umpSOZYRhLggxPvYPBRW9eruVvYmesbrt8fVsTTgV",
"state": "",
"scope": "email phone"
}
},
Expand Down

0 comments on commit 96f572f

Please sign in to comment.