File: test_expiration.bats

package info (click to toggle)
git-secret 0.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 2,724 kB
  • sloc: sh: 4,580; makefile: 162; xml: 31; python: 22
file content (75 lines) | stat: -rw-r--r-- 1,927 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
#!/usr/bin/env bats

export TZ="GMT"

load _test_base


function setup {
  install_fixture_key "$TEST_EXPIRED_USER"

  set_state_initial
  set_state_git
  set_state_secret_init
  set_state_secret_tell "$TEST_EXPIRED_USER"
}


function teardown {
  uninstall_fixture_key "$TEST_EXPIRED_USER"
  unset_current_state
}


@test "run 'hide' using expired key" {
  FILE_TO_HIDE="$TEST_DEFAULT_FILENAME"
  FILE_CONTENTS="hidden content юникод"
  set_state_secret_add "$FILE_TO_HIDE" "$FILE_CONTENTS"

  run git secret hide
  # this will fail, because we're using an expired key

  # echo "$output" | sed "s/^/# '$BATS_TEST_DESCRIPTION' output: /" >&3
    # output will look like:
    # 'abort: problem encrypting file with gpg: exit code 2: space file'
  # echo "# status of hide: $status" >&3

  [ $status -ne 0 ] # we expect failure here. Actual code is 2
}


@test "run 'whoknows' using expired key" {
  run git secret whoknows
  [ $status -eq 0 ]
}

@test "run 'whoknows -l' on only expired user" {
  run git secret whoknows -l
  [ "$status" -eq 0 ]

  # diag output for bats-core
  # echo "$output" | sed "s/^/# '$BATS_TEST_DESCRIPTION' output: /" >&3
  # output should look like 'abort: problem encrypting file with gpg: exit code 2: space file'

  # echo "# $BATS_TEST_DESCRIPTION: $status" >&3

  # Now test the output, both users should be present:
  [[ "$output" == *"$TEST_EXPIRED_USER (expires: 2018-09-23)"* ]]
}


@test "run 'whoknows -l' on normal key and expired key" {
  install_fixture_key "$TEST_DEFAULT_USER"
  set_state_secret_tell "$TEST_DEFAULT_USER"

  run git secret whoknows -l
  [ "$status" -eq 0 ]

  #echo "$output" | sed "s/^/# '$BATS_TEST_DESCRIPTION' output: /" >&3

  # Now test the output, both users should be present:
  [[ "$output" == *"$TEST_DEFAULT_USER (expires: never)"* ]]
  [[ "$output" == *"$TEST_EXPIRED_USER (expires: 2018-09-23)"* ]]

  uninstall_fixture_key "$TEST_DEFAULT_USER"
}