Skip to content

Commit 94a2eef

Browse files
committed
Allow PUTs to create blobs as long as the id can be resolved
1 parent 00b9e1f commit 94a2eef

File tree

4 files changed

+20
-3
lines changed

4 files changed

+20
-3
lines changed

src/main/kotlin/jsonblob/api/http/ApiController.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ class ApiController(
170170

171171
private fun update(blobId: String, json: String): JsonBlob? {
172172
val resolver = idResolvers.firstOrNull { it.handles(blobId) }
173-
return if (resolver != null && jsonBlobStore.exists(blobId)) {
173+
return if (resolver != null) {
174174
val created = resolver.resolveTimestamp(blobId)
175175
val jsonBlob = JsonBlob(
176176
id = blobId,

src/main/kotlin/jsonblob/core/store/JsonBlobStore.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ abstract class JsonBlobStore(
3232
created = created
3333
)
3434
}.onFailure {
35-
log.warn { "Couldn't read JsonBlob with id=$id " }
35+
log.debug { "Couldn't read JsonBlob with id=$id " }
3636
}.getOrNull()
3737
}
3838

src/main/kotlin/jsonblob/core/store/file/FileSystemJsonBlobStore.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ open class FileSystemJsonBlobStore(
5858
lock.unlock()
5959
}
6060
}.onFailure {
61-
log.warn { "Couldn't retrieve JsonBlob with id=$id " }
61+
log.debug { "Couldn't retrieve JsonBlob with id=$id " }
6262
}.getOrNull()
6363
}
6464

src/test/kotlin/jsonblob/api/http/ApiTest.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import org.testcontainers.containers.localstack.LocalStackContainer
2525
import org.testcontainers.shaded.com.google.common.io.Files
2626
import org.testcontainers.utility.DockerImageName
2727
import software.amazon.awssdk.services.s3.S3Client
28+
import java.util.UUID
2829
import javax.inject.Inject
2930

3031

@@ -129,6 +130,22 @@ class ApiTest: TestPropertyProvider {
129130
}
130131
}
131132

133+
@Test
134+
fun `blob is created on API PUT`() {
135+
val resp = client
136+
.toBlocking()
137+
.exchange(PUT("/api/jsonBlob/${type1UUIDJsonBlobHandler.generate()}", json).contentType(MediaType.APPLICATION_JSON_TYPE), String::class.java)
138+
assertThat(resp.code()).isEqualTo(200)
139+
}
140+
141+
@Test
142+
fun `blob is not created on bad API PUT`() {
143+
val resp = client
144+
.toBlocking()
145+
.exchange(PUT("/api/jsonBlob/${UUID.randomUUID()}", json).contentType(MediaType.APPLICATION_JSON_TYPE), String::class.java)
146+
assertThat(resp.code()).isEqualTo(400)
147+
}
148+
132149
@Test
133150
fun `blob is updated on custom API PUT`() {
134151
validateUpdate {

0 commit comments

Comments
 (0)