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