this repo has no description
1mod common;
2use common::*;
3
4use reqwest::StatusCode;
5use serde_json::{json, Value};
6
7#[tokio::test]
8async fn test_health() {
9 let client = client();
10 let res = client.get(format!("{}/health", BASE_URL))
11 .send()
12 .await
13 .expect("Failed to send request");
14
15 assert_eq!(res.status(), StatusCode::OK);
16 assert_eq!(res.text().await.unwrap(), "OK");
17}
18
19#[tokio::test]
20async fn test_describe_server() {
21 let client = client();
22 let res = client.get(format!("{}/xrpc/com.atproto.server.describeServer", BASE_URL))
23 .send()
24 .await
25 .expect("Failed to send request");
26
27 assert_eq!(res.status(), StatusCode::OK);
28 let body: Value = res.json().await.expect("Response was not valid JSON");
29 assert!(body.get("availableUserDomains").is_some());
30}
31
32#[tokio::test]
33async fn test_create_session() {
34 let client = client();
35
36 let handle = format!("user_{}", uuid::Uuid::new_v4());
37 let payload = json!({
38 "handle": handle,
39 "email": format!("{}@example.com", handle),
40 "password": "password"
41 });
42 let _ = client.post(format!("{}/xrpc/com.atproto.server.createAccount", BASE_URL))
43 .json(&payload)
44 .send()
45 .await;
46
47 let payload = json!({
48 "identifier": handle,
49 "password": "password"
50 });
51
52 let res = client.post(format!("{}/xrpc/com.atproto.server.createSession", BASE_URL))
53 .json(&payload)
54 .send()
55 .await
56 .expect("Failed to send request");
57
58 assert_eq!(res.status(), StatusCode::OK);
59 let body: Value = res.json().await.expect("Response was not valid JSON");
60 assert!(body.get("accessJwt").is_some());
61}
62
63#[tokio::test]
64async fn test_create_session_missing_identifier() {
65 let client = client();
66 let payload = json!({
67 "password": "password"
68 });
69
70 let res = client.post(format!("{}/xrpc/com.atproto.server.createSession", BASE_URL))
71 .json(&payload)
72 .send()
73 .await
74 .expect("Failed to send request");
75
76 assert!(res.status() == StatusCode::BAD_REQUEST || res.status() == StatusCode::UNPROCESSABLE_ENTITY,
77 "Expected 400 or 422 for missing identifier, got {}", res.status());
78}
79
80#[tokio::test]
81async fn test_create_account_invalid_handle() {
82 let client = client();
83 let payload = json!({
84 "handle": "invalid!handle.com",
85 "email": "test@example.com",
86 "password": "password"
87 });
88
89 let res = client.post(format!("{}/xrpc/com.atproto.server.createAccount", BASE_URL))
90 .json(&payload)
91 .send()
92 .await
93 .expect("Failed to send request");
94
95 assert_eq!(res.status(), StatusCode::BAD_REQUEST, "Expected 400 for invalid handle chars");
96}
97
98#[tokio::test]
99async fn test_get_session() {
100 let client = client();
101 let res = client.get(format!("{}/xrpc/com.atproto.server.getSession", BASE_URL))
102 .bearer_auth(AUTH_TOKEN)
103 .send()
104 .await
105 .expect("Failed to send request");
106
107 assert_eq!(res.status(), StatusCode::UNAUTHORIZED);
108}
109
110#[tokio::test]
111async fn test_refresh_session() {
112 let client = client();
113
114 let handle = format!("refresh_user_{}", uuid::Uuid::new_v4());
115 let payload = json!({
116 "handle": handle,
117 "email": format!("{}@example.com", handle),
118 "password": "password"
119 });
120 let _ = client.post(format!("{}/xrpc/com.atproto.server.createAccount", BASE_URL))
121 .json(&payload)
122 .send()
123 .await;
124
125 let login_payload = json!({
126 "identifier": handle,
127 "password": "password"
128 });
129 let res = client.post(format!("{}/xrpc/com.atproto.server.createSession", BASE_URL))
130 .json(&login_payload)
131 .send()
132 .await
133 .expect("Failed to login");
134
135 assert_eq!(res.status(), StatusCode::OK);
136 let body: Value = res.json().await.expect("Invalid JSON");
137 let refresh_jwt = body["refreshJwt"].as_str().expect("No refreshJwt").to_string();
138 let access_jwt = body["accessJwt"].as_str().expect("No accessJwt").to_string();
139
140 let res = client.post(format!("{}/xrpc/com.atproto.server.refreshSession", BASE_URL))
141 .bearer_auth(&refresh_jwt)
142 .send()
143 .await
144 .expect("Failed to refresh");
145
146 assert_eq!(res.status(), StatusCode::OK);
147 let body: Value = res.json().await.expect("Invalid JSON");
148 assert!(body["accessJwt"].as_str().is_some());
149 assert!(body["refreshJwt"].as_str().is_some());
150 assert_ne!(body["accessJwt"].as_str().unwrap(), access_jwt);
151 assert_ne!(body["refreshJwt"].as_str().unwrap(), refresh_jwt);
152}
153
154#[tokio::test]
155async fn test_delete_session() {
156 let client = client();
157 let res = client.post(format!("{}/xrpc/com.atproto.server.deleteSession", BASE_URL))
158 .bearer_auth(AUTH_TOKEN)
159 .send()
160 .await
161 .expect("Failed to send request");
162
163 assert_eq!(res.status(), StatusCode::UNAUTHORIZED);
164}