Expand description
§NetHSM containerized tests
Containerized testing environments for NetHSM related projects.
This project contains types which start virtual NetHSM instances using Podman.
§Documentation
- https://signstar.archlinux.page/rustdoc/nethsm_tests/ for development version of the crate
- https://docs.rs/nethsm_tests/latest/nethsm_tests/ for released versions of the crate
§Example
The following integration test starts a NetHSM container with users to retrieve several random bytes:
use nethsm::Credentials;
use nethsm::NetHsm;
use nethsm::Passphrase;
use nethsm_tests::nethsm_with_users;
use nethsm_tests::NetHsmImage;
use nethsm_tests::DEFAULT_OPERATOR_USER_ID;
use nethsm_tests::DEFAULT_OPERATOR_USER_PASSPHRASE;
use rustainers::Container;
use testresult::TestResult;
pub static LENGTH: u32 = 32;
#[ignore = "requires Podman"]
#[rstest::rstest]
#[tokio::test]
async fn get_random_bytes(
#[future] nethsm_with_users: TestResult<(NetHsm, Container<NetHsmImage>)>,
) -> TestResult {
let (nethsm, _container) = nethsm_with_users.await?;
nethsm.add_credentials(Credentials::new(
DEFAULT_OPERATOR_USER_ID.parse()?,
Some(Passphrase::new(
DEFAULT_OPERATOR_USER_PASSPHRASE.to_string(),
)),
));
nethsm.use_credentials(&DEFAULT_OPERATOR_USER_ID.parse()?)?;
let random_message = nethsm.random(LENGTH)?;
println!("A random message from the NetHSM: {:#?}", random_message);
assert_eq!(usize::try_from(LENGTH)?, random_message.len(),);
Ok(())
}
§Contributing
Please refer to the contributing guidelines to learn how to contribute to this project.
§License
This project may be used under the terms of the Apache-2.0 or MIT license.
Changes to this project - unless stated otherwise - automatically fall under the terms of both of the aforementioned licenses.
Modules§
Structs§
- An image of NetHSM used to create a running container.
Statics§
- Identifier for an admin user.
- Sample admin passphrase.
- User ID for backup purposes.
- Sample passphrase for the backup user.
- Real name for the backup user.
- Default size for the AES key in bits.
- Default ID for a key.
- Default user ID for an operator.
- Sample operator passphrase.
- Default real name for an operator.
- Default size of the RSA key in bits.
- Default tag.
- Default ID for the encryption key.
- User ID for the operator user who can access the encryption key.
- Sample passphrase for the operator user who can access the encryption key.
- Real name for the operator user who can access the encryption key.
- Default tag for the encryption key.
- User ID for the metrics user.
- Sample passphrase for the metrics user.
- Real name for the metrics user.
- Sample namespace.
- Second namespace.
- Real name for
namespace1
’s administrator. - Administrator’s user ID for
namespace1
. - Sample passphrase for
namespace1
’s administrator. - Real name of an operator in
namespace1
. - User ID of an operator in
namespace1
. - Sample passphrase of an operator in
namespace1
. - Real name for
namespace2
’s administrator. - Administrator’s user ID for
namespace2
. - Sample passphrase for
namespace2
’s administrator. - Real name of an operator in
namespace2
. - User ID of an operator in
namespace2
. - Sample passphrase of an operator in
namespace2
. - Default ID for a different key.
- User ID for a different user.
- Sample passphrase for a different user.
- Real name for a different user.
- Different tag.
- Sample unlock passphrase.
Functions§
- Creates and starts a new NetHSM container.
- Creates a new [NetHsm] object configured with administrator credentials.
- Adds users and keys to an already provisioned NetHSM container.
- Creates a new [NetHsm] object pointing at a NetHSM container with users.
- Creates a new [NetHsm] object pointing at a provisioned NetHSM container.
- Returns a new [NetHsm] object pointing to an unprovisioned NetHSM.
- Downloads an update file if it’s not already present.