From 249c88eb8eb9d503b0bcefcd191db0f847ae5433 Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Sat, 7 Nov 2020 20:30:51 -0800 Subject: [PATCH 1/3] cli-tests/common.sh: fix _user_do() Apparently, on some distros 'su' doesn't preserve $PATH. So, manually export it in the command. Also, ensure that the shell stays as bash. This is needed for some of the CLI tests to pass in Travis CI. --- cli-tests/common.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli-tests/common.sh b/cli-tests/common.sh index 79b42ae7..527eaa41 100644 --- a/cli-tests/common.sh +++ b/cli-tests/common.sh @@ -117,7 +117,7 @@ _user_do() { [ $# -ne 1 ] && _fail "wrong argument count to ${FUNCNAME[0]}" - su "$TEST_USER" --command="$1" + su "$TEST_USER" --shell=/bin/bash --command="export PATH='$PATH'; $1" } # Runs the given shell command as the test user and expects it to fail. From 3f5ee167b564ffacab4dc946eece67f214ae95ff Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Sat, 7 Nov 2020 20:30:51 -0800 Subject: [PATCH 2/3] cmd/fscrypt: fix race condition in getPassphraseKey() Set the terminal to raw mode *before* printing the prompt. Otherwise the user (or the automated test) might enter the passphrase before the terminal gets put into raw mode. This is needed for some of the CLI tests to pass reliably in Travis CI. --- cmd/fscrypt/keys.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cmd/fscrypt/keys.go b/cmd/fscrypt/keys.go index 77e3900a..33461ec6 100644 --- a/cmd/fscrypt/keys.go +++ b/cmd/fscrypt/keys.go @@ -86,9 +86,6 @@ func (p passphraseReader) Read(buf []byte) (int, error) { // passphrase into a key. If we are not reading from a terminal, just read into // the passphrase into the key normally. func getPassphraseKey(prompt string) (*crypto.Key, error) { - if !quietFlag.Value { - fmt.Print(prompt) - } // Only disable echo if stdin is actually a terminal. if terminal.IsTerminal(stdinFd) { @@ -102,6 +99,10 @@ func getPassphraseKey(prompt string) (*crypto.Key, error) { }() } + if !quietFlag.Value { + fmt.Print(prompt) + } + return crypto.NewKeyFromReader(passphraseReader{}) } From 334ca0a844f07828e4a7fae59850cb22ab2c0eaf Mon Sep 17 00:00:00 2001 From: Eric Biggers Date: Sat, 7 Nov 2020 20:30:51 -0800 Subject: [PATCH 3/3] travis.yml: upgrade to Ubuntu 20.04 and enable cli tests Now that Travis CI supports a version of Ubuntu that has a kernel that supports v2 encryption policies, upgrade to it and enable the cli tests. --- .travis.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 862e5258..62382395 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,6 @@ language: go sudo: false -dist: bionic +dist: focal arch: - amd64 - ppc64le @@ -66,6 +66,14 @@ jobs: - make coverage.out - goveralls -coverprofile=coverage.out -service=travis-ci + - name: Command-line interface tests + sudo: required + before_install: + - sudo apt-get -y install e2fsprogs expect keyutils + script: + - GO111MODULE=on go get github.com/google/fscrypt/cmd/fscrypt + - make cli-test + - stage: deploy name: Release Binaries install: skip