Feature: Command option to add targets to the TUF repository locally.

Test results for features/commands/add_targets.local.feature

Running behat features/commands/add_targets.local.feature results in:

@rugged @commands-local @add-targets
Feature: Command option to add targets to the TUF repository locally.
  In order to benchmark TUF server performance
  As a Rugged developer
  I need to add targets to a TUF repo locally.

  Background:
    Given I reset Rugged
    And local Rugged directories exist
    And I initialize a Rugged repo
    And I am in the "/var/rugged/incoming_targets" directory

  Scenario: Add a target file.
    Given file "test0.txt" contains "test0"
    When I run the Rugged command "rugged --debug add-targets --local"
    Then I should get:
      """
      Added the following targets to the repository:
      test0.txt
      Updated targets metadata.
      Updated snapshot metadata.
      Updated timestamp metadata.
      """
    When I run "grep -r test0.txt ../tuf_repo/metadata"
    Then I should get:
      """
      targets.json
      """
    When I run "ls"
    Then I should not get:
      """
      Permission denied
      test0.txt
      """
    When I run the Rugged command "rugged logs --local --limit=0"
    Then I should get:
      """
      Scanning for inbound targets in '/var/rugged/incoming_targets'
      Found target: test0.txt
      Moved '/var/rugged/incoming_targets/test0.txt' to '/var/rugged/tuf_repo/targets/test0.txt'
      Moved inbound target 'test0.txt' to targets directory.
      Added target 'test0.txt' to 'targets' role.
      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'.
      """

  Scenario: Verify that metadata is updated.
    Given file "test0.txt" contains "test0"
    And I record a reference hash of "../tuf_repo/metadata/1.root.json"
    And the file "../tuf_repo/metadata/2.root.json" does not exist
    And I record a reference hash of "../tuf_repo/metadata/snapshot.json"
    And I record a reference hash of "../tuf_repo/metadata/targets.json"
    And I record a reference hash of "../tuf_repo/metadata/timestamp.json"
    When I run the Rugged command "rugged add-targets --local"
    Then file "../tuf_repo/metadata/1.root.json" has not changed
    And the file "../tuf_repo/metadata/2.root.json" does not exist
    And file "../tuf_repo/metadata/targets.json" has changed
    And file "../tuf_repo/metadata/snapshot.json" has changed
    And file "../tuf_repo/metadata/timestamp.json" has changed

  Scenario: Add multiple target files, including one in a subdirectory.
    Given file "test0.txt" contains "test0"
    And file "test1.txt" contains "test1"
    And the directory "foo/bar" exists
    And file "foo/bar/test2.txt" contains "test2"
    When I run the Rugged command "rugged --debug add-targets --local"
    Then I should get:
      """
      Added the following targets to the repository:
      test0.txt
      test1.txt
      foo/bar/test2.txt
      Updated targets metadata.
      Updated snapshot metadata.
      Updated timestamp metadata.
      """
    When I run "grep -r test0.txt ../tuf_repo/metadata"
    Then I should get:
      """
      targets.json
      """
    When I run "grep -r test1.txt ../tuf_repo/metadata"
    Then I should get:
      """
      targets.json
      """
    When I run "grep -r foo/bar/test2.txt ../tuf_repo/metadata"
    Then I should get:
      """
      targets.json
      """
    When I run "ls"
    Then I should not get:
      """
      test0.txt
      test1.txt
      foo
      """
    Given I am in the "/var/rugged/tuf_repo/targets" directory
    When I run "ls"
    Then I should get:
      """
      test0.txt
      test1.txt
      foo
      """
    When I run the Rugged command "rugged logs --local --limit=0"
    Then I should get:
      """
      Scanning for inbound targets in '/var/rugged/incoming_targets'
      Found target: test1.txt
      Found target: test0.txt
      Found target: foo/bar/test2.txt
      Moved '/var/rugged/incoming_targets/test1.txt' to '/var/rugged/tuf_repo/targets/test1.txt'
      Moved inbound target 'test1.txt' to targets directory.
      Added target 'test1.txt' to 'targets' role.
      Moved '/var/rugged/incoming_targets/test0.txt' to '/var/rugged/tuf_repo/targets/test0.txt'
      Moved inbound target 'test0.txt' to targets directory.
      Added target 'test0.txt' to 'targets' role.
      Moved '/var/rugged/incoming_targets/foo/bar/test2.txt' to '/var/rugged/tuf_repo/targets/foo/bar/test2.txt'
      Cleaned up empty directory '/var/rugged/incoming_targets/foo/bar'.
      Cleaned up empty directory '/var/rugged/incoming_targets/foo'.
      Moved inbound target 'foo/bar/test2.txt' to targets directory.
      Added target 'foo/bar/test2.txt' to 'targets' role.
      Signed 'targets' metadata with 'targets' key.
      Wrote 'targets' metadata to file '/var/rugged/tuf_repo/metadata/targets.json'.
      """

  Scenario: Add multiple target files, in separate invocations.
    Given file "test0.txt" contains "test0"
    When I run the Rugged command "rugged --debug add-targets --local"
    Then I should get:
      """
      Added the following targets to the repository:
      test0.txt
      Updated targets metadata.
      Updated snapshot metadata.
      Updated timestamp metadata.
      """
    When I run "grep -r test0.txt ../tuf_repo/metadata"
    Then I should get:
      """
      targets.json
      """
    When I try to run "grep -r test1.txt ../tuf_repo/metadata"
    Then I should not get:
      """
      targets.json
      """
    Given I am in the "/var/rugged/tuf_repo/targets" directory
    When I run "ls"
    Then I should get:
      """
      test0.txt
      """
    And I should not get:
      """
      test1.txt
      """
    Given I am in the "/var/rugged/incoming_targets" directory
    And file "test1.txt" contains "test1"
    When I run the Rugged command "rugged --debug add-targets --local"
    Then I should get:
      """
      Added the following targets to the repository:
      test1.txt
      Updated targets metadata.
      Updated snapshot metadata.
      Updated timestamp metadata.
      """
    When I run "grep -r test0.txt ../tuf_repo/metadata"
    Then I should get:
      """
      targets.json
      """
    When I run "grep -r test1.txt ../tuf_repo/metadata"
    Then I should get:
      """
      targets.json
      """
    Given I am in the "/var/rugged/tuf_repo/targets" directory
    When I run "ls"
    Then I should get:
      """
      test0.txt
      test1.txt
      """

  @gitlab-149
  Scenario: Ensure that empty directories are cleaned up.
    Given the directory "not_empty_dir" exists
    And file "not_empty_dir/test0.txt" contains "test0"
    And the directory "empty_dir" exists
    And the directory "deeply/nested/empty/directory" exists
    When I run the Rugged command "rugged --debug add-targets --local"
    And I run the Rugged command "rugged logs --local --limit=0"
    Then I should get:
      """
      Cleaned up empty directory '/var/rugged/incoming_targets/not_empty_dir'.
      Scanning for empty directories in inbound targets: '/var/rugged/incoming_targets'
      Cleaned up empty directory '/var/rugged/incoming_targets/empty_dir'.
      Cleaned up empty directory '/var/rugged/incoming_targets/deeply/nested/empty/directory'.
      Cleaned up empty directory '/var/rugged/incoming_targets/deeply/nested/empty'.
      Cleaned up empty directory '/var/rugged/incoming_targets/deeply/nested'.
      Cleaned up empty directory '/var/rugged/incoming_targets/deeply'.
      """
    And the "/var/rugged/incoming_targets/not_empty_dir" directory should not exist
    And the "/var/rugged/incoming_targets/empty_dir" directory should not exist
    And the "/var/rugged/incoming_targets/deeply" directory should not exist
    And the "/var/rugged/incoming_targets" directory should exist

5 scenarios (5 passed)
93 steps (93 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.