this repo has no description
1mod common;
2use common::*;
3use reqwest::StatusCode;
4use serde_json::{json, Value};
5
6// #[tokio::test]
7// async fn test_resolve_handle() {
8// let client = client();
9// let params = [
10// ("handle", "bsky.app"),
11// ];
12// let res = client.get(format!("{}/xrpc/com.atproto.identity.resolveHandle", base_url().await))
13// .query(¶ms)
14// .send()
15// .await
16// .expect("Failed to send request");
17//
18// assert_eq!(res.status(), StatusCode::OK);
19// }
20
21#[tokio::test]
22async fn test_well_known_did() {
23 let client = client();
24 let res = client.get(format!("{}/.well-known/did.json", base_url().await))
25 .send()
26 .await
27 .expect("Failed to send request");
28
29 assert_eq!(res.status(), StatusCode::OK);
30 let body: Value = res.json().await.expect("Response was not valid JSON");
31 assert!(body["id"].as_str().unwrap().starts_with("did:web:"));
32 assert_eq!(body["service"][0]["type"], "AtprotoPersonalDataServer");
33}
34
35#[tokio::test]
36async fn test_create_did_web_account_and_resolve() {
37 let client = client();
38
39 let handle = format!("webuser_{}", uuid::Uuid::new_v4());
40
41 let did = format!("did:web:example.com:u:{}", handle);
42
43 let payload = json!({
44 "handle": handle,
45 "email": format!("{}@example.com", handle),
46 "password": "password",
47 "did": did
48 });
49
50 let res = client.post(format!("{}/xrpc/com.atproto.server.createAccount", base_url().await))
51 .json(&payload)
52 .send()
53 .await
54 .expect("Failed to send request");
55
56 assert_eq!(res.status(), StatusCode::OK);
57 let body: Value = res.json().await.expect("createAccount response was not JSON");
58 assert_eq!(body["did"], did);
59
60 let res = client.get(format!("{}/u/{}/did.json", base_url().await, handle))
61 .send()
62 .await
63 .expect("Failed to fetch DID doc");
64
65 assert_eq!(res.status(), StatusCode::OK);
66 let doc: Value = res.json().await.expect("DID doc was not JSON");
67
68 assert_eq!(doc["id"], did);
69 assert_eq!(doc["alsoKnownAs"][0], format!("at://{}", handle));
70 assert_eq!(doc["verificationMethod"][0]["controller"], did);
71 assert!(doc["verificationMethod"][0]["publicKeyJwk"].is_object());
72}
73
74#[tokio::test]
75async fn test_create_account_duplicate_handle() {
76 let client = client();
77 let handle = format!("dupe_{}", uuid::Uuid::new_v4());
78 let email = format!("{}@example.com", handle);
79
80 let payload = json!({
81 "handle": handle,
82 "email": email,
83 "password": "password"
84 });
85
86 let res = client.post(format!("{}/xrpc/com.atproto.server.createAccount", base_url().await))
87 .json(&payload)
88 .send()
89 .await
90 .expect("Failed to send request");
91 assert_eq!(res.status(), StatusCode::OK);
92
93 let res = client.post(format!("{}/xrpc/com.atproto.server.createAccount", base_url().await))
94 .json(&payload)
95 .send()
96 .await
97 .expect("Failed to send request");
98
99 assert_eq!(res.status(), StatusCode::BAD_REQUEST);
100 let body: Value = res.json().await.expect("Response was not JSON");
101 assert_eq!(body["error"], "HandleTaken");
102}
103
104#[tokio::test]
105async fn test_did_web_lifecycle() {
106 let client = client();
107 let handle = format!("lifecycle_{}", uuid::Uuid::new_v4());
108 let did = format!("did:web:localhost:u:{}", handle);
109 let email = format!("{}@test.com", handle);
110
111 let create_payload = json!({
112 "handle": handle,
113 "email": email,
114 "password": "password",
115 "did": did
116 });
117
118 let res = client.post(format!("{}/xrpc/com.atproto.server.createAccount", base_url().await))
119 .json(&create_payload)
120 .send()
121 .await
122 .expect("Failed createAccount");
123
124 if res.status() != StatusCode::OK {
125 let body: Value = res.json().await.unwrap();
126 println!("createAccount failed: {:?}", body);
127 panic!("createAccount returned non-200");
128 }
129 assert_eq!(res.status(), StatusCode::OK);
130 let create_body: Value = res.json().await.expect("Not JSON");
131 assert_eq!(create_body["did"], did);
132
133 let login_payload = json!({
134 "identifier": handle,
135 "password": "password"
136 });
137 let res = client.post(format!("{}/xrpc/com.atproto.server.createSession", base_url().await))
138 .json(&login_payload)
139 .send()
140 .await
141 .expect("Failed createSession");
142
143 assert_eq!(res.status(), StatusCode::OK);
144 let session_body: Value = res.json().await.expect("Not JSON");
145 let _jwt = session_body["accessJwt"].as_str().unwrap();
146
147 /*
148 let profile_payload = json!({
149 "repo": did,
150 "collection": "app.bsky.actor.profile",
151 "rkey": "self",
152 "record": {
153 "$type": "app.bsky.actor.profile",
154 "displayName": "DID Web User",
155 "description": "Testing lifecycle"
156 }
157 });
158
159 let res = client.post(format!("{}/xrpc/com.atproto.repo.putRecord", base_url().await))
160 .bearer_auth(_jwt)
161 .json(&profile_payload)
162 .send()
163 .await
164 .expect("Failed putRecord");
165
166 if res.status() != StatusCode::OK {
167 let body: Value = res.json().await.unwrap();
168 println!("putRecord failed: {:?}", body);
169 panic!("putRecord returned non-200");
170 }
171 assert_eq!(res.status(), StatusCode::OK);
172
173 let res = client.get(format!("{}/xrpc/com.atproto.repo.getRecord", base_url().await))
174 .query(&[
175 ("repo", &handle),
176 ("collection", &"app.bsky.actor.profile".to_string()),
177 ("rkey", &"self".to_string())
178 ])
179 .send()
180 .await
181 .expect("Failed getRecord");
182
183 if res.status() != StatusCode::OK {
184 let body: Value = res.json().await.unwrap();
185 println!("getRecord failed: {:?}", body);
186 panic!("getRecord returned non-200");
187 }
188 let record_body: Value = res.json().await.expect("Not JSON");
189 assert_eq!(record_body["value"]["displayName"], "DID Web User");
190 */
191}