| 1 |
use crate::harness::TestHarness; |
| 2 |
|
| 3 |
#[tokio::test] |
| 4 |
async fn upload_requires_login() { |
| 5 |
let mut h = TestHarness::new().await; |
| 6 |
|
| 7 |
h.client.get("/").await; |
| 8 |
|
| 9 |
let resp = h.client.post_multipart("/p/test/upload", b"fake", "image/png", "test.png").await; |
| 10 |
|
| 11 |
assert_eq!(resp.status.as_u16(), 401, "Upload without login should return 401"); |
| 12 |
} |
| 13 |
|
| 14 |
#[tokio::test] |
| 15 |
async fn upload_returns_503_without_s3() { |
| 16 |
let mut h = TestHarness::new().await; |
| 17 |
let user_id = h.login_as("uploader").await; |
| 18 |
let comm_id = h.create_community("UploadComm", "upload-comm").await; |
| 19 |
h.add_membership(user_id, comm_id, "member").await; |
| 20 |
|
| 21 |
let resp = h.client.post_multipart("/p/upload-comm/upload", b"fake png data", "image/png", "test.png").await; |
| 22 |
assert_eq!(resp.status.as_u16(), 503, "Should return 503 when S3 is not configured"); |
| 23 |
} |
| 24 |
|
| 25 |
#[tokio::test] |
| 26 |
async fn serve_image_nonexistent_returns_404() { |
| 27 |
let mut h = TestHarness::new().await; |
| 28 |
let fake_id = uuid::Uuid::new_v4(); |
| 29 |
let resp = h.client.get(&format!("/uploads/{fake_id}")).await; |
| 30 |
assert_eq!(resp.status.as_u16(), 404, "Nonexistent image should return 404"); |
| 31 |
} |
| 32 |
|
| 33 |
#[tokio::test] |
| 34 |
async fn serve_image_invalid_uuid_returns_404() { |
| 35 |
let mut h = TestHarness::new().await; |
| 36 |
let resp = h.client.get("/uploads/not-a-uuid").await; |
| 37 |
assert_eq!(resp.status.as_u16(), 404, "Invalid UUID should return 404"); |
| 38 |
} |
| 39 |
|