@@ -6,6 +6,8 @@ package fi.espoo.evaka.s3
6
6
7
7
import fi.espoo.evaka.BucketEnv
8
8
import fi.espoo.evaka.FullApplicationTest
9
+ import fi.espoo.evaka.shared.AttachmentId
10
+ import java.util.UUID
9
11
import kotlin.test.assertContentEquals
10
12
import kotlin.test.assertEquals
11
13
import kotlin.test.assertNotNull
@@ -26,6 +28,8 @@ class S3DocumentServiceIntegrationTest : FullApplicationTest(resetDbBeforeEach =
26
28
27
29
private lateinit var documentClient: DocumentService
28
30
31
+ val documentRef = DocumentKey .Attachment (AttachmentId (UUID .randomUUID()))
32
+
29
33
@BeforeEach
30
34
fun beforeEach () {
31
35
documentClient =
@@ -36,50 +40,41 @@ class S3DocumentServiceIntegrationTest : FullApplicationTest(resetDbBeforeEach =
36
40
fun `redirects when not proxying through nginx` () {
37
41
val documentClientNoProxy =
38
42
S3DocumentService (s3Client, s3Presigner, bucketEnv.copy(proxyThroughNginx = false ))
39
- documentClientNoProxy.upload(
40
- bucketEnv.data,
41
- Document (" test" , byteArrayOf(0x11 , 0x22 , 0x33 ), " text/plain" ),
42
- )
43
+ val location =
44
+ documentClientNoProxy.upload(documentRef, byteArrayOf(0x11 , 0x22 , 0x33 ), " text/plain" )
43
45
44
- val response = documentClientNoProxy.responseAttachment(bucketEnv.data, " test " , null )
46
+ val response = documentClientNoProxy.responseAttachment(location , null )
45
47
assertEquals(HttpStatus .FOUND , response.statusCode)
46
48
assertNotNull(response.headers[" Location" ])
47
49
assertNull(response.headers[" X-Accel-Redirect" ])
48
50
}
49
51
50
52
@Test
51
53
fun `uses X-Accel-Redirect when proxying through nginx` () {
52
- documentClient.upload(
53
- bucketEnv.data,
54
- Document (" test" , byteArrayOf(0x33 , 0x22 , 0x11 ), " text/plain" ),
55
- )
54
+ val location =
55
+ documentClient.upload(documentRef, byteArrayOf(0x33 , 0x22 , 0x11 ), " text/plain" )
56
56
57
- val response = documentClient.responseAttachment(bucketEnv.data, " test " , null )
57
+ val response = documentClient.responseAttachment(location , null )
58
58
assertEquals(HttpStatus .OK , response.statusCode)
59
59
assertNull(response.headers[" Location" ])
60
60
assertNotNull(response.headers[" X-Accel-Redirect" ])
61
61
}
62
62
63
63
@Test
64
64
fun `upload-download round trip with get` () {
65
- documentClient.upload(
66
- bucketEnv.data,
67
- Document (" test" , byteArrayOf(0x11 , 0x33 , 0x22 ), " text/plain" ),
68
- )
65
+ val location =
66
+ documentClient.upload(documentRef, byteArrayOf(0x11 , 0x33 , 0x22 ), " text/plain" )
69
67
70
- val document = documentClient.get(bucketEnv.data, " test " )
68
+ val document = documentClient.get(location )
71
69
72
70
assertContentEquals(byteArrayOf(0x11 , 0x33 , 0x22 ), document.bytes)
73
71
}
74
72
75
73
@Test
76
74
fun `responseAttachment works without filename` () {
77
- documentClient.upload(
78
- bucketEnv.data,
79
- Document (" test" , byteArrayOf(0x22 , 0x11 , 0x33 ), " text/csv" ),
80
- )
75
+ val location = documentClient.upload(documentRef, byteArrayOf(0x22 , 0x11 , 0x33 ), " text/csv" )
81
76
82
- val response = documentClient.responseAttachment(bucketEnv.data, " test " , null )
77
+ val response = documentClient.responseAttachment(location , null )
83
78
val s3Url = responseEntityToS3URL(response)
84
79
val (_, s3response, s3data) = http.get(s3Url).response()
85
80
@@ -90,13 +85,10 @@ class S3DocumentServiceIntegrationTest : FullApplicationTest(resetDbBeforeEach =
90
85
91
86
@Test
92
87
fun `responseAttachment works with filename` () {
93
- documentClient.upload(
94
- bucketEnv.data,
95
- Document (" test" , byteArrayOf(0x33 , 0x11 , 0x22 ), " application/pdf" ),
96
- )
88
+ val location =
89
+ documentClient.upload(documentRef, byteArrayOf(0x33 , 0x11 , 0x22 ), " application/pdf" )
97
90
98
- val response =
99
- documentClient.responseAttachment(bucketEnv.data, " test" , " overridden-filename.pdf" )
91
+ val response = documentClient.responseAttachment(location, " overridden-filename.pdf" )
100
92
val s3Url = responseEntityToS3URL(response)
101
93
val (_, s3response, s3data) = http.get(s3Url).response()
102
94
@@ -112,13 +104,10 @@ class S3DocumentServiceIntegrationTest : FullApplicationTest(resetDbBeforeEach =
112
104
113
105
@Test
114
106
fun `responseInline works` () {
115
- documentClient.upload(
116
- bucketEnv.data,
117
- Document (" test" , byteArrayOf(0x12 , 0x34 , 0x56 ), " text/plain" ),
118
- )
107
+ val location =
108
+ documentClient.upload(documentRef, byteArrayOf(0x12 , 0x34 , 0x56 ), " text/plain" )
119
109
120
- val response =
121
- documentClient.responseInline(bucketEnv.data, " test" , " overridden-filename.txt" )
110
+ val response = documentClient.responseInline(location, " overridden-filename.txt" )
122
111
val s3Url = responseEntityToS3URL(response)
123
112
val (_, s3response, s3data) = http.get(s3Url).response()
124
113
0 commit comments