git-sig/test/test.bats

204 lines
4.5 KiB
Plaintext
Raw Normal View History

2020-11-18 23:23:15 +00:00
load test_helper
@test "Outputs help if run without arguments" {
run sig
2020-11-18 23:23:15 +00:00
[ "$status" -eq 0 ]
2020-11-19 00:52:09 +00:00
echo "${output}" | grep "simple multisig trust toolchain"
}
@test "Outputs help if run with help" {
run sig help
2020-11-19 00:52:09 +00:00
[ "$status" -eq 0 ]
echo "${output}" | grep "simple multisig trust toolchain"
}
@test "Outputs version if run with version" {
run sig version
2020-11-19 00:52:09 +00:00
[ "$status" -eq 0 ]
echo "${output}" | grep "v0.2"
2020-11-18 23:23:15 +00:00
}
@test "Outputs advice to install missing openssl" {
2020-11-19 21:40:38 +00:00
sudo rm /usr/bin/openssl
run sig version
echo "${output}" | grep "apt install openssl"
}
@test "Outputs advice to install missing gpg" {
2020-11-19 21:40:38 +00:00
sudo rm /usr/bin/gpg
run sig version
echo "${output}" | grep "apt install gnupg"
}
@test "Outputs advice to install missing getopt" {
2020-11-19 21:40:38 +00:00
sudo rm /usr/bin/getopt
run sig version
echo "${output}" | grep "apt install getopt"
}
2020-12-08 03:10:52 +00:00
@test "Verify fails if git is in use and tree is dirty" {
set_identity "user1"
echo "test string" > somefile
git init
git add .
git commit -m "initial commit"
echo "dirty" > somefile
run sig verify
2020-12-08 03:10:52 +00:00
[ "$status" -eq 1 ]
}
@test "Exit 1 if git method requested but not a repo" {
run sig verify
2020-12-08 03:10:52 +00:00
[ "$status" -eq 1 ]
}
@test "Verify succeeds when 1 unique git sig requirement is satisfied" {
set_identity "user1"
echo "test string" > somefile
git init
git add .
git commit -m "initial commit"
run sig verify
[ "$status" -eq 0 ]
}
@test "Verify succeeds when 3 unique git sig requirement is satisfied" {
git init
set_identity "user1"
echo "test string 1" > somefile1
git add .
git commit -m "user1 commit"
set_identity "user2"
git log
sig add
set_identity "user3"
sig add
run sig verify --threshold 3
[ "$status" -eq 0 ]
}
@test "Verify fails when 2 unique git sig requirement is not satisfied" {
2020-11-20 10:46:33 +00:00
git init
set_identity "user1"
echo "test string 1" > somefile1
git add .
git commit -m "user1 commit"
2020-12-08 03:10:52 +00:00
sig add
run sig verify --threshold 2
2020-11-20 10:46:33 +00:00
[ "$status" -eq 1 ]
}
@test "Verify succeeds when 1 group git sig requirement is satisifed" {
set_identity "user1"
echo "test string" > somefile
git init
git add .
git commit -m "initial commit"
sig fetch --group maintainers AE08157232C35F04309FA478C5EBC4A7CF55A2D0
run sig verify --group maintainers
[ "$status" -eq 0 ]
}
@test "Verify succeeds when 3 group git sig requirement is satisifed" {
set_identity "user1"
echo "test string" > somefile1
git init
git add .
git commit -m "User 1 Commit"
set_identity "user2"
sig add
set_identity "user3"
sig add
sig fetch --group maintainers AE08157232C35F04309FA478C5EBC4A7CF55A2D0
sig fetch --group maintainers BE4D60F6CFD2237A8AF978583C51CADD33BD0EE8
sig fetch --group maintainers 3E45AC9E190B4EE32BAE9F61A331AFB540761D69
run sig verify --threshold 3 --group maintainers
[ "$status" -eq 0 ]
}
@test "Verify fails when 2 group git sig requirement is not satisifed" {
set_identity "user1"
echo "test string" > somefile
git init
git add .
git commit -m "initial commit"
sig fetch --group maintainers AE08157232C35F04309FA478C5EBC4A7CF55A2D0
run sig verify --threshold 2 --group maintainers
[ "$status" -eq 1 ]
}
2023-01-19 17:48:49 +00:00
@test "Verify succeeds on past commit ref" {
git init
set_identity "user1"
echo "test string" > testfile
git add .
git commit -m "User 1 Commit"
set_identity "user2"
sig add
set_identity "user1"
echo "updated test string" > somefile1
git add .
git commit -m "User 1 Update Commit"
run sig verify --threshold 2 --ref HEAD~1
[ "$status" -eq 0 ]
}
@test "Verify diff shows changes between feature branch and verified master" {
git init
set_identity "user1"
echo "test string" > testfile
git add .
git commit -m "User 1 Commit"
set_identity "user2"
sig add
set_identity "user1"
git checkout -b feature_branch
echo "updated test string" > somefile1
git add .
git commit -m "User 1 Update Commit"
2023-01-19 17:48:49 +00:00
run sig verify --diff --ref master --threshold 2
[ "$status" -eq 0 ]
echo "${output}" | grep "updated test string"
}
2023-01-19 21:43:51 +00:00
@test "Verify diff can automatically discover most recent valid commit" {
git init
set_identity "user1"
echo "test string" > testfile
git add .
git commit -m "User 1 Commit 1"
set_identity "user2"
sig add
set_identity "user3"
sig add
set_identity "user1"
echo "test string 2" > testfile
git add .
git commit -m "User 1 Commit 2"
set_identity "user2"
sig add
set_identity "user1"
git checkout -b feature_branch
echo "updated test string" > somefile1
git add .
git commit -m "User 1 Commit 3"
run sig verify --diff --threshold 3
[ "$status" -eq 0 ]
echo "${output}" | grep "updated test string"
}