public void TestBuild_ShouldThrowArgumentException_WhenMissingDecryptionKey()
 {
     try
     {
         JweConfigBuilder.AJweEncryptionConfig().Build();
     }
     catch (Exception e)
     {
         Assert.AreEqual("You must include at least an encryption certificate or a decryption key", e.Message);
         throw;
     }
 }
 public void TestBuild_ShouldThrowArgumentException_WhenNotDefiniteDecryptionPath()
 {
     try
     {
         JweConfigBuilder.AJweEncryptionConfig()
         .WithDecryptionPath("$.encryptedPayloads[*]", "$.payload")
         .WithDecryptionKey(TestUtils.GetTestDecryptionKey())
         .Build();
     }
     catch (Exception e)
     {
         Assert.AreEqual("JSON paths for decryption must point to a single item!", e.Message);
         throw;
     }
 }
        public void TestBuild_Nominal()
        {
            var config = JweConfigBuilder.AJweEncryptionConfig()
                         .WithEncryptionPath("$.payload", "$.encryptedPayload")
                         .WithEncryptionCertificate(TestUtils.GetTestEncryptionCertificate())
                         .WithDecryptionPath("$.encryptedPayload", "$.payload")
                         .WithDecryptionKey(TestUtils.GetTestDecryptionKey())
                         .WithEncryptedValueFieldName("encryptedValue")
                         .Build();

            Assert.IsNotNull(config);
            Assert.AreEqual(1, config.EncryptionPaths.Count);
            Assert.IsNotNull(config.EncryptionCertificate);
            Assert.AreEqual(1, config.DecryptionPaths.Count);
            Assert.IsNotNull(config.DecryptionKey);
            Assert.AreEqual("encryptedValue", config.EncryptedValueFieldName);
            Assert.AreEqual(EncryptionConfig.EncryptionScheme.Jwe, config.Scheme);
        }
        public void TestBuild_ShouldFallbackToDefaults()
        {
            // WHEN
            var config = JweConfigBuilder.AJweEncryptionConfig()
                         .WithEncryptionCertificate(TestUtils.GetTestEncryptionCertificate())
                         .Build();

            // THEN
            var expectedDecryptionPaths = new Dictionary <string, string> {
                { "$.encryptedData", "$" }
            };
            var expectedEncryptionPaths = new Dictionary <string, string> {
                { "$", "$" }
            };

            Assert.AreEqual(expectedDecryptionPaths.Count, config.DecryptionPaths.Count);
            Assert.AreEqual(expectedEncryptionPaths.Count, config.EncryptionPaths.Count);
            Assert.AreEqual(0, expectedDecryptionPaths.Except(config.DecryptionPaths).Count());
            Assert.AreEqual(0, expectedDecryptionPaths.Except(config.DecryptionPaths).Count());
            Assert.AreEqual("encryptedData", config.EncryptedValueFieldName);
        }
 internal static JweConfigBuilder GetTestJweConfigBuilder()
 {
     return(JweConfigBuilder.AJweEncryptionConfig()
            .WithEncryptionCertificate(TestUtils.GetTestEncryptionCertificate())
            .WithDecryptionKey(TestUtils.GetTestDecryptionKey()));
 }