-
Notifications
You must be signed in to change notification settings - Fork 695
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EXPOSED-203 Lightweight DAO insert with encryptedVarchar attemtps to … (
#2194) * EXPOSED-203 Lightweight DAO insert with encryptedVarchar attemtps to decrypt unencrypted input
- Loading branch information
1 parent
7c3df2f
commit e63f35b
Showing
6 changed files
with
77 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
exposed-crypt/src/test/kotlin/org/jetbrains/exposed/crypt/EncryptedColumnDaoTests.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package org.jetbrains.exposed.crypt | ||
|
||
import org.jetbrains.exposed.dao.IntEntity | ||
import org.jetbrains.exposed.dao.IntEntityClass | ||
import org.jetbrains.exposed.dao.id.EntityID | ||
import org.jetbrains.exposed.dao.id.IntIdTable | ||
import org.jetbrains.exposed.sql.selectAll | ||
import org.jetbrains.exposed.sql.tests.DatabaseTestsBase | ||
import org.jetbrains.exposed.sql.tests.shared.assertEquals | ||
import org.junit.Test | ||
|
||
class EncryptedColumnDaoTests : DatabaseTestsBase() { | ||
object TestTable : IntIdTable() { | ||
val varchar = encryptedVarchar("varchar", 100, Algorithms.AES_256_PBE_GCM("passwd", "12345678")) | ||
val binary = encryptedBinary("binary", 100, Algorithms.AES_256_PBE_GCM("passwd", "12345678")) | ||
} | ||
|
||
class ETest(id: EntityID<Int>) : IntEntity(id) { | ||
companion object : IntEntityClass<ETest>(TestTable) | ||
|
||
var varchar by TestTable.varchar | ||
var binary by TestTable.binary | ||
} | ||
|
||
@Test | ||
fun testEncryptedColumnsWithDao() { | ||
withTables(TestTable) { | ||
val varcharValue = "varchar" | ||
val binaryValue = "binary".toByteArray() | ||
|
||
val entity = ETest.new { | ||
varchar = varcharValue | ||
binary = binaryValue | ||
} | ||
assertEquals(varcharValue, entity.varchar) | ||
assertEquals(binaryValue, entity.binary) | ||
|
||
TestTable.selectAll().first().let { | ||
assertEquals(varcharValue, it[TestTable.varchar]) | ||
assertEquals(String(binaryValue), String(it[TestTable.binary])) | ||
} | ||
} | ||
} | ||
} |