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

Lint tests too #405

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ fmt:

.PHONY: lint
lint:
cargo clippy --workspace -- -D warnings
cargo clippy --all-targets -- -D warnings

.PHONY: doc
doc:
Expand Down
2 changes: 2 additions & 0 deletions clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
allow-unwrap-in-tests = true
allow-panic-in-tests = true
2 changes: 1 addition & 1 deletion src/cosign/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ TNMea7Ix/stJ5TfcLLeABLE4BNJOsQ4vnBHJ
const SIGNED_IMAGE: &str = "busybox:1.34";

pub(crate) fn get_fulcio_cert_pool() -> CertificatePool {
fn pem_to_der<'a>(input: &'a str) -> CertificateDer<'a> {
fn pem_to_der(input: &str) -> CertificateDer<'_> {
let pem_cert = pem::parse(input).unwrap();
assert_eq!(pem_cert.tag(), "CERTIFICATE");
CertificateDer::from(pem_cert.into_contents())
Expand Down
15 changes: 3 additions & 12 deletions src/cosign/signature_layers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -693,10 +693,7 @@ JsB89BPhZYch0U0hKANx5TY+ncrm0s8bfJxxHoenAEFhwhuXeb4PqIrtoQ==
)
.expect_err("Didn't get an error");

let found = match error {
SigstoreError::SigstoreMediaTypeNotFoundError => true,
_ => false,
};
let found = matches!(error, SigstoreError::SigstoreMediaTypeNotFoundError);
assert!(found, "Got a different error type: {}", error);
}

Expand Down Expand Up @@ -725,10 +722,7 @@ JsB89BPhZYch0U0hKANx5TY+ncrm0s8bfJxxHoenAEFhwhuXeb4PqIrtoQ==
)
.expect_err("Didn't get an error");

let found = match error {
SigstoreError::SigstoreMediaTypeNotFoundError => true,
_ => false,
};
let found = matches!(error, SigstoreError::SigstoreMediaTypeNotFoundError);
assert!(found, "Got a different error type: {}", error);
}

Expand Down Expand Up @@ -758,10 +752,7 @@ JsB89BPhZYch0U0hKANx5TY+ncrm0s8bfJxxHoenAEFhwhuXeb4PqIrtoQ==
)
.expect_err("Didn't get an error");

let found = match error {
SigstoreError::SigstoreLayerDigestMismatchError => true,
_ => false,
};
let found = matches!(error, SigstoreError::SigstoreLayerDigestMismatchError);
assert!(found, "Got a different error type: {}", error);
}

Expand Down
34 changes: 14 additions & 20 deletions src/crypto/certificate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,10 +351,10 @@ mod tests {
let cert = x509_cert::Certificate::from_der(pem.contents())?;

let err = verify_key_usages(&cert).expect_err("Was supposed to return an error");
let found = match err {
SigstoreError::CertificateWithoutDigitalSignatureKeyUsage => true,
_ => false,
};
let found = matches!(
err,
SigstoreError::CertificateWithoutDigitalSignatureKeyUsage
);
assert!(found, "Didn't get expected error, got {:?} instead", err);

Ok(())
Expand All @@ -376,10 +376,7 @@ mod tests {
let cert = x509_cert::Certificate::from_der(pem.contents())?;

let err = verify_key_usages(&cert).expect_err("Was supposed to return an error");
let found = match err {
SigstoreError::CertificateWithoutCodeSigningKeyUsage => true,
_ => false,
};
let found = matches!(err, SigstoreError::CertificateWithoutCodeSigningKeyUsage);
assert!(found, "Didn't get expected error, got {:?} instead", err);

Ok(())
Expand All @@ -402,10 +399,10 @@ mod tests {
let cert = x509_cert::Certificate::from_der(pem.contents())?;

let error = verify_has_san(&cert).expect_err("Didn't get an error");
let found = match error {
SigstoreError::CertificateWithoutSubjectAlternativeName => true,
_ => false,
};
let found = matches!(
error,
SigstoreError::CertificateWithoutSubjectAlternativeName
);
assert!(found, "Didn't get the expected error: {}", error);

Ok(())
Expand Down Expand Up @@ -446,10 +443,7 @@ mod tests {
let cert = x509_cert::Certificate::from_der(pem.contents())?;

let err = verify_validity(&cert).expect_err("Was expecting an error");
let found = match err {
SigstoreError::CertificateValidityError(_) => true,
_ => false,
};
let found = matches!(err, SigstoreError::CertificateValidityError(_));
assert!(found, "Didn't get expected error, got {:?} instead", err);

Ok(())
Expand Down Expand Up @@ -508,13 +502,13 @@ mod tests {

let err = verify_expiration(&cert, integrated_time.timestamp())
.expect_err("Was expecting an error");
let found = match err {
let found = matches!(
err,
SigstoreError::CertificateIssuedAfterSignaturesSubmittedToRekor {
integrated_time: _,
not_after: _,
} => true,
_ => false,
};
}
);
assert!(found, "Didn't get expected error, got {:?} instead", err);

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion src/crypto/keyring.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ mod tests {

// Generate the key id.
let mut hasher = sha2::Sha256::new();
hasher.write(pub_key.as_slice()).unwrap();
hasher.write_all(pub_key.as_slice()).unwrap();
let key_id: [u8; 32] = hasher.finalize().into();

// Check for success.
Expand Down
15 changes: 3 additions & 12 deletions src/crypto/verification_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@

/// Verify the signature provided has been actually generated by the given key
/// when signing the provided prehashed message.
pub(crate) fn verify_prehash(&self, signature: Signature, msg: &[u8]) -> Result<()> {

Check warning on line 334 in src/crypto/verification_key.rs

View workflow job for this annotation

GitHub Actions / Check WASM

method `verify_prehash` is never used
let sig = match signature {
Signature::Raw(data) => data.to_owned(),
Signature::Base64Encoded(data) => BASE64_STD_ENGINE.decode(data)?,
Expand Down Expand Up @@ -425,10 +425,7 @@
let err = verification_key
.verify_signature(signature, msg.as_bytes())
.expect_err("Was expecting an error");
let found = match err {
SigstoreError::PublicKeyVerificationError => true,
_ => false,
};
let found = matches!(err, SigstoreError::PublicKeyVerificationError);
assert!(found, "Didn't get expected error, got {:?} instead", err);
}

Expand All @@ -443,10 +440,7 @@
let err = verification_key
.verify_signature(signature, msg.as_bytes())
.expect_err("Was expecting an error");
let found = match err {
SigstoreError::Base64DecodeError(_) => true,
_ => false,
};
let found = matches!(err, SigstoreError::Base64DecodeError(_));
assert!(found, "Didn't get expected error, got {:?} instead", err);
}

Expand All @@ -468,10 +462,7 @@
let err = verification_key
.verify_signature(signature, msg.as_bytes())
.expect_err("Was expecting an error");
let found = match err {
SigstoreError::PublicKeyVerificationError => true,
_ => false,
};
let found = matches!(err, SigstoreError::PublicKeyVerificationError);
assert!(found, "Didn't get expected error, got {:?} instead", err);
}

Expand Down
Loading