Skip to content

Commit 341d7da

Browse files
authored
Merge pull request #52 from TheRipperoni/fix/bskychat
PDS: Fix API Request forwarding for BSky APIs by @TheRipperoni
2 parents 3e30782 + 2355479 commit 341d7da

File tree

6 files changed

+168
-491
lines changed

6 files changed

+168
-491
lines changed

rsky-common/src/lib.rs

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ pub fn get_service_endpoint(doc: DidDocument, opts: GetServiceEndpointOpts) -> O
141141
match found {
142142
None => None,
143143
Some(found) => match opts.r#type {
144-
None => None,
144+
None => validate_url(&found.service_endpoint),
145145
Some(opts_type) if found.r#type == opts_type => {
146146
validate_url(&found.service_endpoint)
147147
}
@@ -175,3 +175,49 @@ pub mod ipld;
175175
pub mod sign;
176176
pub mod tid;
177177
pub mod time;
178+
179+
#[cfg(test)]
180+
mod tests {
181+
use crate::{get_service_endpoint, validate_url, GetServiceEndpointOpts};
182+
use rsky_identity::types::{DidDocument, Service};
183+
184+
#[test]
185+
fn test_validate_url_when_invalid() {
186+
let text = "rsky.com".to_string();
187+
let result = validate_url(&text);
188+
assert_eq!(result, None);
189+
}
190+
191+
#[test]
192+
fn test_validate_url_when_valid() {
193+
let text = "https://rsky.com".to_string();
194+
let result = validate_url(&text);
195+
assert_eq!(result.is_some(), true);
196+
}
197+
198+
#[test]
199+
fn test_get_service_endpoint() {
200+
let text = "https://rsky.com".to_string();
201+
let result = validate_url(&text);
202+
203+
let mut service = Vec::new();
204+
service.push(Service {
205+
id: "#bsky_chat".to_string(),
206+
r#type: "BskyChatService".to_string(),
207+
service_endpoint: "https://api.bsky.chat".to_string(),
208+
});
209+
let doc = DidDocument {
210+
context: None,
211+
id: "#bsky_chat".to_string(),
212+
also_known_as: None,
213+
verification_method: None,
214+
service: Some(service),
215+
};
216+
let opts = GetServiceEndpointOpts {
217+
id: "#bsky_chat".to_string(),
218+
r#type: Some("BskyChatService".to_string()),
219+
};
220+
let result = get_service_endpoint(doc, opts);
221+
assert_eq!(result.is_some(), true);
222+
}
223+
}

0 commit comments

Comments
 (0)