This repository has been archived by the owner on Nov 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6c7acf8
commit 6c7db48
Showing
9 changed files
with
125 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/PDNDClientAssertionGenerator.Tests/DateTimeUtilsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// (c) 2024 Francesco Del Re <francesco.delre.87@gmail.com> | ||
// This code is licensed under MIT license (see LICENSE.txt for details) | ||
using PDNDClientAssertionGenerator.Utils; | ||
|
||
namespace PDNDClientAssertionGenerator.Tests | ||
{ | ||
public class DateTimeUtilsTests | ||
{ | ||
[Fact] | ||
public void ToUnixTimestamp_ShouldReturnCorrectUnixTimestamp_ForGivenDateTime() | ||
{ | ||
// Arrange | ||
DateTime dateTime = new DateTime(2024, 1, 1, 0, 0, 0, DateTimeKind.Utc); | ||
int expectedUnixTimestamp = 1704067200; | ||
|
||
// Act | ||
int actualUnixTimestamp = dateTime.ToUnixTimestamp(); | ||
|
||
// Assert | ||
Assert.Equal(expectedUnixTimestamp, actualUnixTimestamp); | ||
} | ||
|
||
[Fact] | ||
public void ToUnixTimestamp_ShouldHandleDateTimeInDifferentTimeZones_Correctly() | ||
{ | ||
// Arrange | ||
DateTime dateTimeLocal = new DateTime(2024, 1, 1, 0, 0, 0, DateTimeKind.Local); | ||
DateTime dateTimeUtc = dateTimeLocal.ToUniversalTime(); | ||
int expectedUnixTimestamp = (int)new DateTimeOffset(dateTimeUtc).ToUnixTimeSeconds(); | ||
|
||
// Act | ||
int actualUnixTimestamp = dateTimeLocal.ToUnixTimestamp(); | ||
|
||
// Assert | ||
Assert.Equal(expectedUnixTimestamp, actualUnixTimestamp); | ||
} | ||
|
||
[Fact] | ||
public void ToUnixTimestamp_ShouldReturnCorrectUnixTimestamp_ForEpochStart() | ||
{ | ||
// Arrange | ||
DateTime epochStart = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc); | ||
int expectedUnixTimestamp = 0; | ||
|
||
// Act | ||
int actualUnixTimestamp = epochStart.ToUnixTimestamp(); | ||
|
||
// Assert | ||
Assert.Equal(expectedUnixTimestamp, actualUnixTimestamp); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/PDNDClientAssertionGenerator.Tests/SecurityUtilsTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// (c) 2024 Francesco Del Re <francesco.delre.87@gmail.com> | ||
// This code is licensed under MIT license (see LICENSE.txt for details) | ||
using PDNDClientAssertionGenerator.Utils; | ||
|
||
namespace PDNDClientAssertionGenerator.Tests | ||
{ | ||
public class SecurityUtilsTests | ||
{ | ||
[Fact] | ||
public void ExtractBase64Key_ShouldRemoveHeaderFooterAndWhitespace_FromValidPemContent() | ||
{ | ||
// Arrange | ||
string pemContent = @" | ||
-----BEGIN RSA PRIVATE KEY----- | ||
MIIBOgIBAAJBAK5QpQfskLq1djoi0yRz4ksblMdxI0m5lBw9fAWvntA59NgIUlHw | ||
fNhgUJmOygwoQ6dzQbPUZp0ZEOtR10Q+/gECAwEAAQJAR1XlnMvJ0IbG4P1Rb0P/ | ||
gRJyOgkMxybMfzoVr8f+f4IkH2XfsnBhdCdHkHhbtRfct+dM+7Rp3JFd+n+6IOCC | ||
RQIhAPPAz9jYPX+3oBlfV92MdhLB3UjsoXTvGaMDHrG7PjCFAiEAuSMOFJNGFmRJ | ||
kYmujA6SeyDEzJHpxEnbx9FA41gKkBcCIQDHaXsDBL2/WPBOFcOfTLNfBQXoTpEu | ||
AfWRAd5Nvg0I9QIhAL3n2dfYFXAGpPCTg2MgttVfSe+oAapTknnCK6CRz58nAiEA | ||
4lYtY4jOOBVZWz1vUpcsWgGVpRfyRbGmJfrJ6UAKfBM= | ||
-----END RSA PRIVATE KEY----- | ||
"; | ||
|
||
string expectedBase64Key = "MIIBOgIBAAJBAK5QpQfskLq1djoi0yRz4ksblMdxI0m5lBw9fAWvntA59NgIUlHwfNhgUJmOygwoQ6dzQbPUZp0ZEOtR10Q+/gECAwEAAQJAR1XlnMvJ0IbG4P1Rb0P/gRJyOgkMxybMfzoVr8f+f4IkH2XfsnBhdCdHkHhbtRfct+dM+7Rp3JFd+n+6IOCCRQIhAPPAz9jYPX+3oBlfV92MdhLB3UjsoXTvGaMDHrG7PjCFAiEAuSMOFJNGFmRJkYmujA6SeyDEzJHpxEnbx9FA41gKkBcCIQDHaXsDBL2/WPBOFcOfTLNfBQXoTpEuAfWRAd5Nvg0I9QIhAL3n2dfYFXAGpPCTg2MgttVfSe+oAapTknnCK6CRz58nAiEA4lYtY4jOOBVZWz1vUpcsWgGVpRfyRbGmJfrJ6UAKfBM="; | ||
|
||
// Act | ||
string actualBase64Key = SecurityUtils.ExtractBase64Key(pemContent); | ||
|
||
// Assert | ||
Assert.Equal(expectedBase64Key, actualBase64Key); | ||
} | ||
|
||
[Fact] | ||
public void ExtractBase64Key_ShouldReturnEmptyString_WhenPemContentIsEmpty() | ||
{ | ||
// Arrange | ||
string pemContent = ""; | ||
string expectedBase64Key = ""; | ||
|
||
// Act | ||
string actualBase64Key = SecurityUtils.ExtractBase64Key(pemContent); | ||
|
||
// Assert | ||
Assert.Equal(expectedBase64Key, actualBase64Key); | ||
} | ||
|
||
[Fact] | ||
public void ExtractBase64Key_ShouldReturnEmptyString_WhenPemContentIsOnlyHeaderFooter() | ||
{ | ||
// Arrange | ||
string pemContent = @" | ||
-----BEGIN RSA PRIVATE KEY----- | ||
-----END RSA PRIVATE KEY----- | ||
"; | ||
string expectedBase64Key = ""; | ||
|
||
// Act | ||
string actualBase64Key = SecurityUtils.ExtractBase64Key(pemContent); | ||
|
||
// Assert | ||
Assert.Equal(expectedBase64Key, actualBase64Key); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters