Skip to content

Commit

Permalink
Loads of updates
Browse files Browse the repository at this point in the history
  • Loading branch information
virot committed Nov 3, 2024
1 parent 483c8ed commit b1145df
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 49 deletions.
87 changes: 39 additions & 48 deletions TameMyCerts.Tests/CertificateContentValidatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -393,9 +392,7 @@ public void Does_transfer_RDN_to_RDN()

Assert.False(result.DeniedForIssuance);
Assert.Equal(WinError.ERROR_SUCCESS, result.StatusCode);
Assert.True(result.CertificateProperties
.Where(x => x.Key.Equals(RdnTypes.NameProperty[RdnTypes.Organization]))
.Any(x => x.Value.Equals("intranet.adcslabor.de")));
Assert.Contains("intranet.adcslabor.de", result.CertificateProperties.Where(x => x.Key.Equals(RdnTypes.NameProperty[RdnTypes.Organization])).Select(x => x.Value));
}

[Fact]
Expand Down Expand Up @@ -431,12 +428,19 @@ public void Does_transfer_RDN_to_RDN_and_clears_original_RDN()

Assert.False(result.DeniedForIssuance);
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));
Assert.True(result.CertificateProperties.ContainsKey(RdnTypes.NameProperty[RdnTypes.Organization]) &&
result.CertificateProperties[RdnTypes.NameProperty[RdnTypes.Organization]]
.Equals("intranet.adcslabor.de"));

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]
Expand Down Expand Up @@ -465,10 +469,12 @@ public void Does_transfer_RDN_to_SAN()

Assert.False(result.DeniedForIssuance);
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])
.Equals("MBeCFWludHJhbmV0LmFkY3NsYWJvci5kZQ=="));
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]
Expand Down Expand Up @@ -498,9 +504,7 @@ public void Does_transfer_inline_RDN_to_RDN()

Assert.False(result.DeniedForIssuance);
Assert.Equal(WinError.ERROR_SUCCESS, result.StatusCode);
Assert.True(result.CertificateProperties
.Where(x => x.Key.Equals(RdnTypes.NameProperty[RdnTypes.Organization]))
.Any(x => x.Value.Equals("intranet.adcslabor.de")));
Assert.Contains("intranet.adcslabor.de", result.CertificateProperties.Where(x => x.Key.Equals(RdnTypes.NameProperty[RdnTypes.Organization])).Select(x => x.Value));
}

[Fact]
Expand Down Expand Up @@ -560,9 +564,7 @@ public void Does_transfer_inline_custom_RDN_to_RDN()

Assert.False(result.DeniedForIssuance);
Assert.Equal(WinError.ERROR_SUCCESS, result.StatusCode);
Assert.True(result.CertificateProperties
.Where(x => x.Key.Equals(RdnTypes.NameProperty[RdnTypes.CommonName]))
.Any(x => x.Value.Equals("test")));
Assert.Contains("test", result.CertificateProperties.Where(x => x.Key.Equals(RdnTypes.NameProperty[RdnTypes.CommonName])).Select(x => x.Value));
}

[Fact]
Expand Down Expand Up @@ -649,9 +651,7 @@ public void Does_transfer_SAN_to_RDN()

Assert.False(result.DeniedForIssuance);
Assert.Equal(WinError.ERROR_SUCCESS, result.StatusCode);
Assert.True(result.CertificateProperties
.Where(x => x.Key.Equals(RdnTypes.NameProperty[RdnTypes.CommonName]))
.Any(x => x.Value.Equals("intranet.adcslabor.de")));
Assert.Contains("intranet.adcslabor.de", result.CertificateProperties.Where(x => x.Key.Equals(RdnTypes.NameProperty[RdnTypes.CommonName])).Select(x => x.Value));
}

[Fact]
Expand Down Expand Up @@ -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]));
}
);

}


Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion TameMyCerts.Tests/CertificateRequestValidatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2058,7 +2058,7 @@ public void Allow_remove_sid_extension()
PrintResult(result);

Assert.False(result.DeniedForIssuance);
Assert.True(result.DisabledCertificateExtensions.Contains(WinCrypt.szOID_NTDS_CA_SECURITY_EXT));
Assert.Contains(WinCrypt.szOID_NTDS_CA_SECURITY_EXT, result.DisabledCertificateExtensions);
}

[Fact]
Expand Down

0 comments on commit b1145df

Please sign in to comment.