package utils.helpers

import org.scalatest.{Matchers, WordSpec}
import play.api.test.{FakeApplication, WithApplication}

class AesEncryptionSpec extends WordSpec with Matchers {
  val clearText = "qwerty"
  val appWithCryptpConfig = FakeApplication(
    additionalConfiguration = Map("application.secret256Bit" -> "MnPSvGpiEF5OJRG3xLAnsfmdMTLr6wpmJmZLv2RB9Vo="))

  "encryptCookie" should {
    "return an encrypted string" in new WithApplication(app = appWithCryptpConfig) {
      val aesEncryption = new AesEncryption
      aesEncryption.encrypt(clearText) should not equal clearText
    }

    "return a different encrypted string given same clear text input" in new WithApplication(app = appWithCryptpConfig)  {
      val aesEncryption = new AesEncryption
      val cipherText1 = aesEncryption.encrypt(clearText)
      val cipherText2 = aesEncryption.encrypt(clearText)

      withClue("Initialization vectors must be used to ensure output is always random") {
        cipherText1 should not equal cipherText2
      }
    }
  }

  "decryptCookie" should {
    "return a decrypted string" in new WithApplication(app = appWithCryptpConfig)  {
      val aesEncryption = new AesEncryption
      val encrypted = aesEncryption.encrypt(clearText)
      aesEncryption.decrypt(encrypted) should equal(clearText)
    }
  }

}

package utils.helpers

import org.scalatest.{Matchers, WordSpec}
import play.api.test.WithApplication

class AesEncryptionSpec extends WordSpec with Matchers {
  val clearText = "qwerty"

  "encryptCookie" should {
    "return an encrypted string" in new WithApplication {
      val aesEncryption = new AesEncryption
      aesEncryption.encrypt(clearText) should not equal clearText
    }

    "return a different encrypted string given same clear text input" in new WithApplication {
      val aesEncryption = new AesEncryption
      val cipherText1 = aesEncryption.encrypt(clearText)
      val cipherText2 = aesEncryption.encrypt(clearText)

      withClue("Initialization vectors must be used to ensure output is always random") {
        cipherText1 should not equal cipherText2
      }
    }
  }

  "decryptCookie" should {
    "return a decrypted string" in new WithApplication {
      val aesEncryption = new AesEncryption
      val encrypted = aesEncryption.encrypt(clearText)
      aesEncryption.decrypt(encrypted) should equal(clearText)
    }
  }

}

--- 
+++ 
@@ -1,18 +1,20 @@
 package utils.helpers
 
 import org.scalatest.{Matchers, WordSpec}
-import play.api.test.WithApplication
+import play.api.test.{FakeApplication, WithApplication}
 
 class AesEncryptionSpec extends WordSpec with Matchers {
   val clearText = "qwerty"
+  val appWithCryptpConfig = FakeApplication(
+    additionalConfiguration = Map("application.secret256Bit" -> "MnPSvGpiEF5OJRG3xLAnsfmdMTLr6wpmJmZLv2RB9Vo="))
 
   "encryptCookie" should {
-    "return an encrypted string" in new WithApplication {
+    "return an encrypted string" in new WithApplication(app = appWithCryptpConfig) {
       val aesEncryption = new AesEncryption
       aesEncryption.encrypt(clearText) should not equal clearText
     }
 
-    "return a different encrypted string given same clear text input" in new WithApplication {
+    "return a different encrypted string given same clear text input" in new WithApplication(app = appWithCryptpConfig)  {
       val aesEncryption = new AesEncryption
       val cipherText1 = aesEncryption.encrypt(clearText)
       val cipherText2 = aesEncryption.encrypt(clearText)
@@ -24,7 +26,7 @@
   }
 
   "decryptCookie" should {
-    "return a decrypted string" in new WithApplication {
+    "return a decrypted string" in new WithApplication(app = appWithCryptpConfig)  {
       val aesEncryption = new AesEncryption
       val encrypted = aesEncryption.encrypt(clearText)
       aesEncryption.decrypt(encrypted) should equal(clearText)
Fix the encryption tests by using a fakeapplication with the crypto config settings loaded


Former-commit-id: 23b67e57928f15ac80e4aba0a60c28448b38f065