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§
- Container
- A running container
- NetHsm
Image - An image of NetHSM used to create a running container.
- nethsm_
with_ keys - nethsm_
with_ users - provisioned_
nethsm - unprovisioned_
nethsm - update_
file
Statics§
- ADMIN_
USER_ ID - Identifier for an admin user.
- ADMIN_
USER_ PASSPHRASE - Sample admin passphrase.
- BACKUP_
USER_ ID - User ID for backup purposes.
- BACKUP_
USER_ PASSPHRASE - Sample passphrase for the backup user.
- BACKUP_
USER_ REAL_ NAME - Real name for the backup user.
- DEFAULT_
AES_ BITS - Default size for the AES key in bits.
- DEFAULT_
KEY_ ID - Default ID for a key.
- DEFAULT_
OPERATOR_ USER_ ID - Default user ID for an operator.
- DEFAULT_
OPERATOR_ USER_ PASSPHRASE - Sample operator passphrase.
- DEFAULT_
OPERATOR_ USER_ REAL_ NAME - Default real name for an operator.
- DEFAULT_
RSA_ BITS - Default size of the RSA key in bits.
- DEFAULT_
TAG - Default tag.
- ENC_
KEY_ ID - Default ID for the encryption key.
- ENC_
OPERATOR_ USER_ ID - User ID for the operator user who can access the encryption key.
- ENC_
OPERATOR_ USER_ PASSPHRASE - Sample passphrase for the operator user who can access the encryption key.
- ENC_
OPERATOR_ USER_ REAL_ NAME - Real name for the operator user who can access the encryption key.
- ENC_TAG
- Default tag for the encryption key.
- METRICS_
USER_ ID - User ID for the metrics user.
- METRICS_
USER_ PASSPHRASE - Sample passphrase for the metrics user.
- METRICS_
USER_ REAL_ NAME - Real name for the metrics user.
- NAMESPAC
E1 - Sample namespace.
- NAMESPAC
E2 - Second namespace.
- NAMESPAC
E1_ ADMIN_ REAL_ NAME - Real name for
namespace1
’s administrator. - NAMESPAC
E1_ ADMIN_ USER_ ID - Administrator’s user ID for
namespace1
. - NAMESPAC
E1_ ADMIN_ USER_ PASSPHRASE - Sample passphrase for
namespace1
’s administrator. - NAMESPAC
E1_ OPERATOR_ REAL_ NAME - Real name of an operator in
namespace1
. - NAMESPAC
E1_ OPERATOR_ USER_ ID - User ID of an operator in
namespace1
. - NAMESPAC
E1_ OPERATOR_ USER_ PASSPHRASE - Sample passphrase of an operator in
namespace1
. - NAMESPAC
E2_ ADMIN_ REAL_ NAME - Real name for
namespace2
’s administrator. - NAMESPAC
E2_ ADMIN_ USER_ ID - Administrator’s user ID for
namespace2
. - NAMESPAC
E2_ ADMIN_ USER_ PASSPHRASE - Sample passphrase for
namespace2
’s administrator. - NAMESPAC
E2_ OPERATOR_ REAL_ NAME - Real name of an operator in
namespace2
. - NAMESPAC
E2_ OPERATOR_ USER_ ID - User ID of an operator in
namespace2
. - NAMESPAC
E2_ OPERATOR_ USER_ PASSPHRASE - Sample passphrase of an operator in
namespace2
. - OTHER_
KEY_ ID - Default ID for a different key.
- OTHER_
OPERATOR_ USER_ ID - User ID for a different user.
- OTHER_
OPERATOR_ USER_ PASSPHRASE - Sample passphrase for a different user.
- OTHER_
OPERATOR_ USER_ REAL_ NAME - Real name for a different user.
- OTHER_
TAG - Different tag.
- UNLOCK_
PASSPHRASE - Sample unlock passphrase.
Functions§
- add_
keys_ 🔒to_ nethsm - add_
users_ 🔒to_ nethsm - create_
container - Creates and starts a new NetHSM container.
- create_
nethsm - Creates a new [NetHsm] object configured with administrator credentials.
- nethsm_
with_ keys - Adds users and keys to an already provisioned NetHSM container.
- nethsm_
with_ users - Creates a new [NetHsm] object pointing at a NetHSM container with users.
- provision_
nethsm 🔒 - provisioned_
nethsm - Creates a new [NetHsm] object pointing at a provisioned NetHSM container.
- unprovisioned_
nethsm - Returns a new [NetHsm] object pointing to an unprovisioned NetHSM.
- update_
file - Downloads an update file if it’s not already present.