Skip to content
This repository has been archived by the owner on Dec 17, 2024. It is now read-only.

Commit

Permalink
correct query and add parse error test
Browse files Browse the repository at this point in the history
  • Loading branch information
musitdev committed Mar 6, 2024
1 parent 506a6b3 commit fdd2757
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
25 changes: 25 additions & 0 deletions crates/node/src/networking/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,4 +237,29 @@ mod tests {
assert!(set.get("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8").is_some());
}
}

#[tokio::test]
async fn test_acl_merge_with_keyparseerror() {
let db = TestDb(Mutex::new(HashSet::new()));
{
let mut set = db.0.lock().await;
set.insert("0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8".to_string());
}

let to_merge_acl = vec![
Ok("043a1d3d3bfa8b91b18be20009f58616683695765c90c37a404af7635a3e047de50ee62b5da0c02a1ba54489294974aa6a3733ec82e34c8f6a26c29d6aa000e88d\n".as_bytes()),
Ok("0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n".as_bytes()),
Ok("040f28123df7a638647d867dfe186395999a276048c76c1bd56d4b792eca56449751944d6cd0b208f44b9aec332b4b6d0630406ebb07ccfb17e7c505a07156a792\n".as_bytes()),
];
let reader = StreamReader::new(tokio_stream::iter(to_merge_acl));
let res = merge_acl_white_list(reader, &db).await;

assert!(res.is_ok());
{
let set = db.0.lock().await;
assert_eq!(2, set.len());
assert!(set.get("043a1d3d3bfa8b91b18be20009f58616683695765c90c37a404af7635a3e047de50ee62b5da0c02a1ba54489294974aa6a3733ec82e34c8f6a26c29d6aa000e88d").is_some());
assert!(set.get("040f28123df7a638647d867dfe186395999a276048c76c1bd56d4b792eca56449751944d6cd0b208f44b9aec332b4b6d0630406ebb07ccfb17e7c505a07156a792").is_some());
}
}
}
2 changes: 1 addition & 1 deletion crates/node/src/storage/database/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ impl Database {
}

pub async fn get_acl_whitelist(&self) -> Result<Vec<entity::PublicKey>> {
let dbkey_set: Vec<entity::PublicKey> = sqlx::query("SELECT 1 FROM acl_whitelist")
let dbkey_set: Vec<entity::PublicKey> = sqlx::query("SELECT key FROM acl_whitelist")
.map(|row: sqlx::postgres::PgRow| row.get(0))
.fetch_all(&self.pool)
.await?;
Expand Down

0 comments on commit fdd2757

Please sign in to comment.