Add Test for lox-distributor
This commit is contained in:
parent
a823dd9ee2
commit
dc8774f5b8
|
@ -22,4 +22,5 @@ serde_with = "3.0.0"
|
|||
serde_json = "1.0.87"
|
||||
|
||||
lox = { path = "../lox-library", version = "0.1.0"}
|
||||
lox_utils = { path = "../lox-utils", version = "0.1.0"}
|
||||
rdsys_backend = { path = "../rdsys-backend-api", version = "0.1.0"}
|
||||
|
|
|
@ -72,3 +72,109 @@ pub async fn handle(
|
|||
},
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
use lox::{BridgeAuth, BridgeDb};
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
trait LoxClient {
|
||||
fn invite(&self) -> Request<Body>;
|
||||
fn reachability(&self) -> Request<Body>;
|
||||
fn pubkeys(&self) -> Request<Body>;
|
||||
}
|
||||
|
||||
struct LoxClientMock {}
|
||||
|
||||
impl LoxClient for LoxClientMock {
|
||||
fn invite(&self) -> Request<Body> {
|
||||
let req = Request::builder()
|
||||
.method("POST")
|
||||
.uri("http://localhost/invite")
|
||||
.body(Body::empty())
|
||||
.unwrap();
|
||||
req
|
||||
}
|
||||
fn reachability(&self) -> Request<Body> {
|
||||
let req = Request::builder()
|
||||
.method("POST")
|
||||
.uri("http://localhost/reachability")
|
||||
.body(Body::empty())
|
||||
.unwrap();
|
||||
req
|
||||
}
|
||||
|
||||
fn pubkeys(&self) -> Request<Body> {
|
||||
let req = Request::builder()
|
||||
.method("POST")
|
||||
.uri("http://localhost/pubkeys")
|
||||
.body(Body::empty())
|
||||
.unwrap();
|
||||
req
|
||||
}
|
||||
}
|
||||
struct TestHarness {
|
||||
context: LoxServerContext,
|
||||
}
|
||||
|
||||
impl TestHarness {
|
||||
fn new() -> Self {
|
||||
let mut bridgedb = BridgeDb::new();
|
||||
let mut lox_auth = BridgeAuth::new(bridgedb.pubkey);
|
||||
|
||||
// Make 3 x num_buckets open invitation bridges, in sets of 3
|
||||
for _ in 0..5 {
|
||||
let bucket = [
|
||||
lox_context::random(),
|
||||
lox_context::random(),
|
||||
lox_context::random(),
|
||||
];
|
||||
lox_auth.add_openinv_bridges(bucket, &mut bridgedb);
|
||||
}
|
||||
|
||||
// Add hot_spare more hot spare buckets
|
||||
for _ in 0..5 {
|
||||
let bucket = [
|
||||
lox_context::random(),
|
||||
lox_context::random(),
|
||||
lox_context::random(),
|
||||
];
|
||||
lox_auth.add_spare_bucket(bucket);
|
||||
}
|
||||
// Create the encrypted bridge table
|
||||
lox_auth.enc_bridge_table();
|
||||
let context = lox_context::LoxServerContext {
|
||||
db: Arc::new(Mutex::new(bridgedb)),
|
||||
ba: Arc::new(Mutex::new(lox_auth)),
|
||||
extra_bridges: Arc::new(Mutex::new(Vec::new())),
|
||||
unreplaced_bridges: Arc::new(Mutex::new(Vec::new())),
|
||||
};
|
||||
Self { context }
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_handle() {
|
||||
let th = TestHarness::new();
|
||||
let lc = LoxClientMock {};
|
||||
// Test Invite
|
||||
let invite_request = lc.invite();
|
||||
let response = handle(th.context.clone(), invite_request).await.unwrap();
|
||||
println!("Server response?: {:?}", response);
|
||||
assert_eq!(response.status(), StatusCode::OK);
|
||||
// Test Reachability
|
||||
let reachability_request = lc.reachability();
|
||||
let reachability_response = handle(th.context.clone(), reachability_request)
|
||||
.await
|
||||
.unwrap();
|
||||
println!("Server response?: {:?}", reachability_response);
|
||||
assert_eq!(reachability_response.status(), StatusCode::OK);
|
||||
// Test Pubkeys
|
||||
let pubkey_request = lc.pubkeys();
|
||||
let pubkey_response = handle(th.context.clone(), pubkey_request).await.unwrap();
|
||||
println!("Server response?: {:?}", pubkey_response);
|
||||
assert_eq!(pubkey_response.status(), StatusCode::OK);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
[package]
|
||||
name = "lox-utils"
|
||||
name = "lox_utils"
|
||||
version = "0.1.0"
|
||||
authors = ["The Tor Project, Inc.", "Lindsey Tulloch <onyinyang@torproject.org"]
|
||||
edition = "2021"
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
use lox::IssuerPubKey;
|
||||
use lox::bridge_table::{BridgeLine, ENC_BUCKET_BYTES};
|
||||
use lox::cred::{Invitation, Lox};
|
||||
use lox::proto;
|
||||
use lox::cred::{Lox, Invitation};
|
||||
use lox::bridge_table::{ENC_BUCKET_BYTES, BridgeLine};
|
||||
use lox::IssuerPubKey;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_with::{serde_as};
|
||||
use serde_with::serde_as;
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub struct OpenReqState {
|
||||
|
|
Loading…
Reference in New Issue