icrc/client/src/lib.rs

60 lines
1.6 KiB
Rust

pub mod error;
pub mod session;
pub mod storage;
pub use session::Session;
#[cfg(test)]
mod tests {
use super::*;
use crate::storage::standard::StandardStorage;
use std::str::FromStr;
use uuid::Uuid;
#[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!");
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())
}
#[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!");
let mut session = Session::new(
&host,
None,
StandardStorage::new("sqlite::memory:").await.unwrap(),
)
.await
.unwrap();
session
.auth_with_credentials(Uuid::from_str(&userid).unwrap(), "test")
.await
.unwrap()
}
}