2025-03-24 16:47:05 +01:00
|
|
|
import std/times
|
2026-02-19 15:59:15 +11:00
|
|
|
import pkg/storage/conf
|
2026-01-17 06:03:54 +11:00
|
|
|
import pkg/stint
|
|
|
|
|
from pkg/libp2p import Cid, `$`
|
2025-06-25 10:56:16 +02:00
|
|
|
import ../../asynctest
|
|
|
|
|
import ../../checktest
|
|
|
|
|
import ../../examples
|
2026-02-19 15:59:15 +11:00
|
|
|
import ../../storage/examples
|
|
|
|
|
import ../storageconfig
|
|
|
|
|
import ../storageclient
|
2025-06-25 10:56:16 +02:00
|
|
|
import ../multinodes
|
2025-03-24 16:47:05 +01:00
|
|
|
|
2025-05-26 18:49:53 +02:00
|
|
|
multinodesuite "Rest API validation":
|
2026-02-19 15:59:15 +11:00
|
|
|
let config = NodeConfigs(clients: StorageConfigs.init(nodes = 1).some)
|
|
|
|
|
var client: StorageClient
|
2025-03-24 16:47:05 +01:00
|
|
|
|
2025-05-26 18:49:53 +02:00
|
|
|
setup:
|
|
|
|
|
client = clients()[0].client
|
2025-03-24 16:47:05 +01:00
|
|
|
|
2026-01-17 06:03:54 +11:00
|
|
|
test "should return 204 when attempting delete of non-existing dataset", config:
|
2025-03-24 16:47:05 +01:00
|
|
|
let data = await RandomChunker.example(blocks = 2)
|
|
|
|
|
let cid = (await client.upload(data)).get
|
|
|
|
|
|
2026-01-17 06:03:54 +11:00
|
|
|
let responseBefore = await client.deleteRaw($Cid.example)
|
|
|
|
|
check responseBefore.status == 204
|
|
|
|
|
check (await responseBefore.body) == "" # No content
|
2025-03-24 16:47:05 +01:00
|
|
|
|
2025-05-26 18:49:53 +02:00
|
|
|
test "upload fails if content disposition contains bad filename", config:
|
2025-03-24 16:47:05 +01:00
|
|
|
let headers = @[("Content-Disposition", "attachment; filename=\"exam*ple.txt\"")]
|
|
|
|
|
let response = await client.uploadRaw("some file contents", headers)
|
|
|
|
|
|
|
|
|
|
check response.status == 422
|
|
|
|
|
check (await response.body) == "The filename is not valid."
|
|
|
|
|
|
2025-05-26 18:49:53 +02:00
|
|
|
test "upload fails if content type is invalid", config:
|
2025-03-24 16:47:05 +01:00
|
|
|
let headers = @[("Content-Type", "hello/world")]
|
|
|
|
|
let response = await client.uploadRaw("some file contents", headers)
|
|
|
|
|
|
|
|
|
|
check response.status == 422
|
|
|
|
|
check (await response.body) == "The MIME type 'hello/world' is not valid."
|
|
|
|
|
|
2025-11-02 08:32:47 +04:00
|
|
|
test "has block returns error 400 when the cid is invalid", config:
|
|
|
|
|
let response = await client.hasBlockRaw("invalid-cid")
|
|
|
|
|
|
|
|
|
|
check:
|
|
|
|
|
response.status == 400
|
|
|
|
|
(await response.body) == "Incorrect Cid"
|