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+
710namespace AspNet . Security . OAuth . VkId ;
811
912public 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" ) ]
0 commit comments