-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Ignore CA1416 platform OS incompability added GITHUB link * Ignoring CA1416 Changing lots of Unit tests from Assert.True to proper ones * Loads of updates https://xunit.net/xunit.analyzers/rules/xUnit2012
- Loading branch information
Showing
10 changed files
with
148 additions
and
145 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Linq; | ||
using System.Security.AccessControl; | ||
using System.Security.Principal; | ||
using TameMyCerts.Enums; | ||
using TameMyCerts.Models; | ||
|
@@ -185,8 +186,8 @@ public void Does_add_static_RDN_when_not_present() | |
|
||
PrintResult(result); | ||
|
||
Assert.True(result.CertificateProperties.Any(x => | ||
x.Key.Equals(RdnTypes.NameProperty[RdnTypes.Organization]) && x.Value.Equals("ADCS Labor"))); | ||
Assert.Contains("ADCS Labor", result.CertificateProperties.Where(x => x.Key.Equals(RdnTypes.NameProperty[RdnTypes.Organization])).Select(x => x.Value)); | ||
|
||
} | ||
|
||
[Fact] | ||
|
@@ -236,8 +237,7 @@ public void Does_not_add_static_RDN_when_present_and_not_forced() | |
|
||
PrintResult(result); | ||
|
||
Assert.False(result.CertificateProperties.Any(x => | ||
x.Key.Equals(RdnTypes.NameProperty[RdnTypes.Organization]) && x.Value.Equals("ADCS Labor"))); | ||
Assert.DoesNotContain("ADCS Labor", result.CertificateProperties.Where(x => x.Key.Equals(RdnTypes.NameProperty[RdnTypes.Organization])).Select(x => x.Value)); | ||
} | ||
|
||
[Fact] | ||
|
@@ -288,8 +288,7 @@ public void Does_add_static_RDN_when_present_and_forced() | |
|
||
PrintResult(result); | ||
|
||
Assert.True(result.CertificateProperties.Any(x => | ||
x.Key.Equals(RdnTypes.NameProperty[RdnTypes.Organization]) && x.Value.Equals("ADCS Labor"))); | ||
Assert.Contains("ADCS Labor", result.CertificateProperties.Where(x => x.Key.Equals(RdnTypes.NameProperty[RdnTypes.Organization])).Select(x => x.Value)); | ||
} | ||
|
||
[Fact] | ||
|
@@ -307,7 +306,7 @@ public void Does_return_if_already_denied() | |
PrintResult(result); | ||
|
||
Assert.True(result.DeniedForIssuance); | ||
Assert.True(result.StatusCode.Equals(WinError.NTE_FAIL)); | ||
Assert.Equal(WinError.NTE_FAIL, result.StatusCode); | ||
} | ||
|
||
[Fact] | ||
|
@@ -335,7 +334,7 @@ public void Does_not_add_static_RDN_when_length_constraint_was_violated() | |
PrintResult(result); | ||
|
||
Assert.True(result.DeniedForIssuance); | ||
Assert.True(result.StatusCode.Equals(WinError.CERTSRV_E_TEMPLATE_DENIED)); | ||
Assert.Equal(WinError.CERTSRV_E_TEMPLATE_DENIED, result.StatusCode); | ||
} | ||
|
||
|
||
|
@@ -364,7 +363,7 @@ public void Does_add_static_RDN_when_length_constraint_was_not_violated() | |
PrintResult(result); | ||
|
||
Assert.False(result.DeniedForIssuance); | ||
Assert.True(result.StatusCode.Equals(WinError.ERROR_SUCCESS)); | ||
Assert.Equal(WinError.ERROR_SUCCESS, result.StatusCode); | ||
} | ||
|
||
[Fact] | ||
|
@@ -392,10 +391,8 @@ public void Does_transfer_RDN_to_RDN() | |
PrintResult(result); | ||
|
||
Assert.False(result.DeniedForIssuance); | ||
Assert.True(result.StatusCode.Equals(WinError.ERROR_SUCCESS)); | ||
Assert.True(result.CertificateProperties | ||
.Where(x => x.Key.Equals(RdnTypes.NameProperty[RdnTypes.Organization])) | ||
.Any(x => x.Value.Equals("intranet.adcslabor.de"))); | ||
Assert.Equal(WinError.ERROR_SUCCESS, result.StatusCode); | ||
Assert.Contains("intranet.adcslabor.de", result.CertificateProperties.Where(x => x.Key.Equals(RdnTypes.NameProperty[RdnTypes.Organization])).Select(x => x.Value)); | ||
} | ||
|
||
[Fact] | ||
|
@@ -430,13 +427,20 @@ public void Does_transfer_RDN_to_RDN_and_clears_original_RDN() | |
PrintResult(result); | ||
|
||
Assert.False(result.DeniedForIssuance); | ||
Assert.True(result.StatusCode.Equals(WinError.ERROR_SUCCESS)); | ||
Assert.True(result.CertificateProperties.ContainsKey(RdnTypes.NameProperty[RdnTypes.CommonName]) && | ||
result.CertificateProperties[RdnTypes.NameProperty[RdnTypes.CommonName]] | ||
.Equals(string.Empty)); | ||
Assert.True(result.CertificateProperties.ContainsKey(RdnTypes.NameProperty[RdnTypes.Organization]) && | ||
result.CertificateProperties[RdnTypes.NameProperty[RdnTypes.Organization]] | ||
.Equals("intranet.adcslabor.de")); | ||
Assert.Equal(WinError.ERROR_SUCCESS, result.StatusCode); | ||
|
||
Assert.Multiple(() => | ||
{ | ||
Assert.Contains(RdnTypes.NameProperty[RdnTypes.CommonName], result.CertificateProperties.Keys.ToList()); | ||
Assert.Empty(result.CertificateProperties[RdnTypes.NameProperty[RdnTypes.CommonName]]); | ||
} | ||
); | ||
Assert.Multiple(() => | ||
{ | ||
Assert.Contains(RdnTypes.NameProperty[RdnTypes.Organization], result.CertificateProperties.Keys.ToList()); | ||
Assert.Equal("intranet.adcslabor.de", result.CertificateProperties[RdnTypes.NameProperty[RdnTypes.Organization]]); | ||
} | ||
); | ||
} | ||
|
||
[Fact] | ||
|
@@ -464,11 +468,13 @@ public void Does_transfer_RDN_to_SAN() | |
PrintResult(result); | ||
|
||
Assert.False(result.DeniedForIssuance); | ||
Assert.True(result.StatusCode.Equals(WinError.ERROR_SUCCESS)); | ||
Assert.True( | ||
result.CertificateExtensions.ContainsKey(WinCrypt.szOID_SUBJECT_ALT_NAME2) && | ||
Convert.ToBase64String(result.CertificateExtensions[WinCrypt.szOID_SUBJECT_ALT_NAME2]) | ||
.Equals("MBeCFWludHJhbmV0LmFkY3NsYWJvci5kZQ==")); | ||
Assert.Equal(WinError.ERROR_SUCCESS, result.StatusCode); | ||
Assert.Multiple(() => | ||
{ | ||
Assert.Contains(WinCrypt.szOID_SUBJECT_ALT_NAME2, result.CertificateExtensions.Keys.ToList()); | ||
Assert.Equal("MBeCFWludHJhbmV0LmFkY3NsYWJvci5kZQ==", Convert.ToBase64String(result.CertificateExtensions[WinCrypt.szOID_SUBJECT_ALT_NAME2])); | ||
} | ||
); | ||
} | ||
|
||
[Fact] | ||
|
@@ -497,10 +503,8 @@ public void Does_transfer_inline_RDN_to_RDN() | |
PrintResult(result); | ||
|
||
Assert.False(result.DeniedForIssuance); | ||
Assert.True(result.StatusCode.Equals(WinError.ERROR_SUCCESS)); | ||
Assert.True(result.CertificateProperties | ||
.Where(x => x.Key.Equals(RdnTypes.NameProperty[RdnTypes.Organization])) | ||
.Any(x => x.Value.Equals("intranet.adcslabor.de"))); | ||
Assert.Equal(WinError.ERROR_SUCCESS, result.StatusCode); | ||
Assert.Contains("intranet.adcslabor.de", result.CertificateProperties.Where(x => x.Key.Equals(RdnTypes.NameProperty[RdnTypes.Organization])).Select(x => x.Value)); | ||
} | ||
|
||
[Fact] | ||
|
@@ -559,10 +563,8 @@ public void Does_transfer_inline_custom_RDN_to_RDN() | |
PrintResult(result); | ||
|
||
Assert.False(result.DeniedForIssuance); | ||
Assert.True(result.StatusCode.Equals(WinError.ERROR_SUCCESS)); | ||
Assert.True(result.CertificateProperties | ||
.Where(x => x.Key.Equals(RdnTypes.NameProperty[RdnTypes.CommonName])) | ||
.Any(x => x.Value.Equals("test"))); | ||
Assert.Equal(WinError.ERROR_SUCCESS, result.StatusCode); | ||
Assert.Contains("test", result.CertificateProperties.Where(x => x.Key.Equals(RdnTypes.NameProperty[RdnTypes.CommonName])).Select(x => x.Value)); | ||
} | ||
|
||
[Fact] | ||
|
@@ -591,7 +593,7 @@ public void Does_transfer_inline_RDN_to_SAN() | |
PrintResult(result); | ||
|
||
Assert.False(result.DeniedForIssuance); | ||
Assert.True(result.StatusCode.Equals(WinError.ERROR_SUCCESS)); | ||
Assert.Equal(WinError.ERROR_SUCCESS, result.StatusCode); | ||
Assert.True( | ||
result.CertificateExtensions.ContainsKey(WinCrypt.szOID_SUBJECT_ALT_NAME2) && | ||
Convert.ToBase64String(result.CertificateExtensions[WinCrypt.szOID_SUBJECT_ALT_NAME2]) | ||
|
@@ -648,10 +650,8 @@ public void Does_transfer_SAN_to_RDN() | |
PrintResult(result); | ||
|
||
Assert.False(result.DeniedForIssuance); | ||
Assert.True(result.StatusCode.Equals(WinError.ERROR_SUCCESS)); | ||
Assert.True(result.CertificateProperties | ||
.Where(x => x.Key.Equals(RdnTypes.NameProperty[RdnTypes.CommonName])) | ||
.Any(x => x.Value.Equals("intranet.adcslabor.de"))); | ||
Assert.Equal(WinError.ERROR_SUCCESS, result.StatusCode); | ||
Assert.Contains("intranet.adcslabor.de", result.CertificateProperties.Where(x => x.Key.Equals(RdnTypes.NameProperty[RdnTypes.CommonName])).Select(x => x.Value)); | ||
} | ||
|
||
[Fact] | ||
|
@@ -679,7 +679,7 @@ public void Does_not_add_static_RDN_when_field_is_invalid() | |
PrintResult(result); | ||
|
||
Assert.True(result.DeniedForIssuance); | ||
Assert.True(result.StatusCode.Equals(WinError.CERTSRV_E_TEMPLATE_DENIED)); | ||
Assert.Equal(WinError.CERTSRV_E_TEMPLATE_DENIED, result.StatusCode); | ||
} | ||
|
||
[Fact] | ||
|
@@ -858,10 +858,13 @@ public void Does_add_static_SAN_when_present_and_forced() | |
|
||
PrintResult(result); | ||
|
||
Assert.True( | ||
result.CertificateExtensions.ContainsKey(WinCrypt.szOID_SUBJECT_ALT_NAME2) && | ||
Convert.ToBase64String(result.CertificateExtensions[WinCrypt.szOID_SUBJECT_ALT_NAME2]) | ||
.Equals(expectedResult)); | ||
Assert.Multiple(() => | ||
{ | ||
Assert.Contains(WinCrypt.szOID_SUBJECT_ALT_NAME2, result.CertificateExtensions.Keys.ToList()); | ||
Assert.Equal(expectedResult, Convert.ToBase64String(result.CertificateExtensions[WinCrypt.szOID_SUBJECT_ALT_NAME2])); | ||
} | ||
); | ||
|
||
} | ||
|
||
|
||
|
@@ -943,10 +946,7 @@ public void Allow_and_add_one_RDN() | |
PrintResult(result); | ||
|
||
Assert.False(result.DeniedForIssuance); | ||
Assert.True(result.CertificateProperties | ||
.Where(x => x.Key.Equals(RdnTypes.NameProperty[RdnTypes.CommonName])) | ||
.Any(x => x.Value.Equals("[email protected]")) | ||
); | ||
Assert.Contains("[email protected]", result.CertificateProperties.Where(x => x.Key.Equals(RdnTypes.NameProperty[RdnTypes.CommonName])).Select(x => x.Value)); | ||
} | ||
|
||
[Fact] | ||
|
@@ -975,10 +975,7 @@ public void Allow_and_add_one_RDN_CI() | |
PrintResult(result); | ||
|
||
Assert.False(result.DeniedForIssuance); | ||
Assert.True(result.CertificateProperties | ||
.Where(x => x.Key.Equals(RdnTypes.NameProperty[RdnTypes.CommonName])) | ||
.Any(x => x.Value.Equals("[email protected]")) | ||
); | ||
Assert.Contains("[email protected]", result.CertificateProperties.Where(x => x.Key.Equals(RdnTypes.NameProperty[RdnTypes.CommonName])).Select(x => x.Value)); | ||
} | ||
|
||
[Fact] | ||
|
@@ -1007,8 +1004,8 @@ public void Does_recognize_and_deny_valid_name_for_unknown_attribute() | |
PrintResult(result); | ||
|
||
Assert.True(result.DeniedForIssuance); | ||
Assert.True(result.StatusCode.Equals(WinError.CERTSRV_E_TEMPLATE_DENIED)); | ||
Assert.True(string.Join("\n", result.Description.ToList()).Contains("test-attribute")); | ||
Assert.Equal(WinError.CERTSRV_E_TEMPLATE_DENIED, result.StatusCode); | ||
Assert.Contains("test-attribute", string.Join("\n", result.Description.ToList())); | ||
} | ||
|
||
[Fact] | ||
|
@@ -1065,10 +1062,7 @@ public void Allow_and_add_one_combined_RDN() | |
PrintResult(result); | ||
|
||
Assert.False(result.DeniedForIssuance); | ||
Assert.True(result.CertificateProperties | ||
.Where(x => x.Key.Equals(RdnTypes.NameProperty[RdnTypes.CommonName])) | ||
.Any(x => x.Value.Equals("Ratlos, Rudi")) | ||
); | ||
Assert.Contains("Ratlos, Rudi", result.CertificateProperties.Where(x => x.Key.Equals(RdnTypes.NameProperty[RdnTypes.CommonName])).Select(x => x.Value)); | ||
} | ||
|
||
[Fact] | ||
|
@@ -1097,10 +1091,7 @@ public void Allow_and_add_one_combined_RDN_with_twice_the_same_value() | |
PrintResult(result); | ||
|
||
Assert.False(result.DeniedForIssuance); | ||
Assert.True(result.CertificateProperties | ||
.Where(x => x.Key.Equals(RdnTypes.NameProperty[RdnTypes.CommonName])) | ||
.Any(x => x.Value.Equals("Rudi is Rudi")) | ||
); | ||
Assert.Contains("Rudi is Rudi", result.CertificateProperties.Where(x => x.Key.Equals(RdnTypes.NameProperty[RdnTypes.CommonName])).Select(x => x.Value)); | ||
} | ||
|
||
[Fact] | ||
|
@@ -1321,7 +1312,7 @@ public void Does_clear_existing_RDN() | |
PrintResult(result); | ||
|
||
Assert.False(result.DeniedForIssuance); | ||
Assert.True(result.StatusCode.Equals(WinError.ERROR_SUCCESS)); | ||
Assert.Equal(WinError.ERROR_SUCCESS, result.StatusCode); | ||
Assert.True(result.CertificateProperties.ContainsKey(RdnTypes.NameProperty[RdnTypes.CommonName]) && | ||
result.CertificateProperties[RdnTypes.NameProperty[RdnTypes.CommonName]] | ||
.Equals(string.Empty)); | ||
|
@@ -1351,7 +1342,7 @@ public void Does_clear_nonexisting_RDN() | |
PrintResult(result); | ||
|
||
Assert.False(result.DeniedForIssuance); | ||
Assert.True(result.StatusCode.Equals(WinError.ERROR_SUCCESS)); | ||
Assert.Equal(WinError.ERROR_SUCCESS, result.StatusCode); | ||
Assert.True(result.CertificateProperties.ContainsKey(RdnTypes.NameProperty[RdnTypes.State]) && | ||
result.CertificateProperties[RdnTypes.NameProperty[RdnTypes.State]].Equals(string.Empty)); | ||
} | ||
|
@@ -1380,7 +1371,7 @@ public void Does_not_clear_existing_RDN_if_not_mandatory() | |
PrintResult(result); | ||
|
||
Assert.False(result.DeniedForIssuance); | ||
Assert.True(result.StatusCode.Equals(WinError.ERROR_SUCCESS)); | ||
Assert.Equal(WinError.ERROR_SUCCESS, result.StatusCode); | ||
Assert.False(result.CertificateProperties.ContainsKey(RdnTypes.NameProperty[RdnTypes.CommonName])); | ||
} | ||
|
||
|
Oops, something went wrong.