diff --git a/exposed-crypt/build.gradle.kts b/exposed-crypt/build.gradle.kts index b64f299278..3ae9d3e5c9 100644 --- a/exposed-crypt/build.gradle.kts +++ b/exposed-crypt/build.gradle.kts @@ -1,3 +1,5 @@ +import org.jetbrains.kotlin.gradle.tasks.KotlinCompile + plugins { kotlin("jvm") apply true } @@ -7,10 +9,20 @@ repositories { } kotlin { - jvmToolchain(8) + jvmToolchain(17) } dependencies { api(project(":exposed-core")) api(libs.spring.security.crypto) + testImplementation(project(":exposed-dao")) + testImplementation(project(":exposed-tests")) + testImplementation(libs.junit) + testImplementation(kotlin("test-junit")) +} + +tasks.withType().configureEach { + kotlinOptions { + jvmTarget = "17" + } } diff --git a/exposed-crypt/src/test/kotlin/org/jetbrains/exposed/crypt/EncryptedColumnTests.kt b/exposed-crypt/src/test/kotlin/org/jetbrains/exposed/crypt/EncryptedColumnTests.kt new file mode 100644 index 0000000000..0e4cd45df2 --- /dev/null +++ b/exposed-crypt/src/test/kotlin/org/jetbrains/exposed/crypt/EncryptedColumnTests.kt @@ -0,0 +1,92 @@ +package org.jetbrains.exposed.crypt + +import org.jetbrains.exposed.dao.id.IntIdTable +import org.jetbrains.exposed.sql.insertAndGetId +import org.jetbrains.exposed.sql.selectAll +import org.jetbrains.exposed.sql.tests.DatabaseTestsBase +import org.jetbrains.exposed.sql.tests.shared.assertEquals +import org.jetbrains.exposed.sql.update +import org.junit.Test +import kotlin.test.assertEquals + +class EncryptedColumnTests : DatabaseTestsBase() { + @Test + fun testOutputLengthOfEncryption() { + fun testSize(algorithm: String, encryptor: Encryptor, str: String) = + assertEquals( + encryptor.maxColLength(str.toByteArray().size), + encryptor.encrypt(str).toByteArray().size, + "Failed to calculate length of $algorithm's output." + ) + + val encryptors = arrayOf( + "AES_256_PBE_GCM" to Algorithms.AES_256_PBE_GCM("passwd", "12345678"), + "AES_256_PBE_CBC" to Algorithms.AES_256_PBE_CBC("passwd", "12345678"), + "BLOW_FISH" to Algorithms.BLOW_FISH("sadsad"), + "TRIPLE_DES" to Algorithms.TRIPLE_DES("1".repeat(24)) + ) + val testStrings = arrayOf("1", "2".repeat(10), "3".repeat(31), "4".repeat(1001), "5".repeat(5391)) + + for ((algorithm, encryptor) in encryptors) { + for (testStr in testStrings) { + testSize(algorithm, encryptor, testStr) + } + } + } + + @Test + fun testEncryptedColumnTypeWithAString() { + val stringTable = object : IntIdTable("StringTable") { + val name = encryptedVarchar("name", 80, Algorithms.AES_256_PBE_CBC("passwd", "5c0744940b5c369b")) + val city = encryptedBinary("city", 80, Algorithms.AES_256_PBE_GCM("passwd", "5c0744940b5c369b")) + val address = encryptedVarchar("address", 100, Algorithms.BLOW_FISH("key")) + val age = encryptedVarchar("age", 100, Algorithms.TRIPLE_DES("1".repeat(24))) + } + + withTables(stringTable) { + val id1 = stringTable.insertAndGetId { + it[name] = "testName" + it[city] = "testCity".toByteArray() + it[address] = "testAddress" + it[age] = "testAge" + } + + assertEquals(1L, stringTable.selectAll().count()) + + assertEquals("testName", stringTable.selectAll().where { stringTable.id eq id1 }.first()[stringTable.name]) + assertEquals("testCity", String(stringTable.selectAll().where { stringTable.id eq id1 }.first()[stringTable.city])) + assertEquals("testAddress", stringTable.selectAll().where { stringTable.id eq id1 }.first()[stringTable.address]) + assertEquals("testAge", stringTable.selectAll().where { stringTable.id eq id1 }.first()[stringTable.age]) + } + } + + @Test + fun testUpdateEncryptedColumnType() { + val stringTable = object : IntIdTable("StringTable") { + val name = encryptedVarchar("name", 100, Algorithms.AES_256_PBE_GCM("passwd", "12345678")) + val city = encryptedBinary("city", 100, Algorithms.AES_256_PBE_CBC("passwd", "12345678")) + val address = encryptedVarchar("address", 100, Algorithms.BLOW_FISH("key")) + } + + withTables(stringTable) { + val id = stringTable.insertAndGetId { + it[name] = "TestName" + it[city] = "TestCity".toByteArray() + it[address] = "TestAddress" + } + + val updatedName = "TestName2" + val updatedCity = "TestCity2" + val updatedAddress = "TestAddress2" + stringTable.update({ stringTable.id eq id }) { + it[name] = updatedName + it[city] = updatedCity.toByteArray() + it[address] = updatedAddress + } + + assertEquals(updatedName, stringTable.selectAll().where { stringTable.id eq id }.single()[stringTable.name]) + assertEquals(updatedCity, String(stringTable.selectAll().where { stringTable.id eq id }.single()[stringTable.city])) + assertEquals(updatedAddress, stringTable.selectAll().where { stringTable.id eq id }.single()[stringTable.address]) + } + } +} diff --git a/exposed-tests/build.gradle.kts b/exposed-tests/build.gradle.kts index ccea472a7e..4ee9341921 100644 --- a/exposed-tests/build.gradle.kts +++ b/exposed-tests/build.gradle.kts @@ -22,7 +22,6 @@ dependencies { implementation(project(":exposed-core")) implementation(project(":exposed-jdbc")) implementation(project(":exposed-dao")) - implementation(project(":exposed-crypt")) implementation(libs.slf4j) implementation(libs.log4j.slf4j.impl) diff --git a/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/dml/SelectTests.kt b/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/dml/SelectTests.kt index 3e5644bade..9a39fb15d8 100644 --- a/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/dml/SelectTests.kt +++ b/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/dml/SelectTests.kt @@ -1,9 +1,6 @@ package org.jetbrains.exposed.sql.tests.shared.dml import nl.altindag.log.LogCaptor -import org.jetbrains.exposed.crypt.Algorithms -import org.jetbrains.exposed.crypt.encryptedBinary -import org.jetbrains.exposed.crypt.encryptedVarchar import org.jetbrains.exposed.dao.id.IntIdTable import org.jetbrains.exposed.sql.* import org.jetbrains.exposed.sql.tests.DatabaseTestsBase @@ -493,30 +490,4 @@ class SelectTests : DatabaseTestsBase() { assertEquals(0, stringTable.selectAll().where { stringTable.name eq veryLongString }.count()) } } - - @Test - fun testEncryptedColumnTypeWithAString() { - val stringTable = object : IntIdTable("StringTable") { - val name = encryptedVarchar("name", 80, Algorithms.AES_256_PBE_CBC("passwd", "5c0744940b5c369b")) - val city = encryptedBinary("city", 80, Algorithms.AES_256_PBE_GCM("passwd", "5c0744940b5c369b")) - val address = encryptedVarchar("address", 100, Algorithms.BLOW_FISH("key")) - val age = encryptedVarchar("age", 100, Algorithms.TRIPLE_DES("1".repeat(24))) - } - - withTables(stringTable) { - val id1 = stringTable.insertAndGetId { - it[name] = "testName" - it[city] = "testCity".toByteArray() - it[address] = "testAddress" - it[age] = "testAge" - } - - assertEquals(1L, stringTable.selectAll().count()) - - assertEquals("testName", stringTable.selectAll().where { stringTable.id eq id1 }.first()[stringTable.name]) - assertEquals("testCity", String(stringTable.selectAll().where { stringTable.id eq id1 }.first()[stringTable.city])) - assertEquals("testAddress", stringTable.selectAll().where { stringTable.id eq id1 }.first()[stringTable.address]) - assertEquals("testAge", stringTable.selectAll().where { stringTable.id eq id1 }.first()[stringTable.age]) - } - } } diff --git a/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/dml/UpdateTests.kt b/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/dml/UpdateTests.kt index 6e5c5c49f4..36616a8766 100644 --- a/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/dml/UpdateTests.kt +++ b/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/dml/UpdateTests.kt @@ -1,8 +1,5 @@ package org.jetbrains.exposed.sql.tests.shared.dml -import org.jetbrains.exposed.crypt.Algorithms -import org.jetbrains.exposed.crypt.encryptedBinary -import org.jetbrains.exposed.crypt.encryptedVarchar import org.jetbrains.exposed.dao.id.IntIdTable import org.jetbrains.exposed.dao.id.LongIdTable import org.jetbrains.exposed.exceptions.UnsupportedByDialectException @@ -170,34 +167,4 @@ class UpdateTests : DatabaseTestsBase() { } } } - - @Test - fun `update encryptedColumnType`() { - val stringTable = object : IntIdTable("StringTable") { - val name = encryptedVarchar("name", 100, Algorithms.AES_256_PBE_GCM("passwd", "12345678")) - val city = encryptedBinary("city", 100, Algorithms.AES_256_PBE_CBC("passwd", "12345678")) - val address = encryptedVarchar("address", 100, Algorithms.BLOW_FISH("key")) - } - - withTables(stringTable) { - val id = stringTable.insertAndGetId { - it[name] = "TestName" - it[city] = "TestCity".toByteArray() - it[address] = "TestAddress" - } - - val updatedName = "TestName2" - val updatedCity = "TestCity2" - val updatedAddress = "TestAddress2" - stringTable.update({ stringTable.id eq id }) { - it[name] = updatedName - it[city] = updatedCity.toByteArray() - it[address] = updatedAddress - } - - assertEquals(updatedName, stringTable.selectAll().where { stringTable.id eq id }.single()[stringTable.name]) - assertEquals(updatedCity, String(stringTable.selectAll().where { stringTable.id eq id }.single()[stringTable.city])) - assertEquals(updatedAddress, stringTable.selectAll().where { stringTable.id eq id }.single()[stringTable.address]) - } - } } diff --git a/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/functions/FunctionsTests.kt b/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/functions/FunctionsTests.kt index 9fb7d652dd..33947a50a6 100644 --- a/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/functions/FunctionsTests.kt +++ b/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/functions/FunctionsTests.kt @@ -1,11 +1,8 @@ package org.jetbrains.exposed.sql.tests.shared.functions -import org.jetbrains.exposed.crypt.Algorithms -import org.jetbrains.exposed.crypt.Encryptor import org.jetbrains.exposed.dao.id.IntIdTable import org.jetbrains.exposed.sql.* import org.jetbrains.exposed.sql.SqlExpressionBuilder.concat -import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq import org.jetbrains.exposed.sql.tests.DatabaseTestsBase import org.jetbrains.exposed.sql.tests.TestDB import org.jetbrains.exposed.sql.tests.currentDialectTest @@ -15,7 +12,6 @@ import org.jetbrains.exposed.sql.tests.shared.dml.DMLTestsData import org.jetbrains.exposed.sql.tests.shared.dml.withCitiesAndUsers import org.jetbrains.exposed.sql.vendors.* import org.junit.Test -import kotlin.test.assertEquals import kotlin.test.assertNotNull import kotlin.test.assertNull @@ -614,28 +610,4 @@ class FunctionsTests : DatabaseTestsBase() { assertEquals("Hi Andrey!", result3[concatField3]) } } - - private val encryptors = arrayOf( - "AES_256_PBE_GCM" to Algorithms.AES_256_PBE_GCM("passwd", "12345678"), - "AES_256_PBE_CBC" to Algorithms.AES_256_PBE_CBC("passwd", "12345678"), - "BLOW_FISH" to Algorithms.BLOW_FISH("sadsad"), - "TRIPLE_DES" to Algorithms.TRIPLE_DES("1".repeat(24)) - ) - private val testStrings = arrayOf("1", "2".repeat(10), "3".repeat(31), "4".repeat(1001), "5".repeat(5391)) - - @Test - fun `test output length of encryption`() { - fun testSize(algorithm: String, encryptor: Encryptor, str: String) = - assertEquals( - encryptor.maxColLength(str.toByteArray().size), - encryptor.encrypt(str).toByteArray().size, - "Failed to calculate length of $algorithm's output." - ) - - for ((algorithm, encryptor) in encryptors) { - for (testStr in testStrings) { - testSize(algorithm, encryptor, testStr) - } - } - } } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index f676e207ce..30814189c6 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -24,7 +24,7 @@ sqlserver = "9.4.1.jre8" springFramework = "6.1.4" springBoot = "3.2.0" -spring-security-crypto = "5.8.8" +spring-security-crypto = "6.2.1" joda-time = "2.12.7" junit = "4.13.2" kotlinx-datetime = "0.5.0"