aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHenauxg <19689618+Henauxg@users.noreply.github.com>2022-11-18 15:59:43 +0100
committerHenauxg <19689618+Henauxg@users.noreply.github.com>2022-11-18 15:59:43 +0100
commit354c7e0bc53f8e67dcfbbd88d849a4284a37ff8e (patch)
treea089328a0b474c7fdc2aea6e24d0e5dec6405570
parent33266796a68ce07cef4ea9e5659e02e5405f90e7 (diff)
[tests] Update tests
-rw-r--r--src/lib.rs73
1 files changed, 24 insertions, 49 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 813a344..8051c5b 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -23,11 +23,10 @@ mod tests {
Client, ConnectionConfiguration, QuinnetClientPlugin,
},
server::{
- self,
- certificate::{CertificateRetrievalMode, CertificateRetrievedEvent},
- QuinnetServerPlugin, Server, ServerConfigurationData,
+ self, certificate::CertificateRetrievalMode, QuinnetServerPlugin, Server,
+ ServerConfigurationData,
},
- shared::{CertificateFingerprint, ClientId},
+ shared::ClientId,
};
use bevy::{
app::ScheduleRunnerPlugin,
@@ -61,8 +60,6 @@ mod tests {
struct ServerTestData {
connection_events_received: u64,
last_connected_client_id: Option<ClientId>,
- cert_events_received: u64,
- last_cert_fingeprint: Option<CertificateFingerprint>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
@@ -197,8 +194,8 @@ mod tests {
// Server listens with a cert loaded from a file
{
let mut server = server_app.world.resource_mut::<Server>();
- server
- .open_endpoint(
+ let server_cert = server
+ .start_endpoint(
ServerConfigurationData::new(
SERVER_HOST.to_string(),
SERVER_PORT,
@@ -210,6 +207,10 @@ mod tests {
},
)
.unwrap();
+ assert_eq!(
+ TEST_CERT_FINGERPRINT_B64.to_string(),
+ server_cert.fingerprint.to_base64()
+ );
}
// Client connects with empty cert store
@@ -232,19 +233,6 @@ mod tests {
server_app.update();
client_app.update();
- {
- let mut server_test_data = server_app.world.resource_mut::<ServerTestData>();
- assert_eq!(
- TEST_CERT_FINGERPRINT_B64.to_string(),
- server_test_data
- .last_cert_fingeprint
- .as_mut()
- .expect("A certificate should have been loaded")
- .to_base64()
- );
- assert_eq!(server_test_data.cert_events_received, 1);
- }
-
// The server's certificate is treatead as Unknown by the client, which stores it and continues the connection
{
let mut client_test_data = client_app.world.resource_mut::<ClientTestData>();
@@ -306,20 +294,19 @@ mod tests {
}
// Server reboots, and generates a new self-signed certificate
- {
- let mut server = server_app.world.resource_mut::<Server>();
- server.close_endpoint();
- server
- .open_endpoint(
- ServerConfigurationData::new(
- SERVER_HOST.to_string(),
- SERVER_PORT,
- "0.0.0.0".to_string(),
- ),
- CertificateRetrievalMode::GenerateSelfSigned,
- )
- .unwrap();
- }
+ server_app.world.resource_mut::<Server>().stop_endpoint();
+ let server_cert = server_app
+ .world
+ .resource_mut::<Server>()
+ .start_endpoint(
+ ServerConfigurationData::new(
+ SERVER_HOST.to_string(),
+ SERVER_PORT,
+ "0.0.0.0".to_string(),
+ ),
+ CertificateRetrievalMode::GenerateSelfSigned,
+ )
+ .unwrap();
// Client reconnects with its cert store
{
@@ -345,13 +332,6 @@ mod tests {
server_app.update();
client_app.update();
- let mut server_test_data = server_app.world.resource_mut::<ServerTestData>();
- assert_eq!(server_test_data.cert_events_received, 1);
- let generated_cert_fingerprint = server_test_data
- .last_cert_fingeprint
- .as_mut()
- .expect("The server should have generated a self-signed certificate");
-
// The server's certificate is treatead as Untrusted by the client, which requests a client action
// We received the client action request and asked to abort the connection
{
@@ -370,7 +350,7 @@ mod tests {
// Verify that the cert we received is the one generated by the server
assert_eq!(
interaction_cert_info.fingerprint.to_base64(),
- generated_cert_fingerprint.to_base64()
+ server_cert.fingerprint.to_base64()
);
// Verify the known fingerprint
assert_eq!(
@@ -448,7 +428,7 @@ mod tests {
fn start_listening(mut server: ResMut<Server>) {
server
- .open_endpoint(
+ .start_endpoint(
ServerConfigurationData::new(
SERVER_HOST.to_string(),
SERVER_PORT,
@@ -497,16 +477,11 @@ mod tests {
fn handle_server_events(
mut connection_events: EventReader<server::ConnectionEvent>,
- mut cert_events: EventReader<CertificateRetrievedEvent>,
mut test_data: ResMut<ServerTestData>,
) {
for connected_event in connection_events.iter() {
test_data.connection_events_received += 1;
test_data.last_connected_client_id = Some(connected_event.id);
}
- for cert_event in cert_events.iter() {
- test_data.cert_events_received += 1;
- test_data.last_cert_fingeprint = Some(cert_event.fingerprint.clone());
- }
}
}