public void ConverterTest(ConverterTheoryData theoryData) { TestUtilities.WriteHeader($"{this}.ConverterTest", theoryData); var context = new CompareContext($"{this}.ConverterTest, {theoryData.TestId}"); try { var jsonWebKey = JsonWebKeyConverter.ConvertFromSecurityKey(theoryData.SecurityKey); if (theoryData.SecurityKey.GetType() == typeof(X509SecurityKey)) { theoryData.ExpectedException.ProcessNoException(context); IdentityComparer.AreEqual(jsonWebKey.Kty, theoryData.ComparisonJsonWebKey.Kty, context); IdentityComparer.AreEqual(jsonWebKey.Kid, theoryData.ComparisonJsonWebKey.Kid, context); var certificateExpected = (theoryData.SecurityKey as X509SecurityKey).Certificate; var certificateNew = new X509Certificate2(Convert.FromBase64String(jsonWebKey.X5c[0])); IdentityComparer.AreEqual(certificateNew, certificateExpected, context); } else { theoryData.ExpectedException.ProcessNoException(context); IdentityComparer.AreEqual(jsonWebKey, theoryData.ComparisonJsonWebKey, context); } } catch (Exception ex) { theoryData.ExpectedException.ProcessException(ex, context); } TestUtilities.AssertFailIfErrors(context); }
public void CompareJwkThumbprints(JsonWebKeyConverterTheoryData theoryData) { var context = TestUtilities.WriteHeader($"{this}.CompareJwkThumbprints", theoryData); try { JsonWebKey convertedKey; if (theoryData.SecurityKey is X509SecurityKey x509SecurityKey) { convertedKey = JsonWebKeyConverter.ConvertFromX509SecurityKey(x509SecurityKey, true); } else { convertedKey = JsonWebKeyConverter.ConvertFromSecurityKey(theoryData.SecurityKey); } theoryData.ExpectedException.ProcessNoException(context); IdentityComparer.AreBytesEqual(convertedKey.ComputeJwkThumbprint(), theoryData.SecurityKey.ComputeJwkThumbprint(), context); } catch (Exception ex) { theoryData.ExpectedException.ProcessException(ex, context); } TestUtilities.AssertFailIfErrors(context); }
public void ConvertSecurityKeyToJsonWebKey(JsonWebKeyConverterTheoryData theoryData) { var context = TestUtilities.WriteHeader($"{this}.ConvertSecurityKeyToJsonWebKey", theoryData); try { var convertedKey = JsonWebKeyConverter.ConvertFromSecurityKey(theoryData.SecurityKey); theoryData.ExpectedException.ProcessNoException(context); IdentityComparer.AreEqual(convertedKey, theoryData.JsonWebKey, context); if (convertedKey.ConvertedSecurityKey.GetType() != theoryData.SecurityKey.GetType()) { context.AddDiff($"theoryData.JsonWebKey.RelatedSecurityKey.GetType(): '{theoryData.JsonWebKey.ConvertedSecurityKey.GetType()}' != theoryData.SecurityKey.GetType(): '{theoryData.SecurityKey.GetType()}'."); } } catch (Exception ex) { theoryData.ExpectedException.ProcessException(ex, context); } TestUtilities.AssertFailIfErrors(context); }