Skip to content

Commit

Permalink
making a basic test for a webauthn object from a chrome extension (#289)
Browse files Browse the repository at this point in the history
  • Loading branch information
yaleman authored Mar 13, 2023
1 parent aded3a8 commit e9ebff3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
9 changes: 7 additions & 2 deletions webauthn-rs-core/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1157,6 +1157,11 @@ impl WebauthnCore {
true
}
}

/// Returns the RP name
pub fn rp_name(&self) -> &str {
self.rp_name.as_str()
}
}

/*
Expand Down Expand Up @@ -1710,7 +1715,7 @@ mod tests {
"rawId":"at-FfKGsOI21EhtCu7Vx-7t7FKkpUOyKXIkEBBD_vC-eym_AdW6Y9V8WyKxHmii11EBQEe7uFQ0bkYwb0GWmUQ",
"extensions": {
"appid": true
},
},
"response":{
"authenticatorData":"SZYN5YgOjGh0NBcPZHZgW4_krrmihjLHmVzzuoMdl2MBAAAAFA",
"clientDataJSON":"eyJjaGFsbGVuZ2UiOiJXZ1h6X2tUdjNXVVUxa3c4aG0tT0dvR1M0WkNIWF8zYkVxSEgyUHZWcDhNIiwiY2xpZW50RXh0ZW5zaW9ucyI6e30sImhhc2hBbGdvcml0aG0iOiJTSEEtMjU2Iiwib3JpZ2luIjoiaHR0cDovL2xvY2FsaG9zdDo4MDgwIiwidHlwZSI6IndlYmF1dGhuLmdldCJ9",
Expand Down Expand Up @@ -3564,7 +3569,7 @@ mod tests {
{
"type": "public-key",
"alg": -7
}
}
],
"authenticatorSelection": {
"authenticatorAttachment": "platform",
Expand Down
13 changes: 13 additions & 0 deletions webauthn-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1225,3 +1225,16 @@ impl Webauthn {
self.core.authenticate_credential(reg, &state.ast)
}
}

#[test]
/// Test that building a webauthn object from a chrome extension origin is successful.
fn test_webauthnbuilder_chrome_url() {
use crate::prelude::*;
let rp_id = "2114c9f524d0cbd74dbe846a51c3e5b34b83ac02c5220ec5cdff751096fa25a5";
let rp_origin = Url::parse(&format!("chrome-extension://{rp_id}")).expect("Invalid URL");
eprintln!("{rp_origin:?}");
let builder = WebauthnBuilder::new(rp_id, &rp_origin).expect("Invalid configuration");
eprintln!("rp_id: {:?}", builder.rp_id);
let built = builder.build().expect("Failed to build");
eprintln!("rp_name: {}", built.core.rp_name());
}

0 comments on commit e9ebff3

Please sign in to comment.