File tree 4 files changed +28
-6
lines changed
Nager.EmailAuthentication
Nager.EmailAuthentication.UnitTest/DkimPublicKeyRecordParserTests
4 files changed +28
-6
lines changed Original file line number Diff line number Diff line change @@ -62,5 +62,25 @@ public void TryParse_WrongDkimPublicKeyRecord2_ReturnsTrueAndPopulatesDataFragme
62
62
Assert . IsFalse ( isSuccessful ) ;
63
63
Assert . IsNull ( dkimPublicKeyRecord , "DkimPublicKeyRecord is not null" ) ;
64
64
}
65
+
66
+ [ TestMethod ]
67
+ public void TryParse_DkimPublicKeyRecordWithVersion_ReturnsTrueAndPopulatesData ( )
68
+ {
69
+ var dkimPublicKeyRecordRaw = "v=DKIM1;p=test;" ;
70
+
71
+ var isSuccessful = DkimPublicKeyRecordParser . TryParse ( dkimPublicKeyRecordRaw , out var dkimPublicKeyRecord ) ;
72
+ Assert . IsTrue ( isSuccessful ) ;
73
+ Assert . IsNotNull ( dkimPublicKeyRecord , "DkimPublicKeyRecord is null" ) ;
74
+ }
75
+
76
+ [ TestMethod ]
77
+ public void TryParse_DkimPublicKeyRecordWithoutVersion_ReturnsTrueAndPopulatesData ( )
78
+ {
79
+ var dkimPublicKeyRecordRaw = "k=rsa; p=test" ;
80
+
81
+ var isSuccessful = DkimPublicKeyRecordParser . TryParse ( dkimPublicKeyRecordRaw , out var dkimPublicKeyRecord ) ;
82
+ Assert . IsTrue ( isSuccessful ) ;
83
+ Assert . IsNotNull ( dkimPublicKeyRecord , "DkimPublicKeyRecord is null" ) ;
84
+ }
65
85
}
66
86
}
Original file line number Diff line number Diff line change @@ -16,11 +16,6 @@ private static bool ValidateRaw(string? dkimPublicKeyRecordRaw)
16
16
return false ;
17
17
}
18
18
19
- if ( ! dkimPublicKeyRecordRaw . StartsWith ( "v=DKIM1" , StringComparison . OrdinalIgnoreCase ) )
20
- {
21
- return false ;
22
- }
23
-
24
19
return true ;
25
20
}
26
21
@@ -108,6 +103,12 @@ public static bool TryParseV1(
108
103
return false ;
109
104
}
110
105
106
+ if ( ! string . IsNullOrEmpty ( dkimPublicKeyRecordDataFragment . Version ) &&
107
+ ! dkimPublicKeyRecordDataFragment . Version . Equals ( "DKIM1" , StringComparison . OrdinalIgnoreCase ) )
108
+ {
109
+ return false ;
110
+ }
111
+
111
112
dkimPublicKeyRecord = new DkimPublicKeyRecordV1
112
113
{
113
114
Version = dkimPublicKeyRecordDataFragment . Version ?? "DKIM1" ,
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ public class DkimPublicKeyRecordBase
8
8
/// <summary>
9
9
/// Dkim Version <strong>(v=)</strong>
10
10
/// </summary>
11
+ /// <remarks>RECOMMENDED, default is "DKIM1"</remarks>
11
12
public required string Version { get ; set ; } = "DKIM1" ;
12
13
}
13
14
}
Original file line number Diff line number Diff line change 20
20
21
21
<TargetFrameworks >net8.0;net9.0</TargetFrameworks >
22
22
23
- <Version >2.0.1 </Version >
23
+ <Version >2.0.2 </Version >
24
24
</PropertyGroup >
25
25
26
26
<ItemGroup >
You can’t perform that action at this time.
0 commit comments