Skip to content
Snippets Groups Projects
Verified Commit a6f5064d authored by Torsten Grote's avatar Torsten Grote
Browse files

Test that no temp files get left behind after upload errors

parent 402ab91e
No related branches found
No related tags found
1 merge request!86Limit the size of uploaded files
Pipeline #10836 passed
...@@ -15,8 +15,10 @@ import org.briarproject.mailbox.core.server.IntegrationTest ...@@ -15,8 +15,10 @@ import org.briarproject.mailbox.core.server.IntegrationTest
import org.junit.jupiter.api.Assertions.assertArrayEquals import org.junit.jupiter.api.Assertions.assertArrayEquals
import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import java.io.File
import kotlin.random.Random import kotlin.random.Random
import kotlin.test.assertEquals import kotlin.test.assertEquals
import kotlin.test.assertTrue
class FileManagerIntegrationTest : IntegrationTest() { class FileManagerIntegrationTest : IntegrationTest() {
...@@ -68,6 +70,7 @@ class FileManagerIntegrationTest : IntegrationTest() { ...@@ -68,6 +70,7 @@ class FileManagerIntegrationTest : IntegrationTest() {
} }
assertEquals(HttpStatusCode.BadRequest, response.status) assertEquals(HttpStatusCode.BadRequest, response.status)
assertEquals("Bad request: File larger than allowed.", response.readText()) assertEquals("Bad request: File larger than allowed.", response.readText())
assertNoTmpFiles()
} }
@Test @Test
...@@ -79,6 +82,7 @@ class FileManagerIntegrationTest : IntegrationTest() { ...@@ -79,6 +82,7 @@ class FileManagerIntegrationTest : IntegrationTest() {
body = bytes body = bytes
} }
assertEquals(HttpStatusCode.OK, response.status) assertEquals(HttpStatusCode.OK, response.status)
assertNoTmpFiles()
// owner connection got registered // owner connection got registered
assertTimestampRecent(metadataManager.ownerConnectionTime.value) assertTimestampRecent(metadataManager.ownerConnectionTime.value)
...@@ -112,6 +116,7 @@ class FileManagerIntegrationTest : IntegrationTest() { ...@@ -112,6 +116,7 @@ class FileManagerIntegrationTest : IntegrationTest() {
authenticateWithToken(contact1.token) authenticateWithToken(contact1.token)
} }
assertEquals(0, emptyFileListResponse.files.size) assertEquals(0, emptyFileListResponse.files.size)
assertNoTmpFiles()
} }
@Test @Test
...@@ -335,4 +340,11 @@ class FileManagerIntegrationTest : IntegrationTest() { ...@@ -335,4 +340,11 @@ class FileManagerIntegrationTest : IntegrationTest() {
// owner connection got registered // owner connection got registered
assertTimestampRecent(metadataManager.ownerConnectionTime.value) assertTimestampRecent(metadataManager.ownerConnectionTime.value)
} }
private fun assertNoTmpFiles() {
val dir = requireNotNull(this.tempDir)
val tmp = File(dir, "tmp")
assertTrue(tmp.isDirectory)
assertEquals(0, tmp.listFiles()?.size)
}
} }
...@@ -61,6 +61,7 @@ abstract class IntegrationTest(private val installJsonFeature: Boolean = true) { ...@@ -61,6 +61,7 @@ abstract class IntegrationTest(private val installJsonFeature: Boolean = true) {
protected val id = getNewRandomId() protected val id = getNewRandomId()
protected val contact1 = getNewRandomContact() protected val contact1 = getNewRandomContact()
protected val contact2 = getNewRandomContact() protected val contact2 = getNewRandomContact()
protected var tempDir: File? = null
@Volatile @Volatile
protected var exceptionInBackgroundThread: Throwable? = null protected var exceptionInBackgroundThread: Throwable? = null
...@@ -76,6 +77,7 @@ abstract class IntegrationTest(private val installJsonFeature: Boolean = true) { ...@@ -76,6 +77,7 @@ abstract class IntegrationTest(private val installJsonFeature: Boolean = true) {
@BeforeAll @BeforeAll
fun setUp(@TempDir tempDir: File) { fun setUp(@TempDir tempDir: File) {
this.tempDir = tempDir
testComponent = DaggerTestComponent.builder().testModule(TestModule(tempDir)).build() testComponent = DaggerTestComponent.builder().testModule(TestModule(tempDir)).build()
testComponent.injectCoreEagerSingletons() testComponent.injectCoreEagerSingletons()
assertFalse(setupManager.hasDb) assertFalse(setupManager.hasDb)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment