#[cfg(feature = "diesel")]
mod diesel;
mod error;
mod memory;
use super::PendingAuthorization;
#[cfg(feature = "diesel")]
pub use self::diesel::DieselInflightOAuthRequestStore;
pub use error::InflightOAuthRequestStoreError;
pub use memory::MemoryInflightOAuthRequestStore;
pub trait InflightOAuthRequestStore: Sync + Send {
fn insert_request(
&self,
request_id: String,
authorization: PendingAuthorization,
) -> Result<(), InflightOAuthRequestStoreError>;
fn remove_request(
&self,
request_id: &str,
) -> Result<Option<PendingAuthorization>, InflightOAuthRequestStoreError>;
fn clone_box(&self) -> Box<dyn InflightOAuthRequestStore>;
}
impl Clone for Box<dyn InflightOAuthRequestStore> {
fn clone(&self) -> Self {
self.clone_box()
}
}
#[cfg(test)]
mod tests {
use super::*;
pub fn test_request_store_insert_and_remove(
inflight_request_store: &dyn InflightOAuthRequestStore,
) {
inflight_request_store
.insert_request(
"test_request".to_string(),
PendingAuthorization {
pkce_verifier: "this is a pkce_verifier".into(),
client_redirect_url: "http://example.com/someplace/nice".into(),
},
)
.expect("Unable to insert pending request");
let request = inflight_request_store
.remove_request("test_request")
.expect("Unable to remove and return the pending request");
assert_eq!(
Some(PendingAuthorization {
pkce_verifier: "this is a pkce_verifier".into(),
client_redirect_url: "http://example.com/someplace/nice".into(),
}),
request
);
let request = inflight_request_store
.remove_request("test_request")
.expect("Unable to remove and return the pending request");
assert_eq!(None, request);
}
pub fn test_duplicate_id_insert(inflight_request_store: &dyn InflightOAuthRequestStore) {
inflight_request_store
.insert_request(
"test_request".to_string(),
PendingAuthorization {
pkce_verifier: "this is a pkce_verifier".into(),
client_redirect_url: "http://example.com/someplace/nice".into(),
},
)
.expect("Unable to insert pending request");
let err = inflight_request_store
.insert_request(
"test_request".to_string(),
PendingAuthorization {
pkce_verifier: "this is a pkce_verifier".into(),
client_redirect_url: "http://example.com/someplace/nice".into(),
},
)
.expect_err("Should have returned an error");
assert!(matches!(
err,
InflightOAuthRequestStoreError::ConstraintViolation(_)
));
}
}