Skip to content

Commit

Permalink
Fix lints
Browse files Browse the repository at this point in the history
  • Loading branch information
r-n-o committed Jun 24, 2024
1 parent 429e5b8 commit 20849df
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 50 deletions.
95 changes: 86 additions & 9 deletions src/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions src/integration/src/bin/pivot_remote_tls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{
sync::Arc,
};

use borsh::{BorshDeserialize, BorshSerialize};
use borsh::BorshDeserialize;
use integration::PivotRemoteTlsMsg;
use qos_core::{
io::{SocketAddress, TimeVal},
Expand Down Expand Up @@ -73,10 +73,10 @@ impl RequestProcessor for Processor {

let fetched_content =
std::str::from_utf8(&response_bytes).unwrap();
PivotRemoteTlsMsg::RemoteTlsResponse(format!(

borsh::to_vec(&PivotRemoteTlsMsg::RemoteTlsResponse(format!(
"Content fetched successfully ({read_to_end_result} bytes): {fetched_content}"
))
.try_to_vec()
)))
.expect("RemoteTlsResponse is valid borsh")
}
PivotRemoteTlsMsg::RemoteTlsResponse(_) => {
Expand Down
72 changes: 40 additions & 32 deletions src/integration/tests/borsh_serialize.rs
Original file line number Diff line number Diff line change
@@ -1,42 +1,50 @@
#[cfg(test)]
mod tests {
use borsh::{BorshSerialize, BorshDeserialize};
use borsh::{BorshDeserialize, BorshSerialize};

#[derive(BorshSerialize, BorshDeserialize, Debug, PartialEq)]
struct TestSerializable {
a: u32,
b: String,
c: Vec<u8>,
}
#[derive(BorshSerialize, BorshDeserialize, Debug, PartialEq)]
struct TestSerializable {
a: u32,
b: String,
c: Vec<u8>,
}

#[test]
fn test_serializable_to_vec() {
let inst = TestSerializable {
a: 42,
b: "Hello, world!".to_string(),
c: vec![1, 2, 3, 4, 5],
};
#[test]
fn test_serializable_to_vec() {
let inst = TestSerializable {
a: 42,
b: "Hello, world!".to_string(),
c: vec![1, 2, 3, 4, 5],
};

// Expected serialized output
let expected_serialized: Vec<u8> = vec![
42, 0, 0, 0, // a: u32 (little-endian)
13, 0, 0, 0, // Length of the string b (13)
72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100, 33, // "Hello, world!" as bytes
5, 0, 0, 0, // Length of the vector c (5)
1, 2, 3, 4, 5 // c: Vec<u8>
];
// Expected serialized output
let expected_serialized: Vec<u8> = vec![
42, 0, 0, 0, // a: u32 (little-endian)
13, 0, 0, 0, // Length of the string b (13)
72, 101, 108, 108, 111, 44, 32, 119, 111, 114, 108, 100,
33, // "Hello, world!" as bytes
5, 0, 0, 0, // Length of the vector c (5)
1, 2, 3, 4, 5, // c: Vec<u8>
];

// Serialize the instance
let serialized = borsh::to_vec(&inst).expect("Serialization failed");
// Serialize the instance
let serialized = borsh::to_vec(&inst).expect("Serialization failed");

// Assert that the serialized output matches the expected value
assert_eq!(serialized, expected_serialized, "Serialized bytes differ from the expected value");
// Assert that the serialized output matches the expected value
assert_eq!(
serialized, expected_serialized,
"Serialized bytes differ from the expected value"
);

// Deserialize the serialized data back to a new instance
let deserialized_inst: TestSerializable = borsh::BorshDeserialize::try_from_slice(&serialized)
.expect("Deserialization failed");
// Deserialize the serialized data back to a new instance
let deserialized_inst: TestSerializable =
borsh::BorshDeserialize::try_from_slice(&serialized)
.expect("Deserialization failed");

// Assert that the deserialized instance matches the original instance
assert_eq!(deserialized_inst, inst, "Deserialized instance differs from the original");
}
// Assert that the deserialized instance matches the original instance
assert_eq!(
deserialized_inst, inst,
"Deserialized instance differs from the original"
);
}
}
6 changes: 2 additions & 4 deletions src/integration/tests/remote_tls.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::{process::Command, str};

use borsh::BorshSerialize;
use integration::{PivotRemoteTlsMsg, PIVOT_REMOTE_TLS_PATH, QOS_NET_PATH};
use qos_core::{
client::Client,
Expand Down Expand Up @@ -34,11 +33,10 @@ fn fetch_remote_tls_content() {
TimeVal::seconds(ENCLAVE_APP_SOCKET_CLIENT_TIMEOUT_SECS),
);

let app_request = PivotRemoteTlsMsg::RemoteTlsRequest {
let app_request = borsh::to_vec(&PivotRemoteTlsMsg::RemoteTlsRequest {
host: "api.turnkey.com".to_string(),
path: "/health".to_string(),
}
.try_to_vec()
})
.unwrap();

let response = enclave_client.send(&app_request).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion src/qos_net/src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ impl server::RequestProcessor for Proxy {
dns_resolvers,
dns_port,
)
},
}
ProxyMsg::ConnectByIpRequest { ip, port } => {
println!("Proxy connecting to {ip}:{port}");
self.connect_by_ip(ip, port)
Expand Down

0 comments on commit 20849df

Please sign in to comment.