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!(status_body["takedown"].is_null() || !status_body["takedown"]["applied"].as_bool().unwrap_or(false)); 180} 181 182#[tokio::test] 183async fn test_update_subject_status_deactivate_user() { 184 let client = client(); 185 let (access_jwt, did) = create_account_and_login(&client).await; 186 let payload = json!({ 187 "subject": { 188 "$type": "com.atproto.admin.defs#repoRef", 189 "did": did 190 }, 191 "deactivated": { 192 "apply": true 193 } 194 }); 195 let res = client 196 .post(format!( 197 "{}/xrpc/com.atproto.admin.updateSubjectStatus", 198 base_url().await 199 )) 200 .bearer_auth(&access_jwt) 201 .json(&payload) 202 .send() 203 .await 204 .expect("Failed to send request"); 205 assert_eq!(res.status(), StatusCode::OK); 206 let status_res = client 207 .get(format!( 208 "{}/xrpc/com.atproto.admin.getSubjectStatus", 209 base_url().await 210 )) 211 .bearer_auth(&access_jwt) 212 .query(&[("did", did.as_str())]) 213 .send() 214 .await 215 .expect("Failed to send request"); 216 let status_body: Value = status_res.json().await.unwrap(); 217 assert!(status_body["deactivated"].is_object()); 218 assert_eq!(status_body["deactivated"]["applied"], true); 219} 220 221#[tokio::test] 222async fn test_update_subject_status_invalid_type() { 223 let client = client(); 224 let (access_jwt, _did) = create_account_and_login(&client).await; 225 let payload = json!({ 226 "subject": { 227 "$type": "invalid.type", 228 "did": "did:plc:test" 229 }, 230 "takedown": { 231 "apply": true 232 } 233 }); 234 let res = client 235 .post(format!( 236 "{}/xrpc/com.atproto.admin.updateSubjectStatus", 237 base_url().await 238 )) 239 .bearer_auth(&access_jwt) 240 .json(&payload) 241 .send() 242 .await 243 .expect("Failed to send request"); 244 assert_eq!(res.status(), StatusCode::BAD_REQUEST); 245 let body: Value = res.json().await.expect("Response was not valid JSON"); 246 assert_eq!(body["error"], "InvalidRequest"); 247} 248 249#[tokio::test] 250async fn test_update_subject_status_no_auth() { 251 let client = client(); 252 let payload = json!({ 253 "subject": { 254 "$type": "com.atproto.admin.defs#repoRef", 255 "did": "did:plc:test" 256 }, 257 "takedown": { 258 "apply": true 259 } 260 }); 261 let res = client 262 .post(format!( 263 "{}/xrpc/com.atproto.admin.updateSubjectStatus", 264 base_url().await 265 )) 266 .json(&payload) 267 .send() 268 .await 269 .expect("Failed to send request"); 270 assert_eq!(res.status(), StatusCode::UNAUTHORIZED); 271}