2016-02-21 13:26:17 +00:00
|
|
|
#!/usr/bin/env bats
|
|
|
|
|
|
|
|
load _test_base
|
|
|
|
|
|
|
|
|
|
|
|
function setup {
|
|
|
|
install_fixture_key "$TEST_DEFAULT_USER"
|
Version 0.2.2 pre-release
There are a lot of changes, multiple things were refactored: tests,
some commands, building and meta.
Several critical bugs fixed.
Changes:
1. Fixed #74, when `_user_required` was not working after reimporting keys
2. Closes #73, now it is possible to provide multiple emails to the `killperson` command
3. Closes #72, now it is possible to provide multiple emails to the `tell` command
4. Closes #71, now every doc in this project refer to `git-secret.io` instead of old `gh-pages` website
5. Closes #70, now installation section is removed from main `man` file
6. Closes #69, now "See also" section in the `man`s are clickable
7. Closes #61, added "Manual" section to the manuals
8. Refs #38, added `centos` Dockerfile, but `ci` testing is still failing
9. Refs #52, tests are refactored. Added `clean` command tests, removed a lot of hardcoded things, moved tests execution from `./temp` folder to `/tmp`, added a lot of new check in old tests, and some new test cases
10. Refactored `hide` and `clean` commands to be shorter
11. `shellcheck` is now supported with `make lint`
Additional features are not comming to 0.2.2 after this commit.
2017-02-26 13:38:46 +00:00
|
|
|
|
|
|
|
set_state_initial
|
2016-02-21 13:26:17 +00:00
|
|
|
set_state_git
|
|
|
|
set_state_secret_init
|
|
|
|
set_state_secret_tell "$TEST_DEFAULT_USER"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function teardown {
|
|
|
|
uninstall_fixture_key "$TEST_DEFAULT_USER"
|
|
|
|
unset_current_state
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-05 21:46:49 +00:00
|
|
|
@test "run 'add' normally" {
|
2017-03-06 10:14:44 +00:00
|
|
|
# Preparations:
|
2018-07-14 19:23:17 +00:00
|
|
|
local filename="$TEST_DEFAULT_FILENAME"
|
2017-03-05 21:46:49 +00:00
|
|
|
echo "content" > "$filename"
|
|
|
|
echo "$filename" > ".gitignore"
|
|
|
|
|
2019-10-09 18:05:31 +00:00
|
|
|
run git secret add "$filename"
|
2017-03-05 21:46:49 +00:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
|
|
|
# Ensuring that path mappings was set correctly:
|
|
|
|
local path_mappings
|
|
|
|
path_mappings=$(_get_secrets_dir_paths_mapping)
|
|
|
|
|
|
|
|
local files_list=$(cat "$path_mappings")
|
|
|
|
[ "$files_list" = "$filename" ]
|
2017-03-06 10:14:44 +00:00
|
|
|
|
|
|
|
# Cleaning up:
|
|
|
|
rm "$filename" ".gitignore"
|
2017-03-05 21:46:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-31 00:13:54 +00:00
|
|
|
@test "run 'add' with bad arg" {
|
|
|
|
local test_file="$TEST_DEFAULT_FILENAME"
|
|
|
|
touch "$test_file"
|
|
|
|
echo "content" > "$test_file"
|
|
|
|
|
2019-10-09 18:05:31 +00:00
|
|
|
run git secret add -Z "$test_file"
|
2019-03-31 00:13:54 +00:00
|
|
|
[ "$status" -ne 0 ]
|
|
|
|
|
|
|
|
rm "$test_file"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-20 12:03:28 +00:00
|
|
|
@test "run 'add' for file ignored by default" {
|
2018-07-14 19:23:17 +00:00
|
|
|
local test_file="$TEST_DEFAULT_FILENAME"
|
2017-03-06 10:14:44 +00:00
|
|
|
touch "$test_file"
|
|
|
|
echo "content" > "$test_file"
|
2016-02-21 13:26:17 +00:00
|
|
|
|
2019-10-09 18:05:31 +00:00
|
|
|
run git secret add "$test_file"
|
2019-03-20 12:03:28 +00:00
|
|
|
[ "$status" -eq 0 ]
|
2016-10-03 15:44:37 +00:00
|
|
|
|
2017-03-06 10:14:44 +00:00
|
|
|
rm "$test_file"
|
2016-02-21 13:26:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-20 12:03:28 +00:00
|
|
|
@test "run 'add' for file ignored with '-i'" {
|
|
|
|
local test_file="$TEST_DEFAULT_FILENAME"
|
2017-03-06 10:14:44 +00:00
|
|
|
touch "$test_file"
|
|
|
|
echo "content" > "$test_file"
|
2016-05-14 11:03:33 +00:00
|
|
|
|
2019-03-20 12:03:28 +00:00
|
|
|
# add -i is now a no-op (See #225) so this tests that -i does nothing.
|
2019-10-09 18:05:31 +00:00
|
|
|
run git secret add -i "$test_file"
|
2016-05-14 11:03:33 +00:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
2019-10-09 18:05:31 +00:00
|
|
|
run _file_has_line "$test_file" ".gitignore"
|
2016-05-14 11:03:33 +00:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
2017-03-06 10:14:44 +00:00
|
|
|
rm "$test_file"
|
2016-05-14 11:03:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-20 12:03:28 +00:00
|
|
|
@test "run 'add' for file ignored by default and with '-i' in subfolder" {
|
2017-03-05 21:46:49 +00:00
|
|
|
# This test covers this issue:
|
|
|
|
# https://github.com/sobolevn/git-secret/issues/85 task 1
|
2016-02-21 13:26:17 +00:00
|
|
|
|
2017-03-05 21:46:49 +00:00
|
|
|
if [[ "$BATS_RUNNING_FROM_GIT" -eq 1 ]]; then
|
2019-02-10 21:44:21 +00:00
|
|
|
# See #334 for more about this
|
|
|
|
skip "this test is skipped while 'git commit'"
|
2017-03-05 21:46:49 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Preparations:
|
|
|
|
local test_dir='test_dir'
|
|
|
|
local nested_dir="$test_dir/adding"
|
|
|
|
local current_dir=$(pwd)
|
|
|
|
|
|
|
|
mkdir -p "$nested_dir"
|
|
|
|
cd "$nested_dir"
|
|
|
|
|
2017-03-06 10:14:44 +00:00
|
|
|
local test_file='test_file.auto_ignore'
|
|
|
|
touch "$test_file"
|
|
|
|
echo "content" > "$test_file"
|
2017-03-05 21:46:49 +00:00
|
|
|
|
|
|
|
# Test commands:
|
2019-10-09 18:05:31 +00:00
|
|
|
run git secret add -i "$test_file"
|
2016-02-21 13:26:17 +00:00
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
2020-03-07 19:07:03 +00:00
|
|
|
[[ -f "$current_dir/.gitignore" ]]
|
|
|
|
run _file_has_line "$test_file" "$current_dir/.gitignore"
|
2017-03-05 21:46:49 +00:00
|
|
|
[ "$status" -eq 0 ]
|
2016-10-03 15:44:37 +00:00
|
|
|
|
2017-03-05 21:46:49 +00:00
|
|
|
# .gitignore was not created:
|
|
|
|
[[ ! -f ".gitignore" ]]
|
|
|
|
|
|
|
|
# Cleaning up:
|
|
|
|
cd "$current_dir"
|
|
|
|
rm -r "$test_dir"
|
2016-02-21 13:26:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-06 10:14:44 +00:00
|
|
|
@test "run 'add' for relative path" {
|
|
|
|
if [[ "$BATS_RUNNING_FROM_GIT" -eq 1 ]]; then
|
2019-02-10 21:44:21 +00:00
|
|
|
skip "this test is skipped while 'git commit'. See #334"
|
2017-03-06 10:14:44 +00:00
|
|
|
fi
|
|
|
|
|
2019-02-21 20:20:34 +00:00
|
|
|
# Preparations:
|
2017-03-06 10:14:44 +00:00
|
|
|
local root='test_dir'
|
|
|
|
local node="$root/node"
|
|
|
|
local sibling="$root/sibling"
|
2018-07-14 19:23:17 +00:00
|
|
|
local test_file="$node/$TEST_DEFAULT_FILENAME"
|
2017-03-06 10:14:44 +00:00
|
|
|
local current_dir=$(pwd)
|
|
|
|
|
|
|
|
mkdir -p "$node"
|
|
|
|
mkdir -p "$sibling"
|
|
|
|
|
|
|
|
echo "content" > "$test_file"
|
|
|
|
echo "$test_file" > ".gitignore"
|
|
|
|
|
|
|
|
cd "$sibling"
|
|
|
|
|
|
|
|
# Testing:
|
2019-10-09 18:05:31 +00:00
|
|
|
run git secret add "../node/$TEST_DEFAULT_FILENAME"
|
2017-03-06 10:14:44 +00:00
|
|
|
[ "$status" -eq 0 ]
|
2019-03-20 12:03:28 +00:00
|
|
|
[[ "$output" == *"git-secret: 1 item(s) added."* ]]
|
2017-03-06 10:14:44 +00:00
|
|
|
|
|
|
|
# Testing mappings content:
|
|
|
|
local path_mappings
|
|
|
|
path_mappings=$(_get_secrets_dir_paths_mapping)
|
|
|
|
|
|
|
|
local files_list=$(cat "$path_mappings")
|
|
|
|
[ "$files_list" = "$test_file" ]
|
|
|
|
|
|
|
|
# Cleaning up:
|
|
|
|
cd "$current_dir"
|
|
|
|
rm -r "$root"
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-03-05 21:46:49 +00:00
|
|
|
@test "run 'add' for file in subfolder" {
|
2019-02-10 21:44:21 +00:00
|
|
|
if [[ "$BATS_RUNNING_FROM_GIT" -eq 1 ]]; then
|
|
|
|
# See #334 for more about this
|
|
|
|
skip "this test is skipped while 'git commit'"
|
|
|
|
fi
|
|
|
|
|
2017-03-06 10:14:44 +00:00
|
|
|
# Preparations:
|
2018-07-14 19:23:17 +00:00
|
|
|
local test_file="$TEST_DEFAULT_FILENAME"
|
2017-03-06 10:14:44 +00:00
|
|
|
local test_dir='test_dir'
|
2016-10-01 20:07:36 +00:00
|
|
|
|
2017-03-06 10:14:44 +00:00
|
|
|
mkdir -p "$test_dir"
|
|
|
|
touch "$test_dir/$test_file"
|
|
|
|
echo "content" > "$test_dir/$test_file"
|
|
|
|
echo "$test_dir/$test_file" > ".gitignore"
|
2016-10-01 20:07:36 +00:00
|
|
|
|
2017-03-06 10:14:44 +00:00
|
|
|
# Testing:
|
2019-10-09 18:05:31 +00:00
|
|
|
run git secret add "$test_dir/$test_file"
|
2016-10-01 20:07:36 +00:00
|
|
|
[ "$status" -eq 0 ]
|
2019-03-20 12:03:28 +00:00
|
|
|
[[ "$output" == *"git-secret: 1 item(s) added."* ]]
|
2016-10-03 15:44:37 +00:00
|
|
|
|
2017-03-06 10:14:44 +00:00
|
|
|
# Cleaning up:
|
|
|
|
rm -r "$test_dir"
|
2016-10-01 20:07:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-02-21 13:26:17 +00:00
|
|
|
@test "run 'add' twice for one file" {
|
2017-03-06 10:14:44 +00:00
|
|
|
# Preparations:
|
2018-07-14 19:23:17 +00:00
|
|
|
local filename="$TEST_DEFAULT_FILENAME"
|
2016-02-21 13:26:17 +00:00
|
|
|
echo "content" > "$filename"
|
|
|
|
echo "$filename" > ".gitignore"
|
|
|
|
|
2017-03-06 10:14:44 +00:00
|
|
|
# Testing:
|
2019-10-09 18:05:31 +00:00
|
|
|
run git secret add "$filename"
|
|
|
|
run git secret add "$filename"
|
2016-02-21 13:26:17 +00:00
|
|
|
[ "$status" -eq 0 ]
|
2020-10-04 19:19:56 +00:00
|
|
|
[ "$output" = "git-secret: 0 item(s) added." ]
|
2017-03-05 21:46:49 +00:00
|
|
|
|
|
|
|
# Ensuring that path mappings was set correctly:
|
|
|
|
local path_mappings
|
|
|
|
path_mappings=$(_get_secrets_dir_paths_mapping)
|
2016-10-03 15:44:37 +00:00
|
|
|
|
2017-03-05 21:46:49 +00:00
|
|
|
local files_list=$(cat "$path_mappings")
|
2016-02-21 13:26:17 +00:00
|
|
|
[ "$files_list" = "$filename" ]
|
2017-03-06 10:14:44 +00:00
|
|
|
|
|
|
|
# Cleaning up:
|
|
|
|
rm "$filename" ".gitignore"
|
2016-02-21 13:26:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@test "run 'add' for multiple files" {
|
2017-03-06 10:14:44 +00:00
|
|
|
# Preparations:
|
2018-07-14 19:23:17 +00:00
|
|
|
local filename1="$TEST_DEFAULT_FILENAME"
|
2016-02-21 13:26:17 +00:00
|
|
|
echo "content1" > "$filename1"
|
|
|
|
echo "$filename1" > ".gitignore"
|
|
|
|
|
2018-07-14 19:23:17 +00:00
|
|
|
local filename2="$TEST_SECOND_FILENAME"
|
2016-02-21 13:26:17 +00:00
|
|
|
echo "content2" > "$filename2"
|
|
|
|
echo "$filename2" >> ".gitignore"
|
|
|
|
|
2017-03-06 10:14:44 +00:00
|
|
|
# Testing:
|
2019-10-09 18:05:31 +00:00
|
|
|
run git secret add "$filename1" "$filename2"
|
2020-10-04 19:19:56 +00:00
|
|
|
local newline=$'\n'
|
2016-02-21 13:26:17 +00:00
|
|
|
[ "$status" -eq 0 ]
|
2019-03-20 12:03:28 +00:00
|
|
|
[ "$output" = "git-secret: 2 item(s) added." ]
|
2016-10-03 15:44:37 +00:00
|
|
|
|
2017-03-06 10:14:44 +00:00
|
|
|
# Cleaning up:
|
2017-03-05 21:46:49 +00:00
|
|
|
rm "$filename1" "$filename2" ".gitignore"
|
2016-02-21 13:26:17 +00:00
|
|
|
}
|
2020-10-04 19:19:56 +00:00
|
|
|
|
|
|
|
@test "run 'add -v' for multiple files" {
|
|
|
|
# Preparations:
|
|
|
|
local filename1="$TEST_DEFAULT_FILENAME"
|
|
|
|
echo "content1" > "$filename1"
|
|
|
|
echo "$filename1" > ".gitignore"
|
|
|
|
|
|
|
|
local filename2="$TEST_SECOND_FILENAME"
|
|
|
|
echo "content2" > "$filename2"
|
|
|
|
echo "$filename2" >> ".gitignore"
|
|
|
|
|
|
|
|
# Testing:
|
|
|
|
run git secret add -v "$filename1" "$filename2"
|
|
|
|
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
[[ "$output" == *"git-secret: adding file: ${TEST_DEFAULT_FILENAME}"* ]]
|
|
|
|
[[ "$output" == *"git-secret: adding file: ${TEST_SECOND_FILENAME}"* ]]
|
|
|
|
[[ "$output" == *"git-secret: 2 item(s) added."* ]]
|
|
|
|
|
|
|
|
# Cleaning up:
|
|
|
|
rm "$filename1" "$filename2" ".gitignore"
|
|
|
|
}
|
2020-11-21 19:37:58 +00:00
|
|
|
|
|
|
|
@test "run 'add' for file with special chars" {
|
|
|
|
# Preparations:
|
|
|
|
local filename="$TEST_FOURTH_FILENAME"
|
|
|
|
echo "content" > "$filename"
|
|
|
|
echo "$filename" > ".gitignore"
|
|
|
|
|
|
|
|
run git secret add "$filename"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
|
|
|
# Ensuring that path mappings was set correctly:
|
|
|
|
local path_mappings
|
|
|
|
path_mappings=$(_get_secrets_dir_paths_mapping)
|
|
|
|
|
|
|
|
local files_list=$(cat "$path_mappings")
|
|
|
|
[ "$files_list" = "$filename" ]
|
|
|
|
|
|
|
|
# Ensuring the file is correctly git-ignored
|
|
|
|
run git check-ignore "$filename"
|
|
|
|
[ "$status" -eq 0 ]
|
|
|
|
|
|
|
|
# Cleaning up:
|
|
|
|
rm "$filename" ".gitignore"
|
|
|
|
}
|