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