this repo has no description
1mod common; 2use common::*; 3 4use reqwest::{StatusCode, header}; 5use serde_json::Value; 6 7#[tokio::test] 8async fn test_upload_blob_no_auth() { 9 let client = client(); 10 let res = client 11 .post(format!( 12 "{}/xrpc/com.atproto.repo.uploadBlob", 13 base_url().await 14 )) 15 .header(header::CONTENT_TYPE, "text/plain") 16 .body("no auth") 17 .send() 18 .await 19 .expect("Failed to send request"); 20 21 assert_eq!(res.status(), StatusCode::UNAUTHORIZED); 22 let body: Value = res.json().await.expect("Response was not valid JSON"); 23 assert_eq!(body["error"], "AuthenticationRequired"); 24} 25 26#[tokio::test] 27async fn test_upload_blob_success() { 28 let client = client(); 29 let (token, _) = create_account_and_login(&client).await; 30 let res = client 31 .post(format!( 32 "{}/xrpc/com.atproto.repo.uploadBlob", 33 base_url().await 34 )) 35 .header(header::CONTENT_TYPE, "text/plain") 36 .bearer_auth(token) 37 .body("This is our blob data") 38 .send() 39 .await 40 .expect("Failed to send request"); 41 42 assert_eq!(res.status(), StatusCode::OK); 43 let body: Value = res.json().await.expect("Response was not valid JSON"); 44 assert!(body["blob"]["ref"]["$link"].as_str().is_some()); 45} 46 47#[tokio::test] 48async fn test_upload_blob_bad_token() { 49 let client = client(); 50 let res = client 51 .post(format!( 52 "{}/xrpc/com.atproto.repo.uploadBlob", 53 base_url().await 54 )) 55 .header(header::CONTENT_TYPE, "text/plain") 56 .bearer_auth(BAD_AUTH_TOKEN) 57 .body("This is our blob data") 58 .send() 59 .await 60 .expect("Failed to send request"); 61 62 assert_eq!(res.status(), StatusCode::UNAUTHORIZED); 63 let body: Value = res.json().await.expect("Response was not valid JSON"); 64 assert_eq!(body["error"], "AuthenticationFailed"); 65} 66 67#[tokio::test] 68async fn test_upload_blob_unsupported_mime_type() { 69 let client = client(); 70 let (token, _) = create_account_and_login(&client).await; 71 let res = client 72 .post(format!( 73 "{}/xrpc/com.atproto.repo.uploadBlob", 74 base_url().await 75 )) 76 .header(header::CONTENT_TYPE, "application/xml") 77 .bearer_auth(token) 78 .body("<xml>not an image</xml>") 79 .send() 80 .await 81 .expect("Failed to send request"); 82 83 assert_eq!(res.status(), StatusCode::OK); 84} 85 86#[tokio::test] 87async fn test_list_missing_blobs() { 88 let client = client(); 89 let (access_jwt, _) = create_account_and_login(&client).await; 90 91 let res = client 92 .get(format!( 93 "{}/xrpc/com.atproto.repo.listMissingBlobs", 94 base_url().await 95 )) 96 .bearer_auth(&access_jwt) 97 .send() 98 .await 99 .expect("Failed to send request"); 100 101 assert_eq!(res.status(), StatusCode::OK); 102 let body: Value = res.json().await.expect("Response was not valid JSON"); 103 assert!(body["blobs"].is_array()); 104} 105 106#[tokio::test] 107async fn test_list_missing_blobs_no_auth() { 108 let client = client(); 109 let res = client 110 .get(format!( 111 "{}/xrpc/com.atproto.repo.listMissingBlobs", 112 base_url().await 113 )) 114 .send() 115 .await 116 .expect("Failed to send request"); 117 118 assert_eq!(res.status(), StatusCode::UNAUTHORIZED); 119}