2024-03-31 18:44:00 +00:00
|
|
|
pub mod error;
|
|
|
|
pub mod session;
|
|
|
|
pub mod storage;
|
2024-03-31 15:02:21 +00:00
|
|
|
|
|
|
|
pub use session::Session;
|
2024-03-31 10:13:56 +00:00
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
2024-03-31 21:15:28 +00:00
|
|
|
use crate::storage::standard::StandardStorage;
|
2024-03-31 15:55:53 +00:00
|
|
|
use std::str::FromStr;
|
|
|
|
use uuid::Uuid;
|
2024-03-31 10:13:56 +00:00
|
|
|
|
2024-03-31 15:02:21 +00:00
|
|
|
#[tokio::test]
|
|
|
|
async fn authorized_session() {
|
|
|
|
let host = std::env::var("ICRC_TEST_HOST")
|
|
|
|
.expect("The environment variable ICRC_TEST_HOST needs to be set!");
|
|
|
|
let token = std::env::var("ICRC_TEST_AUTH")
|
|
|
|
.expect("The environment variable ICRC_TEST_AUTH needs to be set!");
|
|
|
|
|
2024-03-31 21:15:28 +00:00
|
|
|
let _session = Session::new(
|
|
|
|
&host,
|
|
|
|
Some(token),
|
|
|
|
StandardStorage::new("sqlite:test.db").await.unwrap(),
|
|
|
|
)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
let new_session = Session::new(
|
|
|
|
&host,
|
|
|
|
None,
|
|
|
|
StandardStorage::new("sqlite:test.db").await.unwrap(),
|
|
|
|
)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
assert!(new_session.is_authorized())
|
2024-03-31 15:55:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[tokio::test]
|
|
|
|
async fn authenticate() {
|
|
|
|
let host = std::env::var("ICRC_TEST_HOST")
|
|
|
|
.expect("The environment variable ICRC_TEST_HOST needs to be set!");
|
|
|
|
let userid = std::env::var("ICRC_TEST_USER")
|
|
|
|
.expect("The environment variable ICRC_TEST_USER needs to be set!");
|
2024-03-31 15:02:21 +00:00
|
|
|
|
2024-03-31 21:15:28 +00:00
|
|
|
let mut session = Session::new(
|
|
|
|
&host,
|
|
|
|
None,
|
|
|
|
StandardStorage::new("sqlite::memory:").await.unwrap(),
|
|
|
|
)
|
|
|
|
.await
|
|
|
|
.unwrap();
|
2024-03-31 15:55:53 +00:00
|
|
|
session
|
2024-03-31 16:12:37 +00:00
|
|
|
.auth_with_credentials(Uuid::from_str(&userid).unwrap(), "test")
|
2024-03-31 15:55:53 +00:00
|
|
|
.await
|
|
|
|
.unwrap()
|
2024-03-31 10:13:56 +00:00
|
|
|
}
|
|
|
|
}
|