summaryrefslogtreecommitdiffstats
path: root/rust/tests
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2018-12-28 22:50:47 -0800
committerBryan Newbold <bnewbold@robocracy.org>2018-12-28 22:50:47 -0800
commit156b10220a50f6f441e7484235e227316f26761e (patch)
tree316ccf3a5081b7b43f2a570173d52818acab58f2 /rust/tests
parentd50f7729cbc86c62dba9bd4db80786f07b44a7c0 (diff)
downloadfatcat-156b10220a50f6f441e7484235e227316f26761e.tar.gz
fatcat-156b10220a50f6f441e7484235e227316f26761e.zip
basic auth unittests
Diffstat (limited to 'rust/tests')
-rw-r--r--rust/tests/test_auth.rs48
1 files changed, 48 insertions, 0 deletions
diff --git a/rust/tests/test_auth.rs b/rust/tests/test_auth.rs
new file mode 100644
index 00000000..45956036
--- /dev/null
+++ b/rust/tests/test_auth.rs
@@ -0,0 +1,48 @@
+
+extern crate fatcat;
+extern crate uuid;
+extern crate chrono;
+
+use std::str::FromStr;
+use chrono::prelude::*;
+use fatcat::auth::*;
+use fatcat::api_helpers::*;
+
+#[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
+ let tomorrow = Utc::now() + chrono::Duration::days(1);
+ c.create_token(editor_id, Some(tomorrow)).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).unwrap();
+ assert_eq!(editor_row.id, editor_id.to_uuid());
+
+ // revoke token
+ revoke_tokens(&conn, editor_id);
+
+ // verification should fail
+ assert!(c.parse_macaroon_token(&conn, &token).is_err());
+}