File: check.rs

package info (click to toggle)
rust-sequoia-policy-config 0.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 476 kB
  • sloc: makefile: 5
file content (92 lines) | stat: -rw-r--r-- 2,365 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
use std::env::current_dir;

use sequoia_openpgp as openpgp;
use openpgp::Result;

use assert_cmd::Command;
// use predicates::prelude::*;

#[test]
fn bad_config() -> Result<()> {
    let cwd = current_dir()?;
    println!("The current directory is {}", cwd.display());

    let mut cmd = Command::cargo_bin("sequoia-policy-config-check")?;
    let assert = cmd.arg("tests/config/bad.toml")
        .assert();
    assert.failure();

    Ok(())
}

#[test]
fn good_config() -> Result<()> {
    let cwd = current_dir()?;
    println!("The current directory is {}", cwd.display());

    let mut cmd = Command::cargo_bin("sequoia-policy-config-check")?;
    let assert = cmd.arg("tests/config/good.toml")
        .assert();
    assert.success();

    Ok(())
}

#[test]
fn bad_config_env() -> Result<()> {
    let cwd = current_dir()?;
    println!("The current directory is {}", cwd.display());

    let mut cmd = Command::cargo_bin("sequoia-policy-config-check")?;
    let cmd = cmd.env(
        "SEQUOIA_CRYPTO_POLICY",
        format!("{}/{}", cwd.display(), "tests/config/bad.toml"));
    let assert = cmd.assert();
    assert.failure();

    Ok(())
}

#[test]
fn good_config_env() -> Result<()> {
    let cwd = current_dir()?;
    println!("The current directory is {}", cwd.display());

    let mut cmd = Command::cargo_bin("sequoia-policy-config-check")?;
    let cmd = cmd.env(
        "SEQUOIA_CRYPTO_POLICY",
        format!("{}/{}", cwd.display(), "tests/config/good.toml"));
    let assert = cmd.assert();
    assert.success();

    Ok(())
}

// If no configuration is supplied, this will just read the default
// configuration.
#[test]
fn no_args() -> Result<()> {
    let mut cmd = Command::cargo_bin("sequoia-policy-config-check")?;
    // Make the default config a no-op in case the system
    // configuration is bad.
    cmd.env("SEQUOIA_CRYPTO_POLICY", "");
    let assert = cmd.assert();
    assert.success();

    Ok(())
}

// Using a relative path in "SEQUOIA_CRYPTO_POLICY" is not allowed.
#[test]
fn relative_path_env() -> Result<()> {
    let cwd = current_dir()?;
    println!("The current directory is {}", cwd.display());

    let mut cmd = Command::cargo_bin("sequoia-policy-config-check")?;
    let cmd = cmd.env(
        "SEQUOIA_CRYPTO_POLICY", "tests/config/good.toml");
    let assert = cmd.assert();
    assert.failure();

    Ok(())
}