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