openpgp-card/tools/subplot/opgpcard.md
Nora Widdecke dfb7f3275d
opgpcard: Replace flagfile with environment variable
- A flagfile requires manual management with touch and rm, replace it
    with an environment variable that can be set more conveniently.

  - Removing tools/tests/opgpcard.rs is not necessary, the file it links
    to is always generated in build.rs, either with subplot tests or
    without. But it is always there, so cargo test does not fail for
    that reason.
2022-10-27 15:46:42 +02:00

3.3 KiB

Introduction

This document describes the requirements and acceptance criteria for the opgpcard tool, and also how to verify that they are met. This document is meant to be read and understood by all stakeholders, and processed by the Subplot tool, which also generates code to automatically perform the verification.

Note about running the tests described here

The verification scenarios in this document assume the availability of a virtual smart card. Specifically one described in https://gitlab.com/openpgp-card/virtual-cards. The openpgp-card/tools crate is set up to generate tests only if the environment variable CARD_BASED_TESTS is set (to any value), and the openpgp-card repository .gitlab-ci.yml file is set up to set that environment variable when the repository is tested in GitLab CI.

This means that if you run cargo test, no test code is normally generated from this document. To run the tests locally, outside of GitLab CI, use the script tools/cargo-test-in-docker.

Acceptance criteria

These scenarios mainly test the JSON output format of the tool. That format is meant for consumption by other tools, and it is thus more important that it stays stable. The text output that is meant for human consumption may change at will, so it's not worth testing.

Smoke test

Requirement: The tool can report its version.

Justification: This is useful mainly to make sure the tool can be run at all. As such, it acts as a simple smoke test. However, if this fails, then nothing else has a chance to work.

Note that this is not in JSON format, as it is output by the clap library, and opgpcard doesn't affect what it looks like.

given an installed opgpcard
when I run opgpcard --version
then stdout matches regex ^opgpcard \d+\.\d+\.\d+$

List cards: opgpcard list

Requirement: The tool lists available cards.

This is not at all a thorough test, but it exercises the simple happy paths of the subcommand.

given an installed opgpcard
when I run opgpcard --output-format=json list
then stdout, as JSON, matches embedded file list.json
{
   "idents": ["AFAF:00001234"]
}

Card status: opgpcard status

Requirement: The tool shows status of available cards.

This is not at all a thorough test, but it exercises the simple happy paths of the subcommand.

given an installed opgpcard
when I run opgpcard --output-format=json status
then stdout, as JSON, matches embedded file status.json
{
  "card_version": "2.0",
  "ident": "AFAF:00001234"
}

Card information: opgpcard info

Requirement: The tool shows information about available cards.

This is not at all a thorough test, but it exercises the simple happy paths of the subcommand.

given an installed opgpcard
when I run opgpcard --output-format=json info
then stdout, as JSON, matches embedded file info.json
{
  "card_version": "2.0",
  "application_id": "D276000124 01 01 0200 AFAF 00001234 0000",
  "manufacturer_id": "AFAF",
  "manufacturer_name": "Unknown",
  "card_service_data": [],
  "ident": "AFAF:00001234"
}