-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(feature) Adding attachment max size
- Loading branch information
Showing
13 changed files
with
139 additions
and
54 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
12 changes: 12 additions & 0 deletions
12
server/server-api/src/main/kotlin/projektor/server/api/AddAttachmentResponse.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,12 @@ | ||
package projektor.server.api | ||
|
||
data class AddAttachmentResponse( | ||
val successful: Boolean, | ||
val name: String?, | ||
val error: AddAttachmentError? | ||
) | ||
|
||
enum class AddAttachmentError { | ||
ATTACHMENTS_DISABLED, | ||
ATTACHMENT_TOO_LARGE | ||
} |
3 changes: 0 additions & 3 deletions
3
server/server-api/src/main/kotlin/projektor/server/api/CreateAttachmentResponse.kt
This file was deleted.
Oops, something went wrong.
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
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
79 changes: 79 additions & 0 deletions
79
...er/server-app/src/test/kotlin/projektor/attachment/AddAttachmentMaxSizeApplicationTest.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,79 @@ | ||
package projektor.attachment | ||
|
||
import io.ktor.http.HttpMethod | ||
import io.ktor.http.HttpStatusCode | ||
import io.ktor.server.testing.handleRequest | ||
import io.ktor.server.testing.setBody | ||
import io.ktor.server.testing.withTestApplication | ||
import io.ktor.util.KtorExperimentalAPI | ||
import java.io.File | ||
import java.math.BigDecimal | ||
import kotlin.test.* | ||
import projektor.ApplicationTestCase | ||
import projektor.TestSuiteData | ||
import projektor.incomingresults.randomPublicId | ||
import projektor.server.api.AddAttachmentError | ||
import projektor.server.api.AddAttachmentResponse | ||
import strikt.api.expectThat | ||
import strikt.assertions.isEqualTo | ||
import strikt.assertions.isNotNull | ||
|
||
@KtorExperimentalAPI | ||
class AddAttachmentMaxSizeApplicationTest : ApplicationTestCase() { | ||
@Test | ||
fun `when attachment max size configured and attachment size is over max allowed size should return error`() { | ||
val publicId = randomPublicId() | ||
attachmentsEnabled = true | ||
attachmentsMaxSizeMB = BigDecimal("0.02") | ||
|
||
withTestApplication(::createTestApplication) { | ||
handleRequest(HttpMethod.Post, "/run/$publicId/attachments/test-run-summary.png") { | ||
testRunDBGenerator.createTestRun( | ||
publicId, | ||
listOf( | ||
TestSuiteData("testSuite1", | ||
listOf("testSuite1TestCase1", "testSuite1TestCase2"), | ||
listOf(), | ||
listOf() | ||
) | ||
) | ||
) | ||
|
||
addHeader("content-length", "23342") | ||
setBody(File("src/test/resources/test-run-summary.png").readBytes()) | ||
}.apply { | ||
expectThat(response.status()).isEqualTo(HttpStatusCode.BadRequest) | ||
|
||
val errorResponse = objectMapper.readValue(response.content, AddAttachmentResponse::class.java) | ||
expectThat(errorResponse.error).isNotNull().and { isEqualTo(AddAttachmentError.ATTACHMENT_TOO_LARGE) } | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun `when attachment max size configured and attachment size is under max allowed size should succeed`() { | ||
val publicId = randomPublicId() | ||
attachmentsEnabled = true | ||
attachmentsMaxSizeMB = BigDecimal("0.04") | ||
|
||
withTestApplication(::createTestApplication) { | ||
handleRequest(HttpMethod.Post, "/run/$publicId/attachments/test-run-summary.png") { | ||
testRunDBGenerator.createTestRun( | ||
publicId, | ||
listOf( | ||
TestSuiteData("testSuite1", | ||
listOf("testSuite1TestCase1", "testSuite1TestCase2"), | ||
listOf(), | ||
listOf() | ||
) | ||
) | ||
) | ||
|
||
addHeader("content-length", "23342") | ||
setBody(File("src/test/resources/test-run-summary.png").readBytes()) | ||
}.apply { | ||
expectThat(response.status()).isEqualTo(HttpStatusCode.OK) | ||
} | ||
} | ||
} | ||
} |
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