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

Clippy tests #122

Merged
merged 6 commits into from
Aug 8, 2019
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
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ jobs:

- run:
name: Build
command: NSS_JOBS=3 cargo build -v
command: NSS_JOBS=3 cargo build -v --all-targets --all-features

- run:
name: Clippy
command: NSS_JOBS=3 cargo clippy -v
command: NSS_JOBS=3 cargo clippy -v --all-targets --all-features

- run:
name: Test
Expand Down
4 changes: 2 additions & 2 deletions neqo-common/src/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,8 +518,8 @@ mod tests {
let mut enc = Encoder::default();
enc.encode_uint(2, 10u8); // 000a
enc.encode_uint(1, 257u16); // 01
enc.encode_uint(3, 0xffffffu32); // ffffff
enc.encode_uint(8, 0xfedcba9876543210u64);
enc.encode_uint(3, 0xff_ffffu32); // ffffff
enc.encode_uint(8, 0xfedc_ba98_7654_3210u64);
assert_eq!(enc, Encoder::from_hex("000a01fffffffedcba9876543210"));
}

Expand Down
2 changes: 1 addition & 1 deletion neqo-common/src/incrdecoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ mod tests {
"01" => 1,
"0123" => 0x123,
"012345" => 0x12345,
"ffffffffffffffff" => 0xffffffffffffffff,
"ffffffffffffffff" => 0xffff_ffff_ffff_ffff,
] {
c.run(IncrementalDecoder::decode_uint(c.b.len() / 2));
}
Expand Down
1 change: 1 addition & 0 deletions neqo-crypto/src/prio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#![allow(dead_code)]
#![allow(non_upper_case_globals)]
#![allow(non_snake_case)]
#![allow(clippy::cognitive_complexity)]

include!(concat!(env!("OUT_DIR"), "/nspr_io.rs"));

Expand Down
6 changes: 3 additions & 3 deletions neqo-crypto/src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ mod tests {
"SSL received a record with an incorrect Message Authentication Code."
);
}
_ => assert!(false),
_ => unreachable!(),
}
}

Expand All @@ -104,7 +104,7 @@ mod tests {
// Note that we don't test |desc| here because that comes from
// strerror(0), which is platform-dependent.
}
_ => assert!(false),
_ => unreachable!(),
}
}

Expand All @@ -122,7 +122,7 @@ mod tests {
assert_eq!(code, -5998);
assert_eq!(desc, "The operation would have blocked");
}
_ => assert!(false),
_ => panic!("bad error type"),
}
}

Expand Down
1 change: 1 addition & 0 deletions neqo-crypto/src/ssl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#![allow(dead_code)]
#![allow(non_upper_case_globals)]
#![allow(non_snake_case)]
#![allow(clippy::cognitive_complexity)]

use crate::constants::*;

Expand Down
2 changes: 1 addition & 1 deletion neqo-crypto/src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ mod test {
#[test]
fn convert_stable() {
let now = Time::from(Instant::now());
let pr: PRTime = now.clone().try_into().expect("should convert successfully");
let pr: PRTime = now.try_into().expect("should convert successfully");
println!("now {:?}", now);
println!("pr {:?}", pr);
println!("Time::try_from(pr) {:?}", Time::try_from(pr));
Expand Down
64 changes: 35 additions & 29 deletions neqo-crypto/tests/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,40 +27,58 @@ fn basic() {
println!("server {:p}", &server);

let bytes = client.handshake(now(), &[]).expect("send CH");
assert!(bytes.len() > 0);
assert!(!bytes.is_empty());
assert_eq!(*client.state(), HandshakeState::InProgress);

let bytes = server
.handshake(now(), &bytes[..])
.expect("read CH, send SH");
assert!(bytes.len() > 0);
assert!(!bytes.is_empty());
assert_eq!(*server.state(), HandshakeState::InProgress);

let bytes = client.handshake(now(), &bytes[..]).expect("send CF");
assert_eq!(bytes.len(), 0);
assert!(bytes.is_empty());
assert_eq!(*client.state(), HandshakeState::AuthenticationPending);

client.authenticated();
assert_eq!(*client.state(), HandshakeState::Authenticated);

// Calling handshake() again indicates that we're happy with the cert.
let bytes = client.handshake(now(), &[]).expect("send CF");
assert!(bytes.len() > 0);
assert!(!bytes.is_empty());
assert!(client.state().connected());

let client_info = client.info().expect("got info");
assert_eq!(TLS_VERSION_1_3, client_info.version());
assert_eq!(TLS_AES_128_GCM_SHA256, client_info.cipher_suite());

let bytes = server.handshake(now(), &bytes[..]).expect("finish");
assert_eq!(bytes.len(), 0);
assert!(bytes.is_empty());
assert!(server.state().connected());

let server_info = server.info().expect("got info");
assert_eq!(TLS_VERSION_1_3, server_info.version());
assert_eq!(TLS_AES_128_GCM_SHA256, server_info.cipher_suite());
}

fn check_client_preinfo(client_preinfo: SecretAgentPreInfo) {
assert_eq!(client_preinfo.version(), None);
assert_eq!(client_preinfo.cipher_suite(), None);
assert_eq!(client_preinfo.early_data(), false);
assert_eq!(client_preinfo.early_data_cipher(), None);
assert_eq!(client_preinfo.max_early_data(), 0);
assert_eq!(client_preinfo.alpn(), None);
}

fn check_server_preinfo(server_preinfo: SecretAgentPreInfo) {
assert_eq!(server_preinfo.version(), Some(TLS_VERSION_1_3));
assert_eq!(server_preinfo.cipher_suite(), Some(TLS_AES_128_GCM_SHA256));
assert_eq!(server_preinfo.early_data(), false);
assert_eq!(server_preinfo.early_data_cipher(), None);
assert_eq!(server_preinfo.max_early_data(), 0);
assert_eq!(server_preinfo.alpn(), None);
}

#[test]
fn raw() {
fixture_init();
Expand All @@ -70,44 +88,32 @@ fn raw() {
println!("server {:?}", server);

let client_records = client.handshake_raw(now(), None).expect("send CH");
assert!(client_records.len() > 0);
assert!(!client_records.is_empty());
assert_eq!(*client.state(), HandshakeState::InProgress);

let client_preinfo = client.preinfo().expect("get preinfo");
assert_eq!(client_preinfo.version(), None);
assert_eq!(client_preinfo.cipher_suite(), None);
assert_eq!(client_preinfo.early_data(), false);
assert_eq!(client_preinfo.early_data_cipher(), None);
assert_eq!(client_preinfo.max_early_data(), 0);
assert_eq!(client_preinfo.alpn(), None);
check_client_preinfo(client.preinfo().expect("get preinfo"));

let server_records =
forward_records(now(), &mut server, client_records).expect("read CH, send SH");
assert!(server_records.len() > 0);
assert!(!server_records.is_empty());
assert_eq!(*server.state(), HandshakeState::InProgress);

let server_preinfo = server.preinfo().expect("get preinfo");
assert_eq!(server_preinfo.version(), Some(TLS_VERSION_1_3));
assert_eq!(server_preinfo.cipher_suite(), Some(TLS_AES_128_GCM_SHA256));
assert_eq!(server_preinfo.early_data(), false);
assert_eq!(server_preinfo.early_data_cipher(), None);
assert_eq!(server_preinfo.max_early_data(), 0);
assert_eq!(server_preinfo.alpn(), None);
check_server_preinfo(server.preinfo().expect("get preinfo"));

let client_records = forward_records(now(), &mut client, server_records).expect("send CF");
assert_eq!(client_records.len(), 0);
assert!(client_records.is_empty());
assert_eq!(*client.state(), HandshakeState::AuthenticationPending);

client.authenticated();
assert_eq!(*client.state(), HandshakeState::Authenticated);

// Calling handshake() again indicates that we're happy with the cert.
let client_records = client.handshake_raw(now(), None).expect("send CF");
assert!(client_records.len() > 0);
assert!(!client_records.is_empty());
assert!(client.state().connected());

let server_records = forward_records(now(), &mut server, client_records).expect("finish");
assert_eq!(server_records.len(), 0);
assert!(server_records.is_empty());
assert!(server.state().connected());

// The client should have one certificate for the server.
Expand Down Expand Up @@ -277,8 +283,8 @@ fn zero_rtt() {
server
.enable_0rtt(
anti_replay.as_ref().unwrap(),
0xffffffff,
PermissiveZeroRttChecker::new(),
0xffff_ffff,
PermissiveZeroRttChecker::make(),
)
.expect("should enable 0-RTT");

Expand All @@ -302,8 +308,8 @@ fn zero_rtt_no_eoed() {
server
.enable_0rtt(
anti_replay.as_ref().unwrap(),
0xffffffff,
PermissiveZeroRttChecker::new(),
0xffff_ffff,
PermissiveZeroRttChecker::make(),
)
.expect("should enable 0-RTT");
server.disable_end_of_early_data();
Expand Down Expand Up @@ -336,7 +342,7 @@ fn reject_zero_rtt() {
server
.enable_0rtt(
anti_replay.as_ref().unwrap(),
0xffffffff,
0xffff_ffff,
Box::new(RejectZeroRtt {}),
)
.expect("should enable 0-RTT");
Expand Down
4 changes: 2 additions & 2 deletions neqo-crypto/tests/handshake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pub struct PermissiveZeroRttChecker {
resuming: bool,
}
impl PermissiveZeroRttChecker {
pub fn new() -> Box<dyn ZeroRttChecker> {
pub fn make() -> Box<dyn ZeroRttChecker> {
Box::new(PermissiveZeroRttChecker { resuming: true })
}
}
Expand All @@ -110,7 +110,7 @@ fn zero_rtt_setup(
server
.enable_0rtt(
&anti_replay,
0xffffffff,
0xffff_ffff,
Box::new(PermissiveZeroRttChecker { resuming: false }),
)
.expect("should enable 0-RTT on server");
Expand Down
Loading