all repos — dot @ master

Shell, editor and terminal configuration, and the tools that go with them

secrets/test/put.sh (view raw)

 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
#!/bin/bash
# Tests for put command

this_dir="$(cd "$(dirname "$0")" && pwd)"
source "${this_dir}/common.sh"

test_put_creates_file() {
    echo "test-value" | szecret put "test-secret"
    assert_file_exists "${SZECRET_STORE}/test-secret.age" "put creates encrypted file"
    pass "put creates file"
}

test_put_overwrites() {
    echo "original" | szecret put "overwrite-test"
    echo "updated" | szecret put "overwrite-test"

    local retrieved
    retrieved="$(szecret get "overwrite-test")"
    assert_equals "updated" "${retrieved}" "overwritten value"
    pass "put overwrites existing secret"
}

test_put_requires_name() {
    assert_failure szecret put
    pass "put requires secret name"
}

run_tests() {
    test_put_creates_file
    test_put_overwrites
    test_put_requires_name
}

[[ "${BASH_SOURCE[0]}" == "${0}" ]] && run_tests