this repo has no description
1mod common;
2use common::*;
3
4use reqwest::{header, StatusCode};
5use serde_json::{json, Value};
6use chrono::Utc;
7
8#[tokio::test]
9#[ignore]
10async fn test_get_record() {
11 let client = client();
12 let params = [
13 ("repo", "did:plc:12345"),
14 ("collection", "app.bsky.actor.profile"),
15 ("rkey", "self"),
16 ];
17
18 let res = client.get(format!("{}/xrpc/com.atproto.repo.getRecord", BASE_URL))
19 .query(¶ms)
20 .send()
21 .await
22 .expect("Failed to send request");
23
24 assert_eq!(res.status(), StatusCode::OK);
25 let body: Value = res.json().await.expect("Response was not valid JSON");
26 assert_eq!(body["value"]["$type"], "app.bsky.actor.profile");
27}
28
29#[tokio::test]
30#[ignore]
31async fn test_get_record_not_found() {
32 let client = client();
33 let params = [
34 ("repo", "did:plc:12345"),
35 ("collection", "app.bsky.feed.post"),
36 ("rkey", "nonexistent"),
37 ];
38
39 let res = client.get(format!("{}/xrpc/com.atproto.repo.getRecord", BASE_URL))
40 .query(¶ms)
41 .send()
42 .await
43 .expect("Failed to send request");
44
45 assert_eq!(res.status(), StatusCode::NOT_FOUND);
46 let body: Value = res.json().await.expect("Response was not valid JSON");
47 assert_eq!(body["error"], "NotFound");
48}
49
50#[tokio::test]
51#[ignore]
52async fn test_upload_blob_no_auth() {
53 let client = client();
54 let res = client.post(format!("{}/xrpc/com.atproto.repo.uploadBlob", BASE_URL))
55 .header(header::CONTENT_TYPE, "text/plain")
56 .body("no auth")
57 .send()
58 .await
59 .expect("Failed to send request");
60
61 assert_eq!(res.status(), StatusCode::UNAUTHORIZED);
62 let body: Value = res.json().await.expect("Response was not valid JSON");
63 assert_eq!(body["error"], "AuthenticationFailed");
64}
65
66#[tokio::test]
67#[ignore]
68async fn test_upload_blob_success() {
69 let client = client();
70 let (token, _) = create_account_and_login(&client).await;
71 let res = client.post(format!("{}/xrpc/com.atproto.repo.uploadBlob", BASE_URL))
72 .header(header::CONTENT_TYPE, "text/plain")
73 .bearer_auth(token)
74 .body("This is our blob data")
75 .send()
76 .await
77 .expect("Failed to send request");
78
79 assert_eq!(res.status(), StatusCode::OK);
80 let body: Value = res.json().await.expect("Response was not valid JSON");
81 assert!(body["blob"]["ref"]["$link"].as_str().is_some());
82}
83
84#[tokio::test]
85#[ignore]
86async fn test_put_record_no_auth() {
87 let client = client();
88 let payload = json!({
89 "repo": "did:plc:123",
90 "collection": "app.bsky.feed.post",
91 "rkey": "fake",
92 "record": {}
93 });
94
95 let res = client.post(format!("{}/xrpc/com.atproto.repo.putRecord", BASE_URL))
96 .json(&payload)
97 .send()
98 .await
99 .expect("Failed to send request");
100
101 assert_eq!(res.status(), StatusCode::UNAUTHORIZED);
102 let body: Value = res.json().await.expect("Response was not valid JSON");
103 assert_eq!(body["error"], "AuthenticationFailed");
104}
105
106#[tokio::test]
107#[ignore]
108async fn test_put_record_success() {
109 let client = client();
110 let (token, did) = create_account_and_login(&client).await;
111 let now = Utc::now().to_rfc3339();
112 let payload = json!({
113 "repo": did,
114 "collection": "app.bsky.feed.post",
115 "rkey": "e2e_test_post",
116 "record": {
117 "$type": "app.bsky.feed.post",
118 "text": "Hello from the e2e test script!",
119 "createdAt": now
120 }
121 });
122
123 let res = client.post(format!("{}/xrpc/com.atproto.repo.putRecord", BASE_URL))
124 .bearer_auth(token)
125 .json(&payload)
126 .send()
127 .await
128 .expect("Failed to send request");
129
130 assert_eq!(res.status(), StatusCode::OK);
131 let body: Value = res.json().await.expect("Response was not valid JSON");
132 assert!(body.get("uri").is_some());
133 assert!(body.get("cid").is_some());
134}
135
136#[tokio::test]
137#[ignore]
138async fn test_get_record_missing_params() {
139 let client = client();
140 // Missing `collection` and `rkey`
141 let params = [
142 ("repo", "did:plc:12345"),
143 ];
144
145 let res = client.get(format!("{}/xrpc/com.atproto.repo.getRecord", BASE_URL))
146 .query(¶ms)
147 .send()
148 .await
149 .expect("Failed to send request");
150
151 // This will fail (get 404) until the handler validates query params
152 assert_eq!(res.status(), StatusCode::BAD_REQUEST, "Expected 400 for missing params");
153}
154
155#[tokio::test]
156#[ignore]
157async fn test_upload_blob_bad_token() {
158 let client = client();
159 let res = client.post(format!("{}/xrpc/com.atproto.repo.uploadBlob", BASE_URL))
160 .header(header::CONTENT_TYPE, "text/plain")
161 .bearer_auth(BAD_AUTH_TOKEN)
162 .body("This is our blob data")
163 .send()
164 .await
165 .expect("Failed to send request");
166
167 // This *should* pass if the auth stub is working correctly
168 assert_eq!(res.status(), StatusCode::UNAUTHORIZED);
169 let body: Value = res.json().await.expect("Response was not valid JSON");
170 assert_eq!(body["error"], "AuthenticationFailed");
171}
172
173#[tokio::test]
174#[ignore]
175async fn test_put_record_mismatched_repo() {
176 let client = client();
177 let (token, _) = create_account_and_login(&client).await;
178 let now = Utc::now().to_rfc3339();
179 let payload = json!({
180 "repo": "did:plc:OTHER-USER", // This does NOT match AUTH_DID
181 "collection": "app.bsky.feed.post",
182 "rkey": "e2e_test_post",
183 "record": {
184 "$type": "app.bsky.feed.post",
185 "text": "Hello from the e2e test script!",
186 "createdAt": now
187 }
188 });
189
190 let res = client.post(format!("{}/xrpc/com.atproto.repo.putRecord", BASE_URL))
191 .bearer_auth(token)
192 .json(&payload)
193 .send()
194 .await
195 .expect("Failed to send request");
196
197 // This will fail (get 200) until handler validates repo matches auth
198 assert_eq!(res.status(), StatusCode::FORBIDDEN, "Expected 403 for mismatched repo and auth");
199}
200
201#[tokio::test]
202#[ignore]
203async fn test_put_record_invalid_schema() {
204 let client = client();
205 let (token, did) = create_account_and_login(&client).await;
206 let now = Utc::now().to_rfc3339();
207 let payload = json!({
208 "repo": did,
209 "collection": "app.bsky.feed.post",
210 "rkey": "e2e_test_invalid",
211 "record": {
212 "$type": "app.bsky.feed.post",
213 // "text" field is missing, this is invalid
214 "createdAt": now
215 }
216 });
217
218 let res = client.post(format!("{}/xrpc/com.atproto.repo.putRecord", BASE_URL))
219 .bearer_auth(token)
220 .json(&payload)
221 .send()
222 .await
223 .expect("Failed to send request");
224
225 // This will fail (get 200) until handler validates record schema
226 assert_eq!(res.status(), StatusCode::BAD_REQUEST, "Expected 400 for invalid record schema");
227}
228
229#[tokio::test]
230#[ignore]
231async fn test_upload_blob_unsupported_mime_type() {
232 let client = client();
233 let (token, _) = create_account_and_login(&client).await;
234 let res = client.post(format!("{}/xrpc/com.atproto.repo.uploadBlob", BASE_URL))
235 .header(header::CONTENT_TYPE, "application/xml")
236 .bearer_auth(token)
237 .body("<xml>not an image</xml>")
238 .send()
239 .await
240 .expect("Failed to send request");
241
242 // This will fail (get 200) until handler validates mime type
243 assert_eq!(res.status(), StatusCode::BAD_REQUEST, "Expected 400 for unsupported mime type");
244}
245
246#[tokio::test]
247async fn test_list_records() {
248 let client = client();
249 let (_, did) = create_account_and_login(&client).await;
250 let params = [
251 ("repo", did.as_str()),
252 ("collection", "app.bsky.feed.post"),
253 ("limit", "10"),
254 ];
255 let res = client.get(format!("{}/xrpc/com.atproto.repo.listRecords", BASE_URL))
256 .query(¶ms)
257 .send()
258 .await
259 .expect("Failed to send request");
260
261 assert_eq!(res.status(), StatusCode::OK);
262}
263
264#[tokio::test]
265async fn test_delete_record() {
266 let client = client();
267 let (token, did) = create_account_and_login(&client).await;
268 let payload = json!({
269 "repo": did,
270 "collection": "app.bsky.feed.post",
271 "rkey": "some_post_to_delete"
272 });
273 let res = client.post(format!("{}/xrpc/com.atproto.repo.deleteRecord", BASE_URL))
274 .bearer_auth(token)
275 .json(&payload)
276 .send()
277 .await
278 .expect("Failed to send request");
279
280 assert_eq!(res.status(), StatusCode::OK);
281}
282
283#[tokio::test]
284async fn test_describe_repo() {
285 let client = client();
286 let (_, did) = create_account_and_login(&client).await;
287 let params = [
288 ("repo", did.as_str()),
289 ];
290 let res = client.get(format!("{}/xrpc/com.atproto.repo.describeRepo", BASE_URL))
291 .query(¶ms)
292 .send()
293 .await
294 .expect("Failed to send request");
295
296 assert_eq!(res.status(), StatusCode::OK);
297}
298
299#[tokio::test]
300async fn test_create_record_success_with_generated_rkey() {
301 let client = client();
302 let (token, did) = create_account_and_login(&client).await;
303 let payload = json!({
304 "repo": did,
305 "collection": "app.bsky.feed.post",
306 "record": {
307 "$type": "app.bsky.feed.post",
308 "text": "Hello, world!",
309 "createdAt": "2025-12-02T12:00:00Z"
310 }
311 });
312
313 let res = client.post(format!("{}/xrpc/com.atproto.repo.createRecord", BASE_URL))
314 .json(&payload)
315 .bearer_auth(token) // Assuming auth is required
316 .send()
317 .await
318 .expect("Failed to send request");
319
320 assert_eq!(res.status(), StatusCode::OK);
321 let body: Value = res.json().await.expect("Response was not valid JSON");
322 let uri = body["uri"].as_str().unwrap();
323 assert!(uri.starts_with(&format!("at://{}/app.bsky.feed.post/", did)));
324 // assert_eq!(body["cid"], "bafyreihy"); // CID is now real
325}
326
327#[tokio::test]
328async fn test_create_record_success_with_provided_rkey() {
329 let client = client();
330 let (token, did) = create_account_and_login(&client).await;
331 let rkey = "custom-rkey";
332 let payload = json!({
333 "repo": did,
334 "collection": "app.bsky.feed.post",
335 "rkey": rkey,
336 "record": {
337 "$type": "app.bsky.feed.post",
338 "text": "Hello, world!",
339 "createdAt": "2025-12-02T12:00:00Z"
340 }
341 });
342
343 let res = client.post(format!("{}/xrpc/com.atproto.repo.createRecord", BASE_URL))
344 .json(&payload)
345 .bearer_auth(token) // Assuming auth is required
346 .send()
347 .await
348 .expect("Failed to send request");
349
350 assert_eq!(res.status(), StatusCode::OK);
351 let body: Value = res.json().await.expect("Response was not valid JSON");
352 assert_eq!(body["uri"], format!("at://{}/app.bsky.feed.post/{}", did, rkey));
353 // assert_eq!(body["cid"], "bafyreihy"); // CID is now real
354}