summaryrefslogtreecommitdiffstats
path: root/tests/storage.rs
diff options
context:
space:
mode:
authorsalmonik <salmonik@tuta.io>2026-08-24 15:27:06 +0200
committersalmonik <salmonik@tuta.io>2026-08-24 15:27:06 +0200
commit8218fd584e4053848738a310258893e14c4ee10e (patch)
tree2c92997ba0b6aa260fe72c88190f5f8b590457cb /tests/storage.rs
parentTLS transport and games framework on client and server (diff)
downloadzagan-bet-8218fd584e4053848738a310258893e14c4ee10e.tar.gz
zagan-bet-8218fd584e4053848738a310258893e14c4ee10e.zip
TOFU host trust: SPKI fingerprint pinning, tests, forget-host
Diffstat (limited to '')
-rw-r--r--tests/storage.rs61
1 files changed, 61 insertions, 0 deletions
diff --git a/tests/storage.rs b/tests/storage.rs
new file mode 100644
index 0000000..275d47d
--- /dev/null
+++ b/tests/storage.rs
@@ -0,0 +1,61 @@
1//! Tests for storage layers that already exist. These must PASS.
2
3use std::path::PathBuf;
4
5use zagan_bet::client_database;
6use zagan_bet::server_database;
7
8fn tmp_db(name: &str) -> (String, rusqlite::Connection) {
9 let path = PathBuf::from(env!("CARGO_TARGET_TMPDIR"))
10 .join(format!("storage-{name}.db"))
11 .to_string_lossy()
12 .into_owned();
13 let _ = std::fs::remove_file(&path);
14 let conn = rusqlite::Connection::open(&path).unwrap();
15 (path, conn)
16}
17
18#[test]
19fn client_credentials_roundtrip() {
20 let (_, conn) = tmp_db("creds");
21 client_database::init_db(&conn);
22
23 assert_eq!(client_database::get_credentials(&conn, "h1"), None);
24 client_database::save_credentials(&conn, "h1", "alice", "pw").unwrap();
25 assert_eq!(
26 client_database::get_credentials(&conn, "h1"),
27 Some(("alice".to_string(), "pw".to_string()))
28 );
29 // Overwrite works.
30 client_database::save_credentials(&conn, "h1", "alice", "pw2").unwrap();
31 assert_eq!(
32 client_database::get_credentials(&conn, "h1"),
33 Some(("alice".to_string(), "pw2".to_string()))
34 );
35}
36
37#[test]
38fn client_last_host_tracking() {
39 let (_, conn) = tmp_db("hosts");
40 client_database::init_db(&conn);
41
42 assert_eq!(client_database::get_last_host(&conn), None);
43 client_database::save_host(&conn, "example.com:9000");
44 assert_eq!(
45 client_database::get_last_host(&conn),
46 Some("example.com:9000".to_string())
47 );
48}
49
50#[test]
51fn server_user_registration_and_auth_lookup() {
52 let (_, conn) = tmp_db("users");
53 server_database::init_db(&conn);
54
55 server_database::add_user(&conn, "bob", "cafebabe").unwrap();
56 assert_eq!(
57 server_database::get_hashed_password(&conn, "bob"),
58 Some("cafebabe".to_string())
59 );
60 assert_eq!(server_database::get_hashed_password(&conn, "nobody"), None);
61}