Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/10527#discussion_r53435449
  
    --- Diff: 
sql/catalyst/src/test/scala/org/apache/spark/sql/catalyst/expressions/MiscFunctionsSuite.scala
 ---
    @@ -132,4 +132,92 @@ class MiscFunctionsSuite extends SparkFunSuite with 
ExpressionEvalHelper {
           }
         }
       }
    +
    +  test("aesEncrypt") {
    +    val expr1 = AesEncrypt(Literal("ABC".getBytes), 
Literal("1234567890123456".getBytes))
    +    val expr2 = AesEncrypt(Literal("".getBytes), 
Literal("1234567890123456".getBytes))
    +
    +    checkEvaluation(Base64(expr1), "y6Ss+zCYObpCbgfWfyNWTw==")
    +    checkEvaluation(Base64(expr2), "BQGHoM3lqYcsurCRq3PlUw==")
    +
    +    // input is null
    +    checkEvaluation(AesEncrypt(Literal.create(null, BinaryType),
    +      Literal("1234567890123456".getBytes)), null)
    +    // key is null
    +    checkEvaluation(AesEncrypt(Literal("ABC".getBytes),
    +      Literal.create(null, BinaryType)), null)
    +    // both are null
    +    checkEvaluation(AesEncrypt(Literal.create(null, BinaryType),
    +      Literal.create(null, BinaryType)), null)
    +
    +    // key length (80 bits) is not one of the permitted values (128, 192 
or 256 bits)
    +    intercept[java.security.InvalidKeyException] {
    +      evaluate(AesEncrypt(Literal("ABC".getBytes), 
Literal("1234567890".getBytes)))
    +    }
    +
    +    // check codegen
    +    val instance1 = UnsafeProjection.create(Base64(expr1) :: Nil)
    +    assert(instance1.apply(null).getString(0) === 
"y6Ss+zCYObpCbgfWfyNWTw==")
    +
    +    val instance2 = UnsafeProjection.create(Base64(expr2) :: Nil)
    +    assert(instance2.apply(null).getString(0) === 
"BQGHoM3lqYcsurCRq3PlUw==")
    +  }
    +
    +  test("aesDecrypt") {
    +    val expr1 = AesDecrypt(UnBase64(Literal("y6Ss+zCYObpCbgfWfyNWTw==")),
    +      Literal("1234567890123456".getBytes))
    +    val expr2 = AesDecrypt(UnBase64(Literal("BQGHoM3lqYcsurCRq3PlUw==")),
    +      Literal("1234567890123456".getBytes))
    +
    +    checkEvaluation(expr1, "ABC")
    +    checkEvaluation(expr2, "")
    +
    +    // input is null
    +    checkEvaluation(AesDecrypt(UnBase64(Literal.create(null, StringType)),
    +      Literal("1234567890123456".getBytes)), null)
    +    // key is null
    +    
checkEvaluation(AesDecrypt(UnBase64(Literal("y6Ss+zCYObpCbgfWfyNWTw==")),
    +      Literal.create(null, BinaryType)), null)
    +    // both are null
    +    checkEvaluation(AesDecrypt(UnBase64(Literal.create(null, StringType)),
    +      Literal.create(null, BinaryType)), null)
    +
    +    // key length (80 bits) is not one of the permitted values (128, 192 
or 256 bits)
    +    intercept[java.security.InvalidKeyException] {
    +      evaluate(AesDecrypt(UnBase64(Literal("y6Ss+zCYObpCbgfWfyNWTw==")),
    +        Literal("1234567890".getBytes)))
    +    }
    +
    +    // input can not be decrypted
    +    intercept[javax.crypto.IllegalBlockSizeException] {
    +      
evaluate(AesDecrypt(UnBase64(Literal("y6Ss+zCsdYObpCbgfWfyNW3Twewr")),
    +        Literal("1234567890123456".getBytes)));
    +    }
    +
    +    // input can not be decrypted
    +    intercept[javax.crypto.BadPaddingException] {
    +      evaluate(AesDecrypt(UnBase64(Literal("t6Ss+zCYObpCbgfWfyNWTw==")),
    +        Literal("1234567890123456".getBytes)));
    +    }
    +
    +    // check codegen
    +    val instance1 = UnsafeProjection.create(expr1 :: Nil)
    +    assert(instance1.apply(null).getString(0) === "ABC")
    +
    +    val instance2 = UnsafeProjection.create(expr2 :: Nil)
    +    assert(instance2.apply(null).getString(0) === "")
    --- End diff --
    
    The above 2 are not needed. Normal cases are already covered by 
`checkEvaluation`, we only need to test error case


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to