Crate nethsm_tests

Source
Expand description

§NetHSM containerized tests

Containerized testing environments for NetHSM related projects.

This project contains types which start virtual NetHSM instances using Podman.

§Documentation

§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§

container 🔒

Structs§

Container
A running container
NetHsmImage
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.
NAMESPACE1
Sample namespace.
NAMESPACE2
Second namespace.
NAMESPACE1_ADMIN_REAL_NAME
Real name for namespace1’s administrator.
NAMESPACE1_ADMIN_USER_ID
Administrator’s user ID for namespace1.
NAMESPACE1_ADMIN_USER_PASSPHRASE
Sample passphrase for namespace1’s administrator.
NAMESPACE1_OPERATOR_REAL_NAME
Real name of an operator in namespace1.
NAMESPACE1_OPERATOR_USER_ID
User ID of an operator in namespace1.
NAMESPACE1_OPERATOR_USER_PASSPHRASE
Sample passphrase of an operator in namespace1.
NAMESPACE2_ADMIN_REAL_NAME
Real name for namespace2’s administrator.
NAMESPACE2_ADMIN_USER_ID
Administrator’s user ID for namespace2.
NAMESPACE2_ADMIN_USER_PASSPHRASE
Sample passphrase for namespace2’s administrator.
NAMESPACE2_OPERATOR_REAL_NAME
Real name of an operator in namespace2.
NAMESPACE2_OPERATOR_USER_ID
User ID of an operator in namespace2.
NAMESPACE2_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.