From 8f9705334ec6eab2f714e8720469f26571585b9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9odore=20Pr=C3=A9vot?= Date: Wed, 19 Jul 2023 12:03:08 +0200 Subject: [PATCH 1/7] chore(ci): add engineio ci for v4 and ci for v3 & v4 --- .github/workflows/engineio-ci.yml | 69 +++++++++++++++++++++++++++++-- e2e/Cargo.toml | 2 +- 2 files changed, 66 insertions(+), 5 deletions(-) diff --git a/.github/workflows/engineio-ci.yml b/.github/workflows/engineio-ci.yml index 03bee1ce..3f63bf8a 100644 --- a/.github/workflows/engineio-ci.yml +++ b/.github/workflows/engineio-ci.yml @@ -7,7 +7,6 @@ on: pull_request: branches: - main - - develop jobs: e2e_v3: @@ -30,10 +29,72 @@ jobs: run: | cd engine.io-protocol/test-suite && npm install && cd ../.. cargo build --bin engineioxide-e2e --release --features v3 --no-default-features - cargo run --bin engineioxide-e2e --release --features v3 --no-default-features > v3_server.txt & npm --prefix engine.io-protocol/test-suite test > v3_client.txt + cargo run --bin engineioxide-e2e --release --features v3 --no-default-features > server.txt & npm --prefix engine.io-protocol/test-suite test > client.txt - name: Server output if: always() - run: cat v3_server.txt + run: cat server.txt - name: Client output if: always() - run: cat v3_client.txt \ No newline at end of file + run: cat client.txt + e2e_v4: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + - uses: actions/checkout@v3 + with: + repository: socketio/engine.io-protocol + path: engine.io-protocol + ref: v3 + - uses: actions/setup-node@v3 + with: + node-version: 16 + - name: Install deps & run tests + run: | + cd engine.io-protocol/test-suite && npm install && cd ../.. + cargo build --bin engineioxide-e2e --release --features v4 --no-default-features + cargo run --bin engineioxide-e2e --release --features v4 --no-default-features > server.txt & npm --prefix engine.io-protocol/test-suite test > client.txt + - name: Server output + if: always() + run: cat server.txt + - name: Client output + if: always() + run: cat client.txt + e2e_full: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + - uses: actions/checkout@v3 + with: + repository: socketio/engine.io-protocol + path: engine.io-protocol-v3 + ref: v3 + - uses: actions/checkout@v3 + with: + repository: socketio/engine.io-protocol + path: engine.io-protocol-v4 + ref: main + - uses: actions/setup-node@v3 + with: + node-version: 16 + - name: Install deps & run tests + run: | + cd engine.io-protocol/test-suite && npm install && cd ../.. + cargo build --bin engineioxide-e2e --release --features v3,v4 --no-default-features + cargo run --bin engineioxide-e2e --release --features v3,v4 --no-default-features > server.txt & npm --prefix engine.io-protocol-v4/test-suite test > client_v4.txt & npm --prefix engine.io-protocol-v3/test-suite test > client_v3.txt + - name: Server output + if: always() + run: cat server.txt + - name: Client v3 output + if: always() + run: cat client_v3.txt + - name: Client v4 output + if: always() + run: cat client_v4.txt \ No newline at end of file diff --git a/e2e/Cargo.toml b/e2e/Cargo.toml index 2954dfb3..08c58430 100644 --- a/e2e/Cargo.toml +++ b/e2e/Cargo.toml @@ -20,4 +20,4 @@ path = "src/socketioxide.rs" [[bin]] name = "engineioxide-e2e" -path = "src/engineioxide.rs" \ No newline at end of file +path = "src/engineioxide.rs" From d85c489884986b7515bfb8d83d7500fef9178293 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9odore=20Pr=C3=A9vot?= Date: Wed, 19 Jul 2023 12:10:18 +0200 Subject: [PATCH 2/7] fix: v4 e2e suite branch --- .github/workflows/engineio-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/engineio-ci.yml b/.github/workflows/engineio-ci.yml index 3f63bf8a..9f1b79de 100644 --- a/.github/workflows/engineio-ci.yml +++ b/.github/workflows/engineio-ci.yml @@ -48,7 +48,7 @@ jobs: with: repository: socketio/engine.io-protocol path: engine.io-protocol - ref: v3 + ref: main - uses: actions/setup-node@v3 with: node-version: 16 From 918eaef9a0902466ad3b09c44ebabd5e2247ae6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9odore=20Pr=C3=A9vot?= Date: Wed, 19 Jul 2023 12:35:04 +0200 Subject: [PATCH 3/7] fix: install path for e2e suite --- .github/workflows/engineio-ci.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/engineio-ci.yml b/.github/workflows/engineio-ci.yml index 9f1b79de..a564f976 100644 --- a/.github/workflows/engineio-ci.yml +++ b/.github/workflows/engineio-ci.yml @@ -86,7 +86,8 @@ jobs: node-version: 16 - name: Install deps & run tests run: | - cd engine.io-protocol/test-suite && npm install && cd ../.. + cd engine.io-protocol-v3/test-suite && npm install && cd ../.. + cd engine.io-protocol-v4/test-suite && npm install && cd ../.. cargo build --bin engineioxide-e2e --release --features v3,v4 --no-default-features cargo run --bin engineioxide-e2e --release --features v3,v4 --no-default-features > server.txt & npm --prefix engine.io-protocol-v4/test-suite test > client_v4.txt & npm --prefix engine.io-protocol-v3/test-suite test > client_v3.txt - name: Server output From e2631685d00aa482e3bbcaa7fe26dc8842b614c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9odore=20Pr=C3=A9vot?= Date: Mon, 14 Aug 2023 00:46:26 +0200 Subject: [PATCH 4/7] fix(engineioxide/payload): v3_string_encoder bad format error --- engineioxide/src/payload/decoder.rs | 2 +- engineioxide/src/payload/mod.rs | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/engineioxide/src/payload/decoder.rs b/engineioxide/src/payload/decoder.rs index f408b426..cb455f55 100644 --- a/engineioxide/src/payload/decoder.rs +++ b/engineioxide/src/payload/decoder.rs @@ -263,7 +263,7 @@ pub fn v3_string_decoder( (true, i + 1 - old_len) // Mark as done and set the used bytes count } None if state.end_of_stream && remaining - available.len() == 0 => { - return None; + return Some((Err(Error::InvalidPacketLength), state)); } // Reached end of stream and end of bufferered chunks without finding the separator None => (false, available.len()), // Continue reading more data } diff --git a/engineioxide/src/payload/mod.rs b/engineioxide/src/payload/mod.rs index f7b0fe6b..9b615eee 100644 --- a/engineioxide/src/payload/mod.rs +++ b/engineioxide/src/payload/mod.rs @@ -43,11 +43,14 @@ pub fn decoder( #[cfg(all(feature = "v3", not(feature = "v4")))] { + let is_binary = + body.headers().get(CONTENT_TYPE) == Some(&"application/octet-stream".parse().unwrap()); use futures::future::Either; + use http::header::CONTENT_TYPE; if is_binary { Either::Left(decoder::v3_binary_decoder(body, max_payload)) } else { - Either::Right(decoder::v3_binary_decoder(body, max_payload)) + Either::Right(decoder::v3_string_decoder(body, max_payload)) } } #[cfg(all(feature = "v4", not(feature = "v3")))] From 53d9d0c09e50b094af6e9510ca1634523dc0f8f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9odore=20Pr=C3=A9vot?= Date: Mon, 14 Aug 2023 00:47:56 +0200 Subject: [PATCH 5/7] conf(e2e): configure feature flag for engineioxide --- .github/workflows/engineio-ci.yml | 12 ++++++------ e2e/Cargo.toml | 7 ++++++- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/.github/workflows/engineio-ci.yml b/.github/workflows/engineio-ci.yml index a564f976..4b312168 100644 --- a/.github/workflows/engineio-ci.yml +++ b/.github/workflows/engineio-ci.yml @@ -28,8 +28,8 @@ jobs: - name: Install deps & run tests run: | cd engine.io-protocol/test-suite && npm install && cd ../.. - cargo build --bin engineioxide-e2e --release --features v3 --no-default-features - cargo run --bin engineioxide-e2e --release --features v3 --no-default-features > server.txt & npm --prefix engine.io-protocol/test-suite test > client.txt + cargo build --bin engineioxide-e2e --release --features engineio-v3 --no-default-features + cargo run --bin engineioxide-e2e --release --features engineio-v3 --no-default-features > server.txt & npm --prefix engine.io-protocol/test-suite test > client.txt - name: Server output if: always() run: cat server.txt @@ -55,8 +55,8 @@ jobs: - name: Install deps & run tests run: | cd engine.io-protocol/test-suite && npm install && cd ../.. - cargo build --bin engineioxide-e2e --release --features v4 --no-default-features - cargo run --bin engineioxide-e2e --release --features v4 --no-default-features > server.txt & npm --prefix engine.io-protocol/test-suite test > client.txt + cargo build --bin engineioxide-e2e --release --features engineio-v4 --no-default-features + cargo run --bin engineioxide-e2e --release --features engineio-v4 --no-default-features > server.txt & npm --prefix engine.io-protocol/test-suite test > client.txt - name: Server output if: always() run: cat server.txt @@ -88,8 +88,8 @@ jobs: run: | cd engine.io-protocol-v3/test-suite && npm install && cd ../.. cd engine.io-protocol-v4/test-suite && npm install && cd ../.. - cargo build --bin engineioxide-e2e --release --features v3,v4 --no-default-features - cargo run --bin engineioxide-e2e --release --features v3,v4 --no-default-features > server.txt & npm --prefix engine.io-protocol-v4/test-suite test > client_v4.txt & npm --prefix engine.io-protocol-v3/test-suite test > client_v3.txt + cargo build --bin engineioxide-e2e --release --features engineio-v3,engineio-v4 --no-default-features + cargo run --bin engineioxide-e2e --release --features engineio-v3,engineio-v4 --no-default-features > server.txt & npm --prefix engine.io-protocol-v4/test-suite test > client_v4.txt & npm --prefix engine.io-protocol-v3/test-suite test > client_v3.txt - name: Server output if: always() run: cat server.txt diff --git a/e2e/Cargo.toml b/e2e/Cargo.toml index 08c58430..dc2f4cca 100644 --- a/e2e/Cargo.toml +++ b/e2e/Cargo.toml @@ -4,7 +4,7 @@ version = "0.3.0" edition = "2021" [dependencies] -engineioxide = { path = "../engineioxide" } +engineioxide = { path = "../engineioxide", default-features = false } socketioxide = { path = "../socketioxide" } hyper = { version = "0.14.26" } tokio = { version = "1.13.0", features = ["full"] } @@ -21,3 +21,8 @@ path = "src/socketioxide.rs" [[bin]] name = "engineioxide-e2e" path = "src/engineioxide.rs" + + +[features] +engineio-v3 = ["engineioxide/v3"] +engineio-v4 = ["engineioxide/v4"] From 5553397ad54e2f8f9892bf09b2c4c09d9f8fa9a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9odore=20Pr=C3=A9vot?= Date: Mon, 14 Aug 2023 00:50:11 +0200 Subject: [PATCH 6/7] fix(clippy): tests --- engineioxide/src/payload/decoder.rs | 16 ++++++++-------- engineioxide/src/payload/encoder.rs | 2 +- engineioxide/src/service.rs | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/engineioxide/src/payload/decoder.rs b/engineioxide/src/payload/decoder.rs index cb455f55..dd564360 100644 --- a/engineioxide/src/payload/decoder.rs +++ b/engineioxide/src/payload/decoder.rs @@ -430,7 +430,7 @@ mod tests { payload.next().await.unwrap().unwrap(), Packet::Message(msg) if msg == "faaaaaaaa" )); - assert_eq!(payload.next().await.is_none(), true); + assert!(payload.next().await.is_none()); } #[cfg(feature = "v3")] @@ -438,10 +438,10 @@ mod tests { async fn binary_payload_iterator_v3() { assert!(cfg!(feature = "v3")); - const PAYLOAD: &'static [u8] = &[ + const PAYLOAD: &[u8] = &[ 0, 9, 255, 52, 104, 101, 108, 108, 111, 226, 130, 172, 1, 5, 255, 4, 1, 2, 3, 4, ]; - const BINARY_PAYLOAD: &'static [u8] = &[1, 2, 3, 4]; + const BINARY_PAYLOAD: &[u8] = &[1, 2, 3, 4]; let data = Full::new(Bytes::from(PAYLOAD)); let payload = v3_binary_decoder(data, MAX_PAYLOAD); futures::pin_mut!(payload); @@ -453,7 +453,7 @@ mod tests { payload.next().await.unwrap().unwrap(), Packet::BinaryV3(msg) if msg == BINARY_PAYLOAD )); - assert_eq!(payload.next().await.is_none(), true); + assert!(payload.next().await.is_none()); } #[cfg(feature = "v3")] @@ -481,7 +481,7 @@ mod tests { payload.next().await.unwrap().unwrap(), Packet::Message(msg) if msg == "baaaaaaaar" )); - assert_eq!(payload.next().await.is_none(), true); + assert!(payload.next().await.is_none()); } } @@ -490,10 +490,10 @@ mod tests { async fn binary_payload_stream_v3() { assert!(cfg!(feature = "v3")); - const PAYLOAD: &'static [u8] = &[ + const PAYLOAD: &[u8] = &[ 0, 9, 255, 52, 104, 101, 108, 108, 111, 226, 130, 172, 1, 5, 255, 4, 1, 2, 3, 4, ]; - const BINARY_PAYLOAD: &'static [u8] = &[1, 2, 3, 4]; + const BINARY_PAYLOAD: &[u8] = &[1, 2, 3, 4]; for i in 1..PAYLOAD.len() { println!("payload stream v3 chunk size: {i}"); @@ -510,7 +510,7 @@ mod tests { payload.next().await.unwrap().unwrap(), Packet::BinaryV3(msg) if msg == BINARY_PAYLOAD )); - assert_eq!(payload.next().await.is_none(), true); + assert!(payload.next().await.is_none()); } } diff --git a/engineioxide/src/payload/encoder.rs b/engineioxide/src/payload/encoder.rs index 09cc03dd..73b79f55 100644 --- a/engineioxide/src/payload/encoder.rs +++ b/engineioxide/src/payload/encoder.rs @@ -183,7 +183,7 @@ mod tests { #[cfg(feature = "v3")] #[tokio::test] async fn encode_v3b64_payload() { - const PAYLOAD: &'static str = "7:4hello€10:b4AQIDBA==7:4hello€"; + const PAYLOAD: &str = "7:4hello€10:b4AQIDBA==7:4hello€"; let (tx, rx) = tokio::sync::mpsc::channel::(10); let mutex = Mutex::new(rx); let rx = mutex.lock().await; diff --git a/engineioxide/src/service.rs b/engineioxide/src/service.rs index 3aa2ad2f..6090f7a0 100644 --- a/engineioxide/src/service.rs +++ b/engineioxide/src/service.rs @@ -380,7 +380,7 @@ mod tests { fn request_info_polling_with_bin_by_default() { let req = build_request("http://localhost:3000/socket.io/?EIO=3&transport=polling"); let req = RequestInfo::parse(&req).unwrap(); - assert_eq!(req.b64, false); + assert!(!req.b64); } #[test] @@ -390,7 +390,7 @@ mod tests { let req = build_request("http://localhost:3000/socket.io/?EIO=3&transport=polling&b64=1"); let req = RequestInfo::parse(&req).unwrap(); - assert_eq!(req.b64, true); + assert!(req.b64); } #[test] From 12b3532da94f12741b96ef91417d91e9d68c99b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9odore=20Pr=C3=A9vot?= Date: Mon, 14 Aug 2023 00:53:31 +0200 Subject: [PATCH 7/7] test(engineioxide/payload) fix `string_payload_iterator_v3` test --- engineioxide/src/payload/decoder.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/engineioxide/src/payload/decoder.rs b/engineioxide/src/payload/decoder.rs index dd564360..ea4cb48d 100644 --- a/engineioxide/src/payload/decoder.rs +++ b/engineioxide/src/payload/decoder.rs @@ -415,7 +415,7 @@ mod tests { async fn string_payload_iterator_v3() { assert!(cfg!(feature = "v3")); - let data = Full::new(Bytes::from("4:4foo3:4€f10:4faaaaaaaaa")); + let data = Full::new(Bytes::from("4:4foo3:4€f11:4faaaaaaaaa")); let payload = v3_string_decoder(data, MAX_PAYLOAD); futures::pin_mut!(payload); assert!(matches!( @@ -428,7 +428,7 @@ mod tests { )); assert!(matches!( payload.next().await.unwrap().unwrap(), - Packet::Message(msg) if msg == "faaaaaaaa" + Packet::Message(msg) if msg == "faaaaaaaaa" )); assert!(payload.next().await.is_none()); }