Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Controller session management functions #62

Merged
merged 17 commits into from
Jun 16, 2024
Prev Previous commit
Next Next commit
wip
kariy committed Jun 15, 2024
commit 5a508bebf9a429c1039041720bd8aebe3785defe
19 changes: 17 additions & 2 deletions src/session.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::io;
use std::path::Path;
use std::{fs, path::PathBuf};

use anyhow::Context;
@@ -49,7 +50,7 @@ pub enum Error {
IO(#[from] io::Error),

#[error(transparent)]
Auth(#[from] credential::Error),
Credentials(#[from] credential::Error),

#[error(transparent)]
Serde(#[from] serde_json::Error),
@@ -188,19 +189,33 @@ fn callback_server(tx: Sender<SessionDetails>) -> anyhow::Result<LocalServer> {
fn get_file_path(username: &str, chain_id: FieldElement) -> PathBuf {
// eg 0x12345-session.json
let file_name = format!("{chain_id:#x}-{}", SESSION_FILE_BASE_NAME);

#[cfg(not(test))]
let mut path = dirs::config_local_dir().expect("unsupported OS");
#[cfg(test)]
let mut path = tempfile::tempdir().unwrap().into_path();

path.extend([SLOT_DIR, username, &file_name]);
path
}

#[cfg(test)]
mod tests {
use super::{get, Error};
use crate::credential::Error::Unauthorized;
use starknet::{core::types::FieldElement, macros::felt};

#[test]
fn get_non_existant_session() {}

#[test]
fn get_session_when_not_authenticated() {}
fn get_session_when_not_authenticated() {
let chain = FieldElement::ONE;
let err = get(chain).unwrap_err();
let Error::Credentials(Unauthorized) = err else {
panic!("expected Unauthorized error, got {err:?}");
};
}

#[test]
fn store_session() {}