Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/run-bats-core-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@ jobs:
bash /tmp/bats-core-repo/install.sh /tmp/bats-core

- name: Run tests
run: /tmp/bats-core/bin/bats tests/
run: /tmp/bats-core/bin/bats tests/v2/ tests/v3/
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -371,5 +371,5 @@ version of "Bash Automated Testing System" and stored in the _tests/_ directory.
To run the tests:

- [install bats-core](https://github.com/bats-core/bats-core#installation)
- run all tests with: `bats tests/`
- run an individual test with e.g: `bats tests/test_crypt.bats`
- run all tests with: `bats tests/v2 tests/v3`
- run an individual test with e.g: `bats tests/v3/test_crypt.bats`
4 changes: 2 additions & 2 deletions tests/_test_helper.bash
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ function cleanup_all {
}

function init_transcrypt {
"$BATS_TEST_DIRNAME"/../transcrypt --cipher=aes-256-cbc --password='abc 123' --yes
"$BATS_TEST_DIRNAME"/../../transcrypt --cipher=aes-256-cbc --password='abc 123' --yes
}

function uninstall_transcrypt {
"$BATS_TEST_DIRNAME"/../transcrypt --uninstall --yes
"$BATS_TEST_DIRNAME"/../../transcrypt --uninstall --yes
}

function encrypt_named_file {
Expand Down
6 changes: 3 additions & 3 deletions tests/test_cleanup.bats → tests/v2/test_cleanup.bats
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bats

load "$BATS_TEST_DIRNAME/_test_helper.bash"
load "$BATS_TEST_DIRNAME/../_test_helper.bash"

SECRET_CONTENT="My secret content"
SECRET_CONTENT_ENC="U2FsdGVkX1/6ilR0PmJpAyCF7iG3+k4aBwbgVd48WaQXznsg42nXbQrlWsf/qiCg"
Expand Down Expand Up @@ -31,7 +31,7 @@ SECRET_CONTENT_ENC="U2FsdGVkX1/6ilR0PmJpAyCF7iG3+k4aBwbgVd48WaQXznsg42nXbQrlWsf/
git repack

# Flush credentials
run ../transcrypt -f --yes
run ../../transcrypt -f --yes
[ "$status" -eq 0 ]

# Confirm working copy file is encrypted
Expand Down Expand Up @@ -79,7 +79,7 @@ SECRET_CONTENT_ENC="U2FsdGVkX1/6ilR0PmJpAyCF7iG3+k4aBwbgVd48WaQXznsg42nXbQrlWsf/
git repack

# Uninstall
run ../transcrypt --uninstall --yes
run ../../transcrypt --uninstall --yes
[ "$status" -eq 0 ]

# Confirm working copy file remains unencrypted (per uninstall contract)
Expand Down
92 changes: 46 additions & 46 deletions tests/test_contexts.bats → tests/v2/test_contexts.bats
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bats

load "$BATS_TEST_DIRNAME/_test_helper.bash"
load "$BATS_TEST_DIRNAME/../_test_helper.bash"

SECRET_CONTENT="My secret content"
SECRET_CONTENT_ENC="U2FsdGVkX1/6ilR0PmJpAyCF7iG3+k4aBwbgVd48WaQXznsg42nXbQrlWsf/qiCg"
Expand All @@ -12,7 +12,7 @@ function setup {
init_transcrypt

# Init transcrypt with 'super-secret' context
"$BATS_TEST_DIRNAME"/../transcrypt --context=super-secret --cipher=aes-256-cbc --password=321cba --yes
"$BATS_TEST_DIRNAME"/../../transcrypt --context=super-secret --cipher=aes-256-cbc --password=321cba --yes
}

function teardown {
Expand All @@ -23,42 +23,42 @@ function teardown {

@test "contexts: check validation of context names" {
# Invalid context names
run ../transcrypt --context=-ab --cipher=aes-256-cbc --password=none --yes
run ../../transcrypt --context=-ab --cipher=aes-256-cbc --password=none --yes
[ "$status" -ne 0 ]
run ../transcrypt --context=1ab --cipher=aes-256-cbc --password=none --yes
run ../../transcrypt --context=1ab --cipher=aes-256-cbc --password=none --yes
[ "$status" -ne 0 ]
run ../transcrypt --context=a--b --cipher=aes-256-cbc --password=none --yes
run ../../transcrypt --context=a--b --cipher=aes-256-cbc --password=none --yes
[ "$status" -ne 0 ]
run ../transcrypt --context=a- --cipher=aes-256-cbc --password=none --yes
run ../../transcrypt --context=a- --cipher=aes-256-cbc --password=none --yes
[ "$status" -ne 0 ]
run ../transcrypt --context=A --cipher=aes-256-cbc --password=none --yes
run ../../transcrypt --context=A --cipher=aes-256-cbc --password=none --yes
[ "$status" -ne 0 ]
run ../transcrypt --context=aB --cipher=aes-256-cbc --password=none --yes
run ../../transcrypt --context=aB --cipher=aes-256-cbc --password=none --yes
[ "$status" -ne 0 ]
run ../transcrypt --context=a-B --cipher=aes-256-cbc --password=none --yes
run ../../transcrypt --context=a-B --cipher=aes-256-cbc --password=none --yes
[ "$status" -ne 0 ]

# Valid context names
run ../transcrypt --context=ab --cipher=aes-256-cbc --password=none --yes
run ../../transcrypt --context=ab --cipher=aes-256-cbc --password=none --yes
[ "$status" -eq 0 ]
run ../transcrypt --context=a1 --cipher=aes-256-cbc --password=none --yes
run ../../transcrypt --context=a1 --cipher=aes-256-cbc --password=none --yes
[ "$status" -eq 0 ]
run ../transcrypt --context=a-b --cipher=aes-256-cbc --password=none --yes
run ../../transcrypt --context=a-b --cipher=aes-256-cbc --password=none --yes
[ "$status" -eq 0 ]
run ../transcrypt --context=a-1 --cipher=aes-256-cbc --password=none --yes
run ../../transcrypt --context=a-1 --cipher=aes-256-cbc --password=none --yes
[ "$status" -eq 0 ]
run ../transcrypt --context=a-b-c --cipher=aes-256-cbc --password=none --yes
run ../../transcrypt --context=a-b-c --cipher=aes-256-cbc --password=none --yes
[ "$status" -eq 0 ]
run ../transcrypt --context=a-1-c --cipher=aes-256-cbc --password=none --yes
run ../../transcrypt --context=a-1-c --cipher=aes-256-cbc --password=none --yes
[ "$status" -eq 0 ]
run ../transcrypt --context=a-b-c-d --cipher=aes-256-cbc --password=none --yes
run ../../transcrypt --context=a-b-c-d --cipher=aes-256-cbc --password=none --yes
[ "$status" -eq 0 ]
run ../transcrypt --context=a-1-c-d-2 --cipher=aes-256-cbc --password=none --yes
run ../../transcrypt --context=a-1-c-d-2 --cipher=aes-256-cbc --password=none --yes
[ "$status" -eq 0 ]
}

@test "contexts: check git config for 'super-secret' context" {
VERSION=$(../transcrypt -v | awk '{print $2}')
VERSION=$(../../transcrypt -v | awk '{print $2}')

[[ $(git config --get transcrypt.version) = "$VERSION" ]]
[[ $(git config --get transcrypt.super-secret.cipher) = "aes-256-cbc" ]]
Expand All @@ -80,9 +80,9 @@ function teardown {
}

@test "init: show extra context details in --display" {
VERSION=$(../transcrypt -v | awk '{print $2}')
VERSION=$(../../transcrypt -v | awk '{print $2}')

run ../transcrypt -C super-secret --display
run ../../transcrypt -C super-secret --display
[ "$status" -eq 0 ]
[ "${lines[0]}" = "The current repository was configured using transcrypt version $VERSION" ]
[ "${lines[1]}" = "and has the following configuration for context 'super-secret':" ]
Expand All @@ -96,12 +96,12 @@ function teardown {

@test "contexts: cannot re-init an existing context, fails with error message" {
# Cannot re-init 'default' context
run ../transcrypt --cipher=aes-256-cbc --password='abc 123' --yes
run ../../transcrypt --cipher=aes-256-cbc --password='abc 123' --yes
[ "$status" -ne 0 ]
[ "${lines[0]}" = "transcrypt: the current repository is already configured; see 'transcrypt --display'" ]

# Cannot re-init a named context
run ../transcrypt --context=super-secret --cipher=aes-256-cbc --password=321cba --yes
run ../../transcrypt --context=super-secret --cipher=aes-256-cbc --password=321cba --yes
[ "$status" -ne 0 ]
[ "${lines[0]}" = "transcrypt: the current repository is already configured for context 'super-secret'; see 'transcrypt --context=super-secret --display'" ]
}
Expand All @@ -118,7 +118,7 @@ function teardown {

@test "contexts: confirm --list-contexts lists configured contexts not yet in .gitattributes" {
# Confirm .gitattributes is not yet configured for multiple contexts
run ../transcrypt --list-contexts
run ../../transcrypt --list-contexts
[ "$status" -eq 0 ]
[ "${lines[0]}" = 'default (no patterns in .gitattributes)' ]
[ "${lines[1]}" = 'super-secret (no patterns in .gitattributes)' ]
Expand All @@ -129,7 +129,7 @@ function teardown {
encrypt_named_file super_sensitive_file "$SECRET_CONTENT" "super-secret"

# Confirm .gitattributes is configured for multiple contexts
run ../transcrypt --list-contexts
run ../../transcrypt --list-contexts
[ "$status" -eq 0 ]
[ "${lines[0]}" = 'default' ]
[ "${lines[1]}" = 'super-secret' ]
Expand All @@ -140,24 +140,24 @@ function teardown {
encrypt_named_file super_sensitive_file "$SECRET_CONTENT" "super-secret"

# Remove all transcrypt config, including contexts
../transcrypt --uninstall --yes
../../transcrypt --uninstall --yes

# Don't list contexts when none are known
echo > .gitattributes
run ../transcrypt --list-contexts
run ../../transcrypt --list-contexts
[ "$status" -eq 0 ]
[ "${lines[0]}" = '' ]

# List just super-secret context from .gitattributes
echo '"super_sensitive_file" filter=crypt-super-secret diff=crypt-super-secret merge=crypt-super-secret' > .gitattributes
run ../transcrypt --list-contexts
run ../../transcrypt --list-contexts
[ "$status" -eq 0 ]
[ "${lines[0]}" = 'super-secret (not initialised)' ]
[ "${lines[1]}" = '' ]

# List just default context from .gitattributes
echo '"sensitive_file" filter=crypt diff=crypt merge=crypt' > .gitattributes
run ../transcrypt --list-contexts
run ../../transcrypt --list-contexts
[ "$status" -eq 0 ]
[ "${lines[0]}" = 'default (not initialised)' ]
[ "${lines[1]}" = '' ]
Expand Down Expand Up @@ -205,12 +205,12 @@ function teardown {
encrypt_named_file sensitive_file "$SECRET_CONTENT"
encrypt_named_file super_sensitive_file "$SECRET_CONTENT" "super-secret"

run ../transcrypt --show-raw sensitive_file
run ../../transcrypt --show-raw sensitive_file
[ "$status" -eq 0 ]
[ "${lines[0]}" = "==> sensitive_file <==" ]
[ "${lines[1]}" = "$SECRET_CONTENT_ENC" ]

run ../transcrypt --show-raw super_sensitive_file
run ../../transcrypt --show-raw super_sensitive_file
[ "$status" -eq 0 ]
[ "${lines[0]}" = "==> super_sensitive_file <==" ]
[ "${lines[1]}" = "$SUPER_SECRET_CONTENT_ENC" ]
Expand Down Expand Up @@ -250,7 +250,7 @@ function teardown {
encrypt_named_file sensitive_file "$SECRET_CONTENT"
encrypt_named_file super_sensitive_file "$SECRET_CONTENT" "super-secret"

run ../transcrypt --list
run ../../transcrypt --list
[ "$status" -eq 0 ]
[ "${lines[0]}" = "sensitive_file" ]
[ "${lines[1]}" = "super_sensitive_file" ]
Expand All @@ -261,7 +261,7 @@ function teardown {
encrypt_named_file sensitive_file "$SECRET_CONTENT"
encrypt_named_file super_sensitive_file "$SECRET_CONTENT" "super-secret"

run ../transcrypt --uninstall --yes
run ../../transcrypt --uninstall --yes
[ "$status" -eq 0 ]

run cat sensitive_file
Expand All @@ -283,7 +283,7 @@ function teardown {
encrypt_named_file sensitive_file "$SECRET_CONTENT"
encrypt_named_file super_sensitive_file "$SECRET_CONTENT" "super-secret"

../transcrypt --uninstall --yes
../../transcrypt --uninstall --yes

git reset --hard
check_repo_is_clean
Expand All @@ -303,7 +303,7 @@ function teardown {
# Init transcrypt with encrypted files then reset to be like a new clone
encrypt_named_file sensitive_file "$SECRET_CONTENT"
encrypt_named_file super_sensitive_file "$SECRET_CONTENT" "super-secret"
../transcrypt --uninstall --yes
../../transcrypt --uninstall --yes
git reset --hard
check_repo_is_clean

Expand All @@ -314,14 +314,14 @@ function teardown {
[ "${lines[0]}" = "$SUPER_SECRET_CONTENT_ENC" ]

# Confirm .gitattributes is configured for contexts, but Git is not
run ../transcrypt --list-contexts
run ../../transcrypt --list-contexts
[ "$status" -eq 0 ]
[ "${lines[0]}" = 'default (not initialised)' ]
[ "${lines[1]}" = 'super-secret (not initialised)' ]

# Re-init only super-secret context: its files are decrypted, not default context
../transcrypt --context=super-secret --cipher=aes-256-cbc --password=321cba --yes
run ../transcrypt --list-contexts
../../transcrypt --context=super-secret --cipher=aes-256-cbc --password=321cba --yes
run ../../transcrypt --list-contexts
[ "${lines[0]}" = 'default (not initialised)' ]
[ "${lines[1]}" = 'super-secret' ]
run cat super_sensitive_file
Expand All @@ -330,13 +330,13 @@ function teardown {
[ "${lines[0]}" = "$SECRET_CONTENT_ENC" ]

# Reset again
../transcrypt --uninstall --yes
../../transcrypt --uninstall --yes
git reset --hard
check_repo_is_clean

# Re-init only default context: its files are decrypted, not super-secret context
../transcrypt --cipher=aes-256-cbc --password='abc 123' --yes
run ../transcrypt --list-contexts
../../transcrypt --cipher=aes-256-cbc --password='abc 123' --yes
run ../../transcrypt --list-contexts
[ "${lines[0]}" = 'default' ]
[ "${lines[1]}" = 'super-secret (not initialised)' ]
run cat sensitive_file
Expand All @@ -345,13 +345,13 @@ function teardown {
[ "${lines[0]}" = "$SUPER_SECRET_CONTENT_ENC" ]

# Reset again
../transcrypt --uninstall --yes
../../transcrypt --uninstall --yes
git reset --hard
check_repo_is_clean

# Re-init super-secret then default contexts, to confirm safety check permits this
../transcrypt --context=super-secret --cipher=aes-256-cbc --password=321cba --yes
../transcrypt --cipher=aes-256-cbc --password='abc 123' --yes
../../transcrypt --context=super-secret --cipher=aes-256-cbc --password=321cba --yes
../../transcrypt --cipher=aes-256-cbc --password='abc 123' --yes
}

@test "contexts: --upgrade retains all context configs" {
Expand All @@ -361,15 +361,15 @@ function teardown {

# We use context names without warning notes as a surrogate for checking
# that the super-secret context is configured and in .gitattributes
run ../transcrypt --list-contexts
run ../../transcrypt --list-contexts
[ "$status" -eq 0 ]
[ "${lines[0]}" = 'default' ]
[ "${lines[1]}" = 'super-secret' ]

# Upgrade removes and *should* re-create config for all contexts
run ../transcrypt --upgrade --yes
run ../../transcrypt --upgrade --yes

run ../transcrypt --list-contexts
run ../../transcrypt --list-contexts
[ "$status" -eq 0 ]
[ "${lines[0]}" = 'default' ]
[ "${lines[1]}" = 'super-secret' ]
Expand Down
Loading
Loading