1#!/usr/bin/env bats 2 3load _test_base 4 5 6function setup { 7 install_fixture_key "$TEST_DEFAULT_USER" 8 9 set_state_initial 10 set_state_git 11 set_state_secret_init 12} 13 14 15function teardown { 16 uninstall_fixture_key "$TEST_DEFAULT_USER" 17 unset_current_state 18} 19 20@test "run 'tell' on substring of emails" { 21 run git secret tell -d "$TEST_GPG_HOMEDIR" user 22 # this should give an error because there is no user named 'user', 23 # even though there are users with the substring 'user'. 24 # See issue https://github.com/sobolevn/git-secret/issues/176 25 [ "$status" -eq 1 ] 26 27 run git secret whoknows 28 [ "$status" -eq 1 ] # should error when there are no users told 29 30} 31 32@test "fail on no users" { 33 run _user_required 34 [ "$status" -eq 1 ] 35} 36 37 38@test "constantly fail on no users" { 39 # We had a serious bug with _user_required, 40 # see this link for the details: 41 # https://github.com/sobolevn/git-secret/issues/74 42 43 # Preparations: 44 git secret tell -d "$TEST_GPG_HOMEDIR" "$TEST_DEFAULT_USER" 45 git secret killperson "$TEST_DEFAULT_USER" 46 47 # It was showing something like `tru::1:1289775241:0:2:1:6` 48 # after the preparations done and the error was not generated. 49 run _user_required 50 [ "$status" -eq 1 ] 51} 52 53 54@test "run 'tell' with secret-key imported" { 55 local secrets_dir_keys 56 secrets_dir_keys=$(_get_secrets_dir_keys) 57 58 local private_key="$secrets_dir_keys/secring.gpg" 59 echo "private key" > "$private_key" 60 [ -s "$private_key" ] 61 62 run git secret tell -d "$TEST_GPG_HOMEDIR" "$TEST_DEFAULT_USER" 63 [ "$status" -eq 1 ] 64} 65 66 67@test "run 'tell' without '.gitsecret'" { 68 local secrets_dir 69 secrets_dir=$(_get_secrets_dir) 70 71 rm -r "$secrets_dir" 72 73 run git secret tell -d "$TEST_GPG_HOMEDIR" "$TEST_DEFAULT_USER" 74 [ "$status" -eq 1 ] 75} 76 77 78@test "run 'tell' without arguments" { 79 run git secret tell 80 [ "$status" -eq 1 ] 81} 82 83 84@test "run 'tell' normally" { 85 run git secret tell -d "$TEST_GPG_HOMEDIR" "$TEST_DEFAULT_USER" 86 [ "$status" -eq 0 ] 87 88 # Testing that now user is found: 89 run _user_required 90 [ "$status" -eq 0 ] 91 92 # Testing that now user is in the list of people who knows the secret: 93 run git secret whoknows 94 [[ "$output" == *"$TEST_DEFAULT_USER"* ]] 95} 96 97 98@test "run 'tell' with '-m'" { 99 local email="$TEST_DEFAULT_USER" 100 101 git_set_config_email "$email" 102 run git secret tell -d "$TEST_GPG_HOMEDIR" -m 103 [ "$status" -eq 0 ] 104} 105 106 107@test "run 'tell' with '-m' (empty email)" { 108 # Prepartions: 109 git_set_config_email "" # now it should not allow to add yourself 110 111 run git secret tell -d "$TEST_GPG_HOMEDIR" -m 112 [ "$status" -eq 1 ] 113} 114 115 116@test "run 'tell' with multiple emails" { 117 # Preparations: 118 install_fixture_key "$TEST_SECOND_USER" 119 120 # Testing the command iteself: 121 run git secret tell -d "$TEST_GPG_HOMEDIR" \ 122 "$TEST_DEFAULT_USER" "$TEST_SECOND_USER" 123 124 [ "$status" -eq 0 ] 125 126 # Testing that these users are presented in the 127 # list of people who knows secret: 128 run git secret whoknows 129 130 [[ "$output" == *"$TEST_DEFAULT_USER"* ]] 131 [[ "$output" == *"$TEST_SECOND_USER"* ]] 132 133 # Cleaning up: 134 uninstall_fixture_key "$TEST_SECOND_USER" 135} 136 137 138@test "run 'tell' in subfolder" { 139 if [[ "$BATS_RUNNING_FROM_GIT" -eq 1 ]]; then 140 skip "this test is skipped while 'git commmit'" 141 fi 142 143 # Preparations 144 local root_dir='test_dir' 145 local test_dir="$root_dir/telling" 146 local current_dir=$(pwd) 147 148 mkdir -p "$test_dir" 149 cd "$test_dir" 150 151 # Test: 152 run git secret tell -d "$TEST_GPG_HOMEDIR" "$TEST_DEFAULT_USER" 153 [ "$status" -eq 0 ] 154 155 # Testing that now user is found: 156 run _user_required 157 [ "$status" -eq 0 ] 158 159 # Testing that now user is in the list of people who knows the secret: 160 run git secret whoknows 161 [[ "$output" == *"$TEST_DEFAULT_USER"* ]] 162 163 # Cleaning up: 164 cd "$current_dir" 165 rm -r "$root_dir" 166} 167