File tree Expand file tree Collapse file tree 2 files changed +34
-2
lines changed
src/NetDevPack.Security.Jwt.Core/Model
tests/NetDevPack.Security.Jwt.Tests/ModelTests Expand file tree Collapse file tree 2 files changed +34
-2
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ public class KeyMaterial
11
11
public KeyMaterial ( ) { }
12
12
public KeyMaterial ( CryptographicKey cryptographicKey )
13
13
{
14
- CreationDate = DateTime . Now ;
14
+ CreationDate = DateTime . UtcNow ;
15
15
Parameters = JsonSerializer . Serialize ( cryptographicKey . GetJsonWebKey ( ) , typeof ( JsonWebKey ) ) ;
16
16
Type = cryptographicKey . Algorithm . Kty ( ) ;
17
17
KeyId = cryptographicKey . Key . KeyId ;
@@ -34,7 +34,7 @@ public void Revoke()
34
34
{
35
35
var jsonWebKey = GetSecurityKey ( ) ;
36
36
var publicWebKey = PublicJsonWebKey . FromJwk ( jsonWebKey ) ;
37
- ExpiredAt = DateTime . Now ;
37
+ ExpiredAt = DateTime . UtcNow ;
38
38
IsRevoked = true ;
39
39
Parameters = JsonSerializer . Serialize ( publicWebKey . ToNativeJwk ( ) , new JsonSerializerOptions ( ) { DefaultIgnoreCondition = JsonIgnoreCondition . WhenWritingDefault } ) ;
40
40
}
Original file line number Diff line number Diff line change
1
+ using System ;
2
+ using NetDevPack . Security . Jwt . Core . Jwa ;
3
+ using NetDevPack . Security . Jwt . Core . Model ;
4
+ using Xunit ;
5
+
6
+ namespace NetDevPack . Security . Jwt . Tests . ModelTests ;
7
+
8
+ public class KeyMaterialTests
9
+ {
10
+ [ Fact ]
11
+ public void Should_Start_CreationDate_With_Utc_Kind ( )
12
+ {
13
+ var alg = Algorithm . Create ( DigitalSignaturesAlgorithm . HmacSha256 ) ;
14
+ var key = new CryptographicKey ( alg ) ;
15
+
16
+ var keyMaterial = new KeyMaterial ( key ) ;
17
+
18
+ Assert . Equal ( DateTimeKind . Utc , keyMaterial . CreationDate . Kind ) ;
19
+ }
20
+
21
+ [ Fact ]
22
+ public void Should_Define_ExpiredAt_With_Utc_Kind ( )
23
+ {
24
+ var alg = Algorithm . Create ( DigitalSignaturesAlgorithm . HmacSha256 ) ;
25
+ var key = new CryptographicKey ( alg ) ;
26
+ var keyMaterial = new KeyMaterial ( key ) ;
27
+
28
+ keyMaterial . Revoke ( ) ;
29
+
30
+ Assert . Equal ( DateTimeKind . Utc , keyMaterial . ExpiredAt ? . Kind ) ;
31
+ }
32
+ }
You can’t perform that action at this time.
0 commit comments