diff --git a/net/quinn/tests/certs/localhost.crt b/net/quinn/tests/certs/localhost.crt new file mode 100644 index 00000000..3f9d65f5 --- /dev/null +++ b/net/quinn/tests/certs/localhost.crt @@ -0,0 +1,10 @@ +-----BEGIN CERTIFICATE----- +MIIBZjCCAQ2gAwIBAgIUducmm59E2q/s87I6F8uymGvNuM4wCgYIKoZIzj0EAwIw +FDESMBAGA1UEAwwJTG9jYWxob3N0MB4XDTI0MTAxNjA4MDExMFoXDTI0MTExNTA4 +MDExMFowFDESMBAGA1UEAwwJTG9jYWxob3N0MFkwEwYHKoZIzj0CAQYIKoZIzj0D +AQcDQgAEEmItpfgNKextROvDh4+phcUP3s0jb1OeQHuHnYa5hw5O+FVQf6FtgL6U +Zx5fdgl+NIW795ZR/Nt7y9D5H4fxP6M9MDswGgYDVR0RBBMwEYIJbG9jYWxob3N0 +hwR/AAABMB0GA1UdDgQWBBSLX7qrn+1oorVuolaoiKVBU6irfTAKBggqhkjOPQQD +AgNHADBEAiASp7doLyxErcAfUJ3QLxQZ+Rav8+n/Xv7ukisxNr+UuAIgALEzXXsa +mN1VcFcbHPcQoTwCFlv/MxKAmaOgJel43tc= +-----END CERTIFICATE----- diff --git a/net/quinn/tests/certs/localhost.key b/net/quinn/tests/certs/localhost.key new file mode 100644 index 00000000..a640d5d7 --- /dev/null +++ b/net/quinn/tests/certs/localhost.key @@ -0,0 +1,8 @@ +-----BEGIN EC PARAMETERS----- +BggqhkjOPQMBBw== +-----END EC PARAMETERS----- +-----BEGIN EC PRIVATE KEY----- +MHcCAQEEINlRLGfOFJfJFhcOYkW1PXw6OPM5qABO0FT158tiI25hoAoGCCqGSM49 +AwEHoUQDQgAEEmItpfgNKextROvDh4+phcUP3s0jb1OeQHuHnYa5hw5O+FVQf6Ft +gL6UZx5fdgl+NIW795ZR/Nt7y9D5H4fxPw== +-----END EC PRIVATE KEY----- diff --git a/net/quinn/tests/quinnwebtransport.rs b/net/quinn/tests/quinnwebtransport.rs new file mode 100644 index 00000000..fc66b679 --- /dev/null +++ b/net/quinn/tests/quinnwebtransport.rs @@ -0,0 +1,119 @@ +// Copyright (C) 2024, Fluendo S.A. +// Author: Andoni Morales Alastruey +// +// This Source Code Form is subject to the terms of the Mozilla Public License, v2.0. +// If a copy of the MPL was not distributed with this file, You can obtain one at +// . +// +// SPDX-License-Identifier: MPL-2.0 + +use gst::prelude::*; +use serial_test::serial; +use std::{path::PathBuf, thread}; + +fn init() { + use std::sync::Once; + static INIT: Once = Once::new(); + + INIT.call_once(|| { + gst::init().unwrap(); + gstquinn::plugin_register_static().expect("WebTransport source sink send receive tests"); + }); +} + +fn make_buffer(content: &[u8]) -> gst::Buffer { + let mut buf = gst::Buffer::from_slice(content.to_owned()); + buf.make_mut().set_pts(gst::ClockTime::from_mseconds(200)); + buf +} + +fn get_certificates_paths() -> (String, String) { + let mut certs_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")); + certs_dir.push("tests"); + certs_dir.push("certs"); + + ( + certs_dir + .join("localhost.crt") + .into_os_string() + .into_string() + .unwrap(), + certs_dir + .join("localhost.key") + .into_os_string() + .into_string() + .unwrap(), + ) +} + +fn send_receive(src_pipeline_props: &str, sink_pipeline_props: &str) { + init(); + + let content = "Hello, world!\n".as_bytes(); + + let (cert_path, key_path) = get_certificates_paths(); + + let src_pipeline = format!( + "quinnwtclientsrc {} certificate-file={} caps=text/plain", + src_pipeline_props, cert_path + ); + let sink_pipeline = format!( + "quinnwtserversink {} server-name=localhost \ + address=127.0.0.1 certificate-file={} private-key-file={}", + sink_pipeline_props, cert_path, key_path + ); + + thread::spawn(move || { + let mut h1 = gst_check::Harness::new_empty(); + h1.add_parse(&sink_pipeline); + + h1.set_src_caps(gst::Caps::builder("text/plain").build()); + + h1.play(); + + assert!(h1.push(make_buffer(content)) == Ok(gst::FlowSuccess::Ok)); + + h1.push_event(gst::event::Eos::new()); + + h1.element().unwrap().set_state(gst::State::Null).unwrap(); + + drop(h1); + }); + + let mut h2 = gst_check::Harness::new_empty(); + h2.add_parse(&src_pipeline); + + h2.play(); + + let buf = h2.pull_until_eos().unwrap().unwrap(); + + assert_eq!( + content, + buf.into_mapped_buffer_readable().unwrap().as_slice() + ); + + h2.element().unwrap().set_state(gst::State::Null).unwrap(); + + drop(h2); +} + +#[test] +#[serial] +fn test_send_receive_without_datagram() { + send_receive("url=https://127.0.0.1:7770", "port=7770"); +} + +#[test] +#[serial] +fn test_send_receive_with_datagram() { + send_receive( + "use-datagram=true url=https://127.0.0.1:7771", + "use-datagram=true port=7771", + ); +} + +#[test] +#[serial] +fn test_send_receive_with_hostname() { + send_receive("url=https://localhost:7772", "port=7772"); +}