Skip to content

Commit

Permalink
add failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Ream authored and robertream committed May 27, 2024
1 parent 4dc2ae4 commit 34b6970
Showing 1 changed file with 49 additions and 4 deletions.
53 changes: 49 additions & 4 deletions srt-tokio/tests/crypto.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
use std::time::{Duration, Instant};
use std::{
io,
time::{Duration, Instant},
};

use srt_tokio::SrtSocket;

use assert_matches::assert_matches;
use bytes::Bytes;
use futures::{SinkExt, TryStreamExt};
use log::info;

use tokio::{spawn, time::sleep};
use tokio::{select, spawn, time::sleep};

async fn test_crypto(size: u16) {
let sender = SrtSocket::builder()
Expand Down Expand Up @@ -49,5 +52,47 @@ async fn crypto_exchange() {
test_crypto(32).await;
}

// TODO: bad password
#[tokio::test]
async fn bad_password_listen() {
let listener = SrtSocket::builder()
.encryption(16, "password1234")
.listen_on(":3000");

let caller = SrtSocket::builder()
.encryption(16, "password123")
.call("127.0.0.1:3000", None);

let listener_fut = spawn(async move {
listener.await.unwrap();
});

let res = caller.await;
assert_matches!(res, Err(e) if e.kind() == io::ErrorKind::ConnectionRefused);

assert_matches!(
tokio::time::timeout(Duration::from_millis(100), listener_fut).await,
Err(_)
);
}

#[tokio::test]
async fn bad_password_rendezvous() {
let a = SrtSocket::builder()
.local_port(5301)
.encryption(16, "password1234")
.rendezvous("127.0.0.1:5300");

let b = SrtSocket::builder()
.encryption(16, "password123")
.local_port(5300)
.rendezvous("127.0.0.1:5301");

let result = select!(
r = a => r,
r = b => r
);

assert_matches!(result, Err(e) if e.kind() == io::ErrorKind::ConnectionRefused);
}

// TODO: mismatch

0 comments on commit 34b6970

Please sign in to comment.