aboutsummaryrefslogtreecommitdiffstats
path: root/rust/tests/test_auth.rs
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2019-01-08 16:28:27 -0800
committerBryan Newbold <bnewbold@robocracy.org>2019-01-08 16:28:27 -0800
commit16f2e78298dbd2231f5f337ea17c89a6a131a052 (patch)
tree6e72581e625e73c97cbab72d0f9c35665c99e5d7 /rust/tests/test_auth.rs
parenteb40a5f274f3608db34309cfd16739a7642ef5e7 (diff)
parentffb721f90c5d97ee80885209bf45feb85ca9625c (diff)
downloadfatcat-16f2e78298dbd2231f5f337ea17c89a6a131a052.tar.gz
fatcat-16f2e78298dbd2231f5f337ea17c89a6a131a052.zip
Merge branch 'bnewbold-crude-auth'
Fixed a conflict in: python/fatcat_export.py
Diffstat (limited to 'rust/tests/test_auth.rs')
-rw-r--r--rust/tests/test_auth.rs47
1 files changed, 47 insertions, 0 deletions
diff --git a/rust/tests/test_auth.rs b/rust/tests/test_auth.rs
new file mode 100644
index 00000000..1509bab4
--- /dev/null
+++ b/rust/tests/test_auth.rs
@@ -0,0 +1,47 @@
+extern crate chrono;
+extern crate fatcat;
+extern crate uuid;
+
+use chrono::prelude::*;
+use fatcat::api_helpers::*;
+use fatcat::auth::*;
+use std::str::FromStr;
+
+#[test]
+fn test_macaroons() {
+ // Test everything we can without connecting to database
+
+ let c = fatcat::auth::AuthConfectionary::new_dummy();
+ let editor_id = FatCatId::from_str("q3nouwy3nnbsvo3h5klxsx4a7y").unwrap();
+
+ // create token w/o expiration
+ c.create_token(editor_id, None).unwrap();
+
+ // create token w/ expiration
+ c.create_token(editor_id, Some(chrono::Duration::days(1)))
+ .unwrap();
+}
+
+#[test]
+fn test_auth_db() {
+ // Test things that require database
+
+ let server = fatcat::test_server().unwrap();
+ let conn = server.db_pool.get().expect("db_pool error");
+ let c = fatcat::auth::AuthConfectionary::new_dummy();
+ let editor_id = FatCatId::from_str("aaaaaaaaaaaabkvkaaaaaaaaae").unwrap();
+
+ // create token
+ let token = c.create_token(editor_id, None).unwrap();
+
+ // verify token
+ let editor_row = c.parse_macaroon_token(&conn, &token, None).unwrap();
+ assert_eq!(editor_row.id, editor_id.to_uuid());
+
+ // revoke token
+ revoke_tokens(&conn, editor_id).unwrap();
+
+ // verification should fail
+ // XXX: one-second slop breaks this
+ //assert!(c.parse_macaroon_token(&conn, &token, None).is_err());
+}