Skip to content

Commit 2ae27eb

Browse files
Merge pull request #24 from eliezeralmeida/ea/fix-issue-23
fix: datetime kind problem use npgsql [issues #23]
2 parents 638cf29 + 04134d2 commit 2ae27eb

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

src/NetDevPack.Security.Jwt.Core/Model/Key.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class KeyMaterial
1111
public KeyMaterial() { }
1212
public KeyMaterial(CryptographicKey cryptographicKey)
1313
{
14-
CreationDate = DateTime.Now;
14+
CreationDate = DateTime.UtcNow;
1515
Parameters = JsonSerializer.Serialize(cryptographicKey.GetJsonWebKey(), typeof(JsonWebKey));
1616
Type = cryptographicKey.Algorithm.Kty();
1717
KeyId = cryptographicKey.Key.KeyId;
@@ -34,7 +34,7 @@ public void Revoke()
3434
{
3535
var jsonWebKey = GetSecurityKey();
3636
var publicWebKey = PublicJsonWebKey.FromJwk(jsonWebKey);
37-
ExpiredAt = DateTime.Now;
37+
ExpiredAt = DateTime.UtcNow;
3838
IsRevoked = true;
3939
Parameters = JsonSerializer.Serialize(publicWebKey.ToNativeJwk(), new JsonSerializerOptions() { DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingDefault });
4040
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
}

0 commit comments

Comments
 (0)