this repo has no description
1mod common;
2
3use common::*;
4use reqwest::StatusCode;
5use serde_json::{Value, json};
6
7#[tokio::test]
8async fn test_get_subject_status_user_success() {
9 let client = client();
10 let (access_jwt, did) = create_account_and_login(&client).await;
11 let res = client
12 .get(format!(
13 "{}/xrpc/com.atproto.admin.getSubjectStatus",
14 base_url().await
15 ))
16 .bearer_auth(&access_jwt)
17 .query(&[("did", did.as_str())])
18 .send()
19 .await
20 .expect("Failed to send request");
21 assert_eq!(res.status(), StatusCode::OK);
22 let body: Value = res.json().await.expect("Response was not valid JSON");
23 assert!(body["subject"].is_object());
24 assert_eq!(body["subject"]["$type"], "com.atproto.admin.defs#repoRef");
25 assert_eq!(body["subject"]["did"], did);
26}
27
28#[tokio::test]
29async fn test_get_subject_status_not_found() {
30 let client = client();
31 let (access_jwt, _did) = create_account_and_login(&client).await;
32 let res = client
33 .get(format!(
34 "{}/xrpc/com.atproto.admin.getSubjectStatus",
35 base_url().await
36 ))
37 .bearer_auth(&access_jwt)
38 .query(&[("did", "did:plc:nonexistent")])
39 .send()
40 .await
41 .expect("Failed to send request");
42 assert_eq!(res.status(), StatusCode::NOT_FOUND);
43 let body: Value = res.json().await.expect("Response was not valid JSON");
44 assert_eq!(body["error"], "SubjectNotFound");
45}
46
47#[tokio::test]
48async fn test_get_subject_status_no_param() {
49 let client = client();
50 let (access_jwt, _did) = create_account_and_login(&client).await;
51 let res = client
52 .get(format!(
53 "{}/xrpc/com.atproto.admin.getSubjectStatus",
54 base_url().await
55 ))
56 .bearer_auth(&access_jwt)
57 .send()
58 .await
59 .expect("Failed to send request");
60 assert_eq!(res.status(), StatusCode::BAD_REQUEST);
61 let body: Value = res.json().await.expect("Response was not valid JSON");
62 assert_eq!(body["error"], "InvalidRequest");
63}
64
65#[tokio::test]
66async fn test_get_subject_status_no_auth() {
67 let client = client();
68 let res = client
69 .get(format!(
70 "{}/xrpc/com.atproto.admin.getSubjectStatus",
71 base_url().await
72 ))
73 .query(&[("did", "did:plc:test")])
74 .send()
75 .await
76 .expect("Failed to send request");
77 assert_eq!(res.status(), StatusCode::UNAUTHORIZED);
78}
79
80#[tokio::test]
81async fn test_update_subject_status_takedown_user() {
82 let client = client();
83 let (access_jwt, did) = create_account_and_login(&client).await;
84 let payload = json!({
85 "subject": {
86 "$type": "com.atproto.admin.defs#repoRef",
87 "did": did
88 },
89 "takedown": {
90 "apply": true,
91 "ref": "mod-action-123"
92 }
93 });
94 let res = client
95 .post(format!(
96 "{}/xrpc/com.atproto.admin.updateSubjectStatus",
97 base_url().await
98 ))
99 .bearer_auth(&access_jwt)
100 .json(&payload)
101 .send()
102 .await
103 .expect("Failed to send request");
104 assert_eq!(res.status(), StatusCode::OK);
105 let body: Value = res.json().await.expect("Response was not valid JSON");
106 assert!(body["takedown"].is_object());
107 assert_eq!(body["takedown"]["applied"], true);
108 assert_eq!(body["takedown"]["ref"], "mod-action-123");
109 let status_res = client
110 .get(format!(
111 "{}/xrpc/com.atproto.admin.getSubjectStatus",
112 base_url().await
113 ))
114 .bearer_auth(&access_jwt)
115 .query(&[("did", did.as_str())])
116 .send()
117 .await
118 .expect("Failed to send request");
119 let status_body: Value = status_res.json().await.unwrap();
120 assert!(status_body["takedown"].is_object());
121 assert_eq!(status_body["takedown"]["applied"], true);
122 assert_eq!(status_body["takedown"]["ref"], "mod-action-123");
123}
124
125#[tokio::test]
126async fn test_update_subject_status_remove_takedown() {
127 let client = client();
128 let (access_jwt, did) = create_account_and_login(&client).await;
129 let takedown_payload = json!({
130 "subject": {
131 "$type": "com.atproto.admin.defs#repoRef",
132 "did": did
133 },
134 "takedown": {
135 "apply": true,
136 "ref": "mod-action-456"
137 }
138 });
139 let _ = client
140 .post(format!(
141 "{}/xrpc/com.atproto.admin.updateSubjectStatus",
142 base_url().await
143 ))
144 .bearer_auth(&access_jwt)
145 .json(&takedown_payload)
146 .send()
147 .await;
148 let remove_payload = json!({
149 "subject": {
150 "$type": "com.atproto.admin.defs#repoRef",
151 "did": did
152 },
153 "takedown": {
154 "apply": false
155 }
156 });
157 let res = client
158 .post(format!(
159 "{}/xrpc/com.atproto.admin.updateSubjectStatus",
160 base_url().await
161 ))
162 .bearer_auth(&access_jwt)
163 .json(&remove_payload)
164 .send()
165 .await
166 .expect("Failed to send request");
167 assert_eq!(res.status(), StatusCode::OK);
168 let status_res = client
169 .get(format!(
170 "{}/xrpc/com.atproto.admin.getSubjectStatus",
171 base_url().await
172 ))
173 .bearer_auth(&access_jwt)
174 .query(&[("did", did.as_str())])
175 .send()
176 .await
177 .expect("Failed to send request");
178 let status_body: Value = status_res.json().await.unwrap();
179 assert!(
180 status_body["takedown"].is_null()
181 || !status_body["takedown"]["applied"]
182 .as_bool()
183 .unwrap_or(false)
184 );
185}
186
187#[tokio::test]
188async fn test_update_subject_status_deactivate_user() {
189 let client = client();
190 let (access_jwt, did) = create_account_and_login(&client).await;
191 let payload = json!({
192 "subject": {
193 "$type": "com.atproto.admin.defs#repoRef",
194 "did": did
195 },
196 "deactivated": {
197 "apply": true
198 }
199 });
200 let res = client
201 .post(format!(
202 "{}/xrpc/com.atproto.admin.updateSubjectStatus",
203 base_url().await
204 ))
205 .bearer_auth(&access_jwt)
206 .json(&payload)
207 .send()
208 .await
209 .expect("Failed to send request");
210 assert_eq!(res.status(), StatusCode::OK);
211 let status_res = client
212 .get(format!(
213 "{}/xrpc/com.atproto.admin.getSubjectStatus",
214 base_url().await
215 ))
216 .bearer_auth(&access_jwt)
217 .query(&[("did", did.as_str())])
218 .send()
219 .await
220 .expect("Failed to send request");
221 let status_body: Value = status_res.json().await.unwrap();
222 assert!(status_body["deactivated"].is_object());
223 assert_eq!(status_body["deactivated"]["applied"], true);
224}
225
226#[tokio::test]
227async fn test_update_subject_status_invalid_type() {
228 let client = client();
229 let (access_jwt, _did) = create_account_and_login(&client).await;
230 let payload = json!({
231 "subject": {
232 "$type": "invalid.type",
233 "did": "did:plc:test"
234 },
235 "takedown": {
236 "apply": true
237 }
238 });
239 let res = client
240 .post(format!(
241 "{}/xrpc/com.atproto.admin.updateSubjectStatus",
242 base_url().await
243 ))
244 .bearer_auth(&access_jwt)
245 .json(&payload)
246 .send()
247 .await
248 .expect("Failed to send request");
249 assert_eq!(res.status(), StatusCode::BAD_REQUEST);
250 let body: Value = res.json().await.expect("Response was not valid JSON");
251 assert_eq!(body["error"], "InvalidRequest");
252}
253
254#[tokio::test]
255async fn test_update_subject_status_no_auth() {
256 let client = client();
257 let payload = json!({
258 "subject": {
259 "$type": "com.atproto.admin.defs#repoRef",
260 "did": "did:plc:test"
261 },
262 "takedown": {
263 "apply": true
264 }
265 });
266 let res = client
267 .post(format!(
268 "{}/xrpc/com.atproto.admin.updateSubjectStatus",
269 base_url().await
270 ))
271 .json(&payload)
272 .send()
273 .await
274 .expect("Failed to send request");
275 assert_eq!(res.status(), StatusCode::UNAUTHORIZED);
276}