Skip to content

Commit 96f572f

Browse files
committed
provider/vk-id: fix tests for VK ID provider
1 parent 366b909 commit 96f572f

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

test/AspNet.Security.OAuth.Providers.Tests/VkId/VkIdTests.cs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
* for more information concerning the license and the contributors participating to this project.
55
*/
66

7+
using Microsoft.AspNetCore.DataProtection;
8+
using NSubstitute;
9+
710
namespace AspNet.Security.OAuth.VkId;
811

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

2023
protected internal override void RegisterAuthentication(AuthenticationBuilder builder)
2124
{
22-
builder.AddVkId(options => ConfigureDefaults(builder, options));
25+
var dataProtector = (IDataProtector)DataProtectionProvider.Create("test");
26+
var fakeDataProtector = Substitute.For<IDataProtector>();
27+
28+
fakeDataProtector.Protect(Arg.Any<byte[]>())
29+
.Returns(x => dataProtector.Protect(x.Arg<byte[]>()));
30+
fakeDataProtector.Unprotect(Arg.Is<byte[]>(x => !x.SequenceEqual(Array.Empty<byte>())))
31+
.Returns(x => dataProtector.Unprotect(x.Arg<byte[]>()));
32+
33+
// Use fake DP with empty AuthenticationProperties for ExchangeCodeAsync state validation
34+
fakeDataProtector.Unprotect(Arg.Is<byte[]>(x => x.SequenceEqual(Array.Empty<byte>())))
35+
.Returns([1, 0, 0, 0, 0, 0, 0, 0]);
36+
37+
builder.AddVkId(
38+
options =>
39+
{
40+
ConfigureDefaults(builder, options);
41+
options.StateDataFormat = new PropertiesDataFormat(fakeDataProtector);
42+
});
2343
}
2444

2545
[Theory]
2646
[InlineData(ClaimTypes.NameIdentifier, "1234567890")]
2747
[InlineData(ClaimTypes.GivenName, "Ivan")]
2848
[InlineData(ClaimTypes.Surname, "Ivanov")]
29-
[InlineData(VkIdAuthenticationConstants.Claims.Avatar, "https://pp.userapi.com/60tZWMo4SmwcploUVl9XEt8ufnTTvDUmQ6Bj1g/mmv1pcj63C4.png")]
49+
[InlineData(
50+
VkIdAuthenticationConstants.Claims.Avatar,
51+
"https://pp.userapi.com/60tZWMo4SmwcploUVl9XEt8ufnTTvDUmQ6Bj1g/mmv1pcj63C4.png")]
3052
[InlineData(ClaimTypes.Gender, "2")]
3153
[InlineData(VkIdAuthenticationConstants.Claims.IsVerified, "False")]
3254
[InlineData(ClaimTypes.DateOfBirth, "01.01.2000")]

test/AspNet.Security.OAuth.Providers.Tests/VkId/bundle.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"id_token": "XXXXX",
1212
"expires_in": 0,
1313
"user_id": 1234567890,
14-
"state": "CfDJ8Pr-vgGKYEFCgHueyh17vWJ8_XXJHbV5XtKOAW1PZ7cddgZQNE8Jlv7QL7wa3fdIFbUxtxqp9lfe4volp6-TBWPj1SNU0VUO5SjY3jwDPgRfgxcbPlSk3yzYriW9bgrZ3B3umpSOZYRhLggxPvYPBRW9eruVvYmesbrt8fVsTTgV",
14+
"state": "",
1515
"scope": "email phone"
1616
}
1717
},

0 commit comments

Comments
 (0)