pull/146/head
Chip Senkbeil 2 years ago
parent 443326af62
commit d81b5df330
No known key found for this signature in database
GPG Key ID: 35EF1F8EC72A4131

@ -80,6 +80,11 @@ impl<T> Keychain<T> {
.map(|(_, data)| data)
}
/// Checks if there is an `id` stored within the keychain.
pub async fn has_id(&self, id: impl AsRef<str>) -> bool {
self.map.read().await.contains_key(id.as_ref())
}
/// Checks if there is a key with the given `id` that matches the provided `key`.
pub async fn has_key(&self, id: impl AsRef<str>, key: impl PartialEq<HeapSecretKey>) -> bool {
self.map

@ -857,6 +857,53 @@ mod tests {
let (mut t1, t2) = FramedTransport::pair(100);
let verifier = Verifier::none();
let keychain = Keychain::new();
// Spawn a task to perform the server connection so we don't deadlock while simulating the
// client actions on the other side
let task = tokio::spawn({
let keychain = keychain.clone();
async move {
Connection::server(t2.into_inner(), &verifier, keychain)
.await
.unwrap()
}
});
// Perform first step of completing client-side of handshake
t1.client_handshake().await.unwrap();
// Send type to indicate a new connection
t1.write_frame_for(&ConnectType::Connect).await.unwrap();
// Receive the connection id
let id = t1.read_frame_as::<ConnectionId>().await.unwrap().unwrap();
// Pass verification using the dummy handler since our verifier supports no authentication
t1.authenticate(DummyAuthHandler).await.unwrap();
// Perform otp exchange
let otp = t1.exchange_keys().await.unwrap();
// Server connection should be established, and have received some replayed frames
let server = task.await.unwrap();
// Validate the connection ids match
assert_eq!(server.id(), id);
// Validate the OTP was stored in our keychain
assert!(
keychain
.has_key(id.to_string(), otp.into_heap_secret_key())
.await,
"Missing OTP"
);
}
#[test(tokio::test)]
async fn server_should_succeed_if_establishes_connection_with_existing_client() {
let (mut t1, t2) = FramedTransport::pair(100);
let verifier = Verifier::none();
let keychain = Keychain::new();
let key = HeapSecretKey::generate(32).unwrap();
keychain
@ -926,23 +973,18 @@ mod tests {
// Validate the connection ids match
assert_eq!(server.id(), id);
// Check that our old connection id is no longer contained in the keychain
assert!(!keychain.has_id("1234").await, "Old OTP still exists");
// Validate the OTP was stored in our keychain
assert!(
keychain.has_key("1234", otp.into_heap_secret_key()).await,
keychain
.has_key(id.to_string(), otp.into_heap_secret_key())
.await,
"Missing OTP"
);
}
#[test(tokio::test)]
async fn server_should_succeed_if_establishes_connection_with_existing_client() {
todo!();
}
#[test(tokio::test)]
async fn server_should_synchronize_previous_backup_with_existing_client() {
todo!();
}
#[test(tokio::test)]
async fn reconnect_should_fail_if_client_side_connection_unable_to_reconnect_transport() {
todo!();

Loading…
Cancel
Save