Feature: Command to initialize Rugged TUF repository.

Test results for features/commands/initialize.root_worker.feature

Running behat features/commands/initialize.root_worker.feature results in:

@rugged @commands @initialize
Feature: Command to initialize Rugged TUF repository.
  In order to host TUF metadata
  As an administrator
  I need to initialize a TUF repo.

  Background:
    Given I reset Rugged

  Scenario: Initialize repository.
    When I run the Rugged command "rugged generate-keys"
    When I run the Rugged command "rugged --debug initialize"
    Then I should get:
      """
      TUF repository initialized.
      """
    And the "/var/rugged/tuf_repo/targets" directory should exist
    When I run the Rugged command "rugged logs --worker=root-worker --limit=0"
    Then I should get:
      """
      Received 'initialize' task.
      Instantiated repository.
      Signed 'targets' metadata with 'targets' key.
      Wrote 'targets' metadata to file '/var/rugged/tuf_repo/metadata/targets.json'.
      Signed 'snapshot' metadata with 'snapshot' key.
      Wrote 'snapshot' metadata to file '/var/rugged/tuf_repo/metadata/snapshot.json'.
      Signed 'timestamp' metadata with 'timestamp' key.
      Wrote 'timestamp' metadata to file '/var/rugged/tuf_repo/metadata/timestamp.json'.
      Signed 'root' metadata with 'root' key.
      Signed 'root' metadata with 'root1' key.
      Wrote 'root' metadata to file '/var/rugged/tuf_repo/metadata/1.root.json'.
      TUF repository initialized.
      """
    When I run "ls /var/rugged/tuf_repo"
    Then I should get:
      """
      metadata
      targets
      """
    And I should not get:
      """
      Permission denied
      """
    When I run "ls /var/rugged/tuf_repo/metadata"
    Then I should get:
      """
      1.root.json
      """

  @gitlab-123
  Scenario: Repo instantiation does not try to access unavailable keys.
    Given I run the Rugged command "rugged generate-keys"
    And I run the Rugged command "rugged initialize"
    And I run the Rugged command "rugged logs --truncate"
    When I run the Rugged command "rugged --debug status --worker=snapshot-worker"
    And I run the Rugged command "rugged logs --worker=snapshot-worker --limit=0"
    Then I should get:
      """
      Instantiated repository.
      Loaded metadata for 'targets' role from '/var/rugged/tuf_repo/metadata/targets.json'.
      Loaded metadata for 'snapshot' role from '/var/rugged/tuf_repo/metadata/snapshot.json'.
      Loaded metadata for 'timestamp' role from '/var/rugged/tuf_repo/metadata/timestamp.json'.
      Loaded metadata for 'root' role from '/var/rugged/tuf_repo/metadata/1.root.json'.
      Loaded all metadata.
      """
    And I should not get:
      """
      UnsignedMetadataError thrown in sign_metadata: Problem signing the metadata
      Failed to sign 'targets' metadata with 'targets' key.
      UnsignedMetadataError thrown in sign_metadata: Problem signing the metadata
      Failed to sign 'timestamp' metadata with 'timestamp' key.
      UnsignedMetadataError thrown in sign_metadata: Problem signing the metadata
      Failed to sign 'root' metadata with 'root1' key.
      UnsignedMetadataError thrown in sign_metadata: Problem signing the metadata
      Failed to sign 'root' metadata with 'root' key.
      """
    And I should not get:
      """
      Signed 'targets' metadata with 'targets' key.
      Signed 'snapshot' metadata with 'snapshot' key.
      Signed 'timestamp' metadata with 'timestamp' key.
      Signed 'root' metadata with 'root' key.
      Signed 'root' metadata with 'root1' key.
      """

  Scenario: Fail gracefully on initialization errors.
    Given I run "sudo chmod 000 /var/rugged/tuf_repo"
    When I fail to run the Rugged command "rugged --debug initialize"
    Then I should get:
      """
      error: Failed to initialize repository at /var/rugged/tuf_repo.
      Failed to initialize TUF repository. Check the logs for more detailed error reporting.
      """
    And I should not get:
      """
      TUF repository initialized.
      """
    When I run the Rugged command "rugged logs --worker=root-worker --limit=0"
    Then I should get:
      """
      Received 'initialize' task.
      Initializing new TUF repository locally.
      Initializing new TUF repository at /var/rugged/tuf_repo.
      PermissionError thrown in _init_dirs: [Errno 13] Permission denied: '/var/rugged/tuf_repo/metadata'
      RuggedStorageError: The repository could not create the needed directories.
      RuggedStorageError thrown in __init__: The repository could not create the needed directories.
      Failed to instantiate repository.
      RuggedRepositoryError: The repository could not load a repository at the given path.
      RuggedRepositoryError thrown in init_repo: The repository could not load a repository at the given path.
      Failed to initialize repository at /var/rugged/tuf_repo.
      """
    And I should not get:
      """
      TUF repository initialized.
      """

  Scenario: Fail gracefully on metadata errors.
    Given I run the Rugged command "rugged generate-keys --role=root"
    And I run the Rugged command "rugged generate-keys --role=snapshot"
    And I run the Rugged command "rugged generate-keys --role=timestamp"
    Given the file "/var/rugged/verification_keys/targets/targets.pub" does not exist
    When I fail to run the Rugged command "rugged --debug initialize"
    Then I should get:
      """
      error: Failed to generate metadata during TUF repository initialization.
      Failed to initialize TUF repository. Check the logs for more detailed error reporting.
      """
    And I should not get:
      """
      TUF repository initialized.
      """
    When I run the Rugged command "rugged logs --worker=root-worker --limit=0"
    Then I should get:
      """
      Failed to load 'targets' keys for 'targets' role.
      No keys loaded for 'targets' keypair for 'targets' role.
      No 'targets' key in keychain for 'targets' role.
      Failed to generate metadata during TUF repository initialization.
      RuggedMetadataError: No key available to sign 'targets' metadata.
      RuggedMetadataError thrown in init_repo: No key available to sign 'targets' metadata.
      """
    And I should not get:
      """
      TUF repository initialized.
      """

4 scenarios (4 passed)
40 steps (40 passed)
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
Rugged TUF Server is a trademark of Consensus Enterprises.