Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CI tests for all platforms #6

Merged
merged 6 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# GitHub workflow which runs on pushes.
# Does multiple checks with nightly Rust on Linux.

name: All Checks

on:
push:

env:
CARGO_TERM_COLOR: always

jobs:
build_and_test:
name: All Checks
runs-on: ubuntu-latest
strategy:
matrix:
toolchain:
- nightly
steps:
- uses: actions/checkout@v3

- name: Update rustup
run: rustup update

- name: Build
run: cargo build --verbose

- name: Test
run: cargo test --verbose

- name: Clippy
run: cargo clippy --verbose

- name: Check documentation
run: cargo doc --no-deps --verbose

- name: Check formatting
run: cargo fmt --check --verbose

- name: Install cargo audit
run: cargo install --locked cargo-audit

- name: Audit dependencies
run: cargo audit
26 changes: 4 additions & 22 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
# GitHub workflow which automatically
# tests code on pushes and pull requests.
# GitHub workflow which runs on pushes.
# Does a build and test with stable Rust on 3 different platforms.

name: Cargo Build & Test
name: Stable Build & Test

on:
push:
# pull_request:

env:
CARGO_TERM_COLOR: always

jobs:
build_and_test:
name: Rust Build & Test
name: Stable Build & Test
runs-on: ${{ matrix.os }}
strategy:
matrix:
Expand All @@ -22,8 +21,6 @@ jobs:
- macos-latest
toolchain:
- stable
- beta
- nightly
steps:
- uses: actions/checkout@v3

Expand All @@ -35,18 +32,3 @@ jobs:

- name: Test
run: cargo test --verbose

- name: Clippy
run: cargo clippy --verbose

- name: Check documentation
run: cargo doc --no-deps --verbose

- name: Check formatting
run: cargo fmt --check --verbose

- name: Install cargo audit
run: cargo install --locked cargo-audit

- name: Audit dependencies
run: cargo audit
4 changes: 2 additions & 2 deletions gday/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ async fn run(args: crate::Args) -> Result<(), Box<dyn std::error::Error>> {
.await
.map_err(|_| gday_hole_punch::Error::HolePunchTimeout)??;

// Gracefully close the server connection
// Gracefully terminate TLS
server_connection.shutdown().await?;

let mut stream = EncryptedStream::encrypt_connection(stream, &shared_key).await?;
Expand Down Expand Up @@ -264,7 +264,7 @@ async fn run(args: crate::Args) -> Result<(), Box<dyn std::error::Error>> {
.await
.map_err(|_| gday_hole_punch::Error::HolePunchTimeout)??;

// Gracefully close the server connection
// Gracefully terminate TLS
server_connection.shutdown().await?;

let mut stream = EncryptedStream::encrypt_connection(stream, &shared_key).await?;
Expand Down
4 changes: 2 additions & 2 deletions gday_contact_exchange_protocol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ impl std::fmt::Display for FullContact {

/// Writes `msg` to `writer` using [`serde_json`], and flushes.
///
/// Prefixes the message with 2 bytes holding the [`PROTOCOL_VERSION`]
/// Prefixes the message with 1 byte holding the [`PROTOCOL_VERSION`]
/// and 2 bytes holding the length of the following message (all in big-endian).
pub fn write_to(msg: impl Serialize, writer: &mut impl Write) -> Result<(), Error> {
let vec = serde_json::to_vec(&msg)?;
Expand All @@ -300,7 +300,7 @@ pub fn write_to(msg: impl Serialize, writer: &mut impl Write) -> Result<(), Erro

/// Asynchronously writes `msg` to `writer` using [`serde_json`], and flushes.
///
/// Prefixes the message with 2 bytes holding the [`PROTOCOL_VERSION`]
/// Prefixes the message with 1 byte holding the [`PROTOCOL_VERSION`]
/// and 2 bytes holding the length of the following message (all in big-endian).
pub async fn write_to_async(
msg: impl Serialize,
Expand Down
10 changes: 5 additions & 5 deletions gday_encryption/src/helper_buf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ pub struct HelperBufPart<'a> {
start_i: usize,
}

impl<'a> aead::Buffer for HelperBufPart<'a> {
impl aead::Buffer for HelperBufPart<'_> {
/// Extends the [`HelperBufPart`] with `other`.
/// - Returns an [`aead::Error`] if there's not enough capacity.
fn extend_from_slice(&mut self, other: &[u8]) -> aead::Result<()> {
Expand All @@ -153,27 +153,27 @@ impl<'a> aead::Buffer for HelperBufPart<'a> {

// The 4 following impls let the user treat this
// struct as a slice with the data-containing portion
impl<'a> Deref for HelperBufPart<'a> {
impl Deref for HelperBufPart<'_> {
type Target = [u8];

fn deref(&self) -> &Self::Target {
&self.parent.inner[self.start_i..self.parent.r_cursor]
}
}

impl<'a> DerefMut for HelperBufPart<'a> {
impl DerefMut for HelperBufPart<'_> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.parent.inner[self.start_i..self.parent.r_cursor]
}
}

impl<'a> AsRef<[u8]> for HelperBufPart<'a> {
impl AsRef<[u8]> for HelperBufPart<'_> {
fn as_ref(&self) -> &[u8] {
&self.parent.inner[self.start_i..self.parent.r_cursor]
}
}

impl<'a> AsMut<[u8]> for HelperBufPart<'a> {
impl AsMut<[u8]> for HelperBufPart<'_> {
fn as_mut(&mut self) -> &mut [u8] {
&mut self.parent.inner[self.start_i..self.parent.r_cursor]
}
Expand Down
7 changes: 2 additions & 5 deletions gday_encryption/tests/test_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async fn test_transfers() {
let chunk_size = 200_000;

// Listens on the loopback address
let listener = tokio::net::TcpListener::bind("[::]:0").await.unwrap();
let listener = tokio::net::TcpListener::bind("[::1]:0").await.unwrap();
let pipe_addr = listener.local_addr().unwrap();

// A thread that will send data to the loopback address
Expand All @@ -38,8 +38,6 @@ async fn test_transfers() {
stream_a.write_all(chunk).await.unwrap();
stream_a.flush().await.unwrap();
}
// Ensure calling shutdown multiple times works
stream_a.shutdown().await.unwrap();
stream_a.shutdown().await.unwrap();
});

Expand Down Expand Up @@ -79,7 +77,7 @@ async fn test_bufread() {
let chunk_size = 200_000;

// Listens on the loopback address
let listener = tokio::net::TcpListener::bind("[::]:0").await.unwrap();
let listener = tokio::net::TcpListener::bind("[::1]:0").await.unwrap();
let pipe_addr = listener.local_addr().unwrap();

// A thread that will send data to the loopback address
Expand All @@ -97,7 +95,6 @@ async fn test_bufread() {
}

stream_a.shutdown().await.unwrap();
stream_a.shutdown().await.unwrap();
});

// Stream that will receive the test data sent to the loopback address.
Expand Down
4 changes: 2 additions & 2 deletions gday_file_transfer/src/offer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ impl FileResponseMsg {

/// Writes `msg` to `writer` using [`serde_json`], and flushes.
///
/// Prefixes the message with 2 bytes holding the [`PROTOCOL_VERSION`]
/// Prefixes the message with 1 byte holding the [`PROTOCOL_VERSION`]
/// and 4 bytes holding the length of the following message (all in big-endian).
pub fn write_to(msg: impl Serialize, writer: &mut impl Write) -> Result<(), Error> {
let vec = serde_json::to_vec(&msg)?;
Expand All @@ -181,7 +181,7 @@ pub fn write_to(msg: impl Serialize, writer: &mut impl Write) -> Result<(), Erro

/// Asynchronously writes `msg` to `writer` using [`serde_json`], and flushes.
///
/// Prefixes the message with 2 bytes holding the [`PROTOCOL_VERSION`]
/// Prefixes the message with 1 byte holding the [`PROTOCOL_VERSION`]
/// and 4 bytes holding the length of the following message (all in big-endian).
pub async fn write_to_async(
msg: impl Serialize,
Expand Down
2 changes: 1 addition & 1 deletion gday_hole_punch/tests/test_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ async fn test_integration() {
key: None,
certificate: None,
unencrypted: true,
addresses: vec!["0.0.0.0:0".parse().unwrap(), "[::]:0".parse().unwrap()],
addresses: vec!["127.0.0.1:0".parse().unwrap(), "[::1]:0".parse().unwrap()],
timeout: 3600,
request_limit: 10,
verbosity: log::LevelFilter::Off,
Expand Down
4 changes: 3 additions & 1 deletion gday_server/src/connection_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use gday_contact_exchange_protocol::{read_from_async, write_to_async, ClientMsg,
use log::{error, info, warn};
use std::net::SocketAddr;
use tokio::{
io::{AsyncRead, AsyncWrite},
io::{AsyncRead, AsyncWrite, AsyncWriteExt},
net::TcpStream,
};
use tokio_rustls::TlsAcceptor;
Expand All @@ -27,6 +27,8 @@ pub async fn handle_connection(
}
};
let _ = handle_requests(&mut tls_stream, state, origin).await;
// Graceful TLS termination
let _ = tls_stream.shutdown().await;
} else {
let _ = handle_requests(&mut tcp_stream, state, origin).await;
}
Expand Down
4 changes: 2 additions & 2 deletions gday_server/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ mod tests {

#[tokio::test]
async fn test_room_timeout() {
let mut state1 = State::new(100, Duration::from_millis(10));
let mut state1 = State::new(100, Duration::from_millis(30));
let mut state2 = state1.clone();

let origin1 = IpAddr::V4(123.into());
Expand All @@ -440,7 +440,7 @@ mod tests {
.unwrap();

// wait for the room to time out
tokio::time::sleep(Duration::from_millis(20)).await;
tokio::time::sleep(Duration::from_millis(300)).await;

// confirm this room has been removed
let result = state2.update_client(ROOM, false, example_endpoint, false, origin2);
Expand Down
17 changes: 5 additions & 12 deletions gday_server/tests/test_integration.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#![forbid(unsafe_code)]
#![warn(clippy::all)]

use std::io::Read;

use gday_contact_exchange_protocol::{read_from, write_to, ClientMsg, Contact, ServerMsg};

#[tokio::test]
Expand All @@ -10,7 +12,7 @@ async fn test_integration() {
key: None,
certificate: None,
unencrypted: true,
addresses: vec!["0.0.0.0:0".parse().unwrap(), "[::]:0".parse().unwrap()],
addresses: vec!["127.0.0.1:0".parse().unwrap(), "[::1]:0".parse().unwrap()],
timeout: 3600,
request_limit: 10,
verbosity: log::LevelFilter::Off,
Expand Down Expand Up @@ -183,7 +185,7 @@ async fn test_request_limit() {
key: None,
certificate: None,
unencrypted: true,
addresses: vec!["0.0.0.0:0".parse().unwrap(), "[::]:0".parse().unwrap()],
addresses: vec!["127.0.0.1:0".parse().unwrap(), "[::1]:0".parse().unwrap()],
timeout: 3600,
request_limit: 10,
verbosity: log::LevelFilter::Off,
Expand Down Expand Up @@ -222,16 +224,7 @@ async fn test_request_limit() {
assert_eq!(response, ServerMsg::ErrorTooManyRequests);

// ensure the server closed the connection
let result = write_to(
ClientMsg::CreateRoom {
room_code: [100; 32],
},
&mut stream_v4,
);
assert!(matches!(
result,
Err(gday_contact_exchange_protocol::Error::IO(_))
));
assert_eq!(stream_v4.read(&mut [0, 0]).unwrap(), 0);

// ensure other connections are unaffected
write_to(
Expand Down
Loading