public void KeyPolicySerialized(CertificatePolicy policy, string expectedJson) { using (JsonStream json = new JsonStream()) { json.WriteObject(policy); Assert.That(json.ToString(), Is.EqualTo(expectedJson)); } }
public void AreEqual(SubjectAlternativeNames actual, string expectedJson) { Assert.IsFalse(actual.IsEmpty); using JsonStream json = new JsonStream(); json.WriteObject(actual); string actualJson = json.ToString(); Assert.AreEqual(expectedJson, actualJson); }
public void InitializedAdministrators() { const string expectedJson = @"{""provider"":""provider"",""credentials"":{""account_id"":""accountId""},""org_details"":{""admin_details"":[{""first_name"":""fName"",""last_name"":""lName"",""email"":""*****@*****.**"",""phone"":""1234""}]}}"; CertificateIssuer issuer = new CertificateIssuer("test", "provider") { AccountId = "accountId", AdministratorContacts = { new AdministratorContact { Email = "*****@*****.**", FirstName = "fName", LastName = "lName", Phone = "1234" }, }, }; // Serialize the CertificateIssuer. using JsonStream json = new JsonStream(); using (Utf8JsonWriter writer = json.CreateWriter()) { writer.WriteStartObject(); ((IJsonSerializable)issuer).WriteProperties(writer); writer.WriteEndObject(); } // Assert that the CertificateIssuer was serialized properly. Assert.That(expectedJson, Is.EqualTo(json.ToString())); // De-Serialze the CertificateIssuer. var jDoc = JsonDocument.Parse(expectedJson); CertificateIssuer deserializedIssuer = new CertificateIssuer(); ((IJsonDeserializable)deserializedIssuer).ReadProperties(jDoc.RootElement); // Assert that the CertificateIssuer was de-serialized properly. Assert.That(deserializedIssuer.AccountId, Is.EqualTo(issuer.AccountId)); Assert.That(deserializedIssuer.AdministratorContacts[0].Email, Is.EqualTo(issuer.AdministratorContacts[0].Email)); Assert.That(deserializedIssuer.AdministratorContacts[0].FirstName, Is.EqualTo(issuer.AdministratorContacts[0].FirstName)); Assert.That(deserializedIssuer.AdministratorContacts[0].LastName, Is.EqualTo(issuer.AdministratorContacts[0].LastName)); Assert.That(deserializedIssuer.AdministratorContacts[0].Phone, Is.EqualTo(issuer.AdministratorContacts[0].Phone)); }
public void UninitializedAdministrators() { CertificateIssuer issuer = new CertificateIssuer("test") { AccountId = "accountId", }; using JsonStream json = new JsonStream(); using (Utf8JsonWriter writer = json.CreateWriter()) { writer.WriteStartObject(); ((IJsonSerializable)issuer).WriteProperties(writer); writer.WriteEndObject(); } Assert.AreEqual(@"{""credentials"":{""account_id"":""accountId""}}", json.ToString()); }
public void DisablePolicySerialized() { CertificatePolicy policy = new CertificatePolicy(); using (JsonStream json = new JsonStream()) { json.WriteObject(policy); Assert.AreEqual(@"{}", json.ToString()); } policy.Enabled = false; using (JsonStream json = new JsonStream()) { json.WriteObject(policy); Assert.AreEqual(@"{""attributes"":{""enabled"":false}}", json.ToString()); } }
public void DeserializesSerializesRoundtrip() { string originalJson = @"{ ""id"": ""https://testvault1021.vault.azure.net/certificates/updateCert01/policy"", ""key_props"": { ""kty"": ""RSA"", ""reuse_key"": false, ""exportable"": true, ""key_size"": 2048 }, ""secret_props"": { ""contentType"": ""application/x-pkcs12"" }, ""x509_props"": { ""subject"": ""CN=KeyVaultTest"", ""key_usage"": [], ""ekus"": [], ""validity_months"": 297, ""basic_constraints"": { ""ca"": false } }, ""lifetime_actions"": [ { ""trigger"": { ""lifetime_percentage"": 80 }, ""action"": { ""action_type"": ""EmailContacts"" } } ], ""issuer"": { ""name"": ""Unknown"" }, ""attributes"": { ""enabled"": true, ""created"": 1482188947, ""updated"": 1482188947 } }"; CertificatePolicy policy = new CertificatePolicy(); using (JsonStream json = new JsonStream(originalJson)) { policy.Deserialize(json.AsStream()); } Assert.AreEqual(CertificateKeyType.Rsa, policy.KeyType); Assert.IsFalse(policy.ReuseKey); Assert.IsTrue(policy.Exportable); Assert.AreEqual(2048, policy.KeySize); Assert.AreEqual(CertificateContentType.Pkcs12, policy.ContentType); Assert.AreEqual("CN=KeyVaultTest", policy.Subject); Assert.NotNull(policy.KeyUsage); CollectionAssert.IsEmpty(policy.KeyUsage); Assert.NotNull(policy.EnhancedKeyUsage); CollectionAssert.IsEmpty(policy.EnhancedKeyUsage); Assert.AreEqual(297, policy.ValidityInMonths); Assert.NotNull(policy.LifetimeActions); Assert.AreEqual(1, policy.LifetimeActions.Count); Assert.AreEqual(80, policy.LifetimeActions[0].LifetimePercentage); Assert.AreEqual(CertificatePolicyAction.EmailContacts, policy.LifetimeActions[0].Action); Assert.AreEqual("Unknown", policy.IssuerName); Assert.IsTrue(policy.Enabled); Assert.AreEqual(DateTimeOffset.FromUnixTimeSeconds(1482188947), policy.CreatedOn); Assert.AreEqual(DateTimeOffset.FromUnixTimeSeconds(1482188947), policy.UpdatedOn); using (JsonStream json = new JsonStream()) { JsonWriterOptions options = new JsonWriterOptions { Indented = true, }; json.WriteObject(policy, options); string expectedJson = @"{ ""key_props"": { ""kty"": ""RSA"", ""reuse_key"": false, ""exportable"": true, ""key_size"": 2048 }, ""secret_props"": { ""contentType"": ""application/x-pkcs12"" }, ""x509_props"": { ""subject"": ""CN=KeyVaultTest"", ""validity_months"": 297 }, ""issuer"": { ""name"": ""Unknown"" }, ""attributes"": { ""enabled"": true }, ""lifetime_actions"": [ { ""trigger"": { ""lifetime_percentage"": 80 }, ""action"": { ""action_type"": ""EmailContacts"" } } ] }"; Assert.AreEqual(expectedJson, json.ToString()); } }
public void InitializedAdministrators() { CertificateIssuer issuer = new CertificateIssuer("test") { AccountId = "accountId", AdministratorContacts = { new AdministratorContact { Email = "*****@*****.**", }, }, }; using JsonStream json = new JsonStream(); using (Utf8JsonWriter writer = json.CreateWriter()) { writer.WriteStartObject(); ((IJsonSerializable)issuer).WriteProperties(writer); writer.WriteEndObject(); } Assert.AreEqual(@"{""credentials"":{""account_id"":""accountId""},""org_details"":{""admin_details"":[{""email"":""*****@*****.**""}]}}", json.ToString()); }