From 156b10220a50f6f441e7484235e227316f26761e Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Fri, 28 Dec 2018 22:50:47 -0800 Subject: basic auth unittests --- rust/src/api_helpers.rs | 2 +- rust/src/auth.rs | 5 +---- rust/src/bin/fatcat-auth.rs | 6 +++++- 3 files changed, 7 insertions(+), 6 deletions(-) (limited to 'rust/src') diff --git a/rust/src/api_helpers.rs b/rust/src/api_helpers.rs index da208c0a..3c5a2e17 100644 --- a/rust/src/api_helpers.rs +++ b/rust/src/api_helpers.rs @@ -294,7 +294,7 @@ pub fn accept_editgroup(editgroup_id: FatCatId, conn: &DbConn) -> Result>) -> Result { - let _ed: EditorRow = editor::table - .find(&editor_id.to_uuid()) - .get_result(conn)?; + pub fn create_token(&self, editor_id: FatCatId, expires: Option>) -> Result { let mut mac = Macaroon::create(&self.location, &self.key, &self.identifier).expect("Macaroon creation"); mac.add_first_party_caveat(&format!("editor_id = {}", editor_id.to_string())); // TODO: put created one second in the past to prevent timing synchronization glitches? diff --git a/rust/src/bin/fatcat-auth.rs b/rust/src/bin/fatcat-auth.rs index 4b90da74..5a8f0f98 100644 --- a/rust/src/bin/fatcat-auth.rs +++ b/rust/src/bin/fatcat-auth.rs @@ -106,7 +106,11 @@ fn run() -> Result<()> { }, ("create-token", Some(subm)) => { let editor_id = FatCatId::from_str(subm.value_of("editor-id").unwrap())?; - println!("{}", confectionary.create_token(&db_conn, editor_id, None)?); + // check that editor exists + let _ed: fatcat::database_models::EditorRow = fatcat::database_schema::editor::table + .find(&editor_id.to_uuid()) + .get_result(&db_conn)?; + println!("{}", confectionary.create_token(editor_id, None)?); }, ("inspect-token", Some(subm)) => { confectionary.inspect_token(&db_conn, subm.value_of("token").unwrap())?; -- cgit v1.2.3