-
Notifications
You must be signed in to change notification settings - Fork 30
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
feature-gate tests that use generate
#254
Comments
All the tests calling I think the issue here is, calling
orion/.github/workflows/test.yml Line 80 in cfa2c0c
Or did you mean other tests? |
If we can get doctests working without default features, by gating those that e.g. generate keys, that would be very useful. But I suspect most doctests make use of Some, like hashing, could be in scope though. |
@vlmutolo I'll remove the bug-label and add the improvement-label instead. Let me know if I misunderstood something here. |
Yes, good point. I hadn't realized that it was only the doctests failing.
So I guess it just depends on what "bug" means. It's certainly not as severe as a runtime bug or security issue. But I'd probably consider doctests failing under esoteric-but-valid combinations of features to be a (minor) bug. |
I understand where you're coming from. I don't think it's the best state-of-affairs either. My initial thoughts on how this could be approached, is simply feature-gating the actual doc-tests that use //! # #[cfg(feature = "safe_api")] { // ADDED HERE
//! use orion::hazardous::aead;
//!
//! let secret_key = aead::xchacha20poly1305::SecretKey::generate();
//! let nonce = aead::xchacha20poly1305::Nonce::generate();
//! let ad = "Additional data".as_bytes();
//! let message = "Data to protect".as_bytes();
//!
//! // Length of the above message is 15 and then we accommodate 16 for the Poly1305
//! // tag.
//!
//! let mut dst_out_ct = [0u8; 15 + 16];
//! let mut dst_out_pt = [0u8; 15];
//! // Encrypt and place ciphertext + tag in dst_out_ct
//! aead::xchacha20poly1305::seal(&secret_key, &nonce, message, Some(&ad), &mut dst_out_ct)?;
//! // Verify tag, if correct then decrypt and place message in dst_out_pt
//! aead::xchacha20poly1305::open(&secret_key, &nonce, &dst_out_ct, Some(&ad), &mut dst_out_pt)?;
//!
//! assert_eq!(dst_out_pt.as_ref(), message.as_ref());
//! # Ok::<(), orion::errors::UnknownCryptoError>(()) } // ADDED HERE With this, we still get the documentation generated even when generating with However, if a user compiles docs with the above example, then runs tests, they might expect to be able to use e.g. So what do you think about feature-gating those tests failing for |
This is very interesting. I don't think I've seen a conditional compilation macro applied this way before. I think this is a good solution.
I'm not too worried about that scenario. It's still a compile-time error to try to use generate when it's not available, and the docs are effective at communicating when you need it, like you said. I'll just throw out one other solution for consideration. We could expose the feature-gating in the doctest itself. Maybe something like the following: #[cfg(feature = "safe_api")]
let secret_key = aead::xchacha20poly1305::SecretKey::generate();
#[cfg(not(feature = "safe_api"))]
let secret_key = aead::xchacha20poly1305::SecretKey::from(b"do_it_yourself");
// Etc On one hand, this is pretty clear about what features need to be used and it also should pass tests without default features. On the other hand, it kind of clutters the doctest and distracts from the main example for each of the tests. |
Makes sense.
I thought about this approach as well, but opted for the other one because I thought plastering the examples would make them unreadable. I tihnk it's worth prioritizing as simple as possible and secure examples. Because of that, I'm leaning more towards my initial suggestion, unless you have other concerns. |
That sounds like a good plan to me. Keeping the documentation easy to understand is critical. |
A tentative list of modules that use
Added to scope of next minor release. |
Description
Tests currently fail with
cargo test --no-default-features
.Additional information
It seems like this is happening because lots of the tests generate a random key. We could probably just feature-gate all those tests behind
getrandom
or maybesafe_api
. Thoughts?default-features = false
723d9ef11c2b4e5f2f7746ffa9392c7cea5d8dbf
$ rustc -V : rustc 1.56.0 (09c42c458 2021-10-18)
We should probably also make sure the CI is testing no "no enabled features" case.
The text was updated successfully, but these errors were encountered: