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