summaryrefslogtreecommitdiff
path: root/tests/trezor/trezor_test.go
blob: ba468d94aaa3d86a8b46d9434bad26c29c608d97 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package trezor

// Test operations with "-trezor".
// See also the "cli" package - the tests there are very similar.

import (
	"os/exec"
	"runtime"
	"testing"

	"github.com/rfjakob/gocryptfs/internal/configfile"

	"github.com/rfjakob/gocryptfs/tests/test_helpers"
)

func isTrezorConnected() bool {
	if runtime.GOOS != "linux" {
		return false
	}
	c := exec.Command("lsusb", "-d", "534c:0001")
	err := c.Run()
	if err != nil {
		return false
	}
	return true
}

// Test -init with -trezor
func TestInitTrezor(t *testing.T) {
	if !isTrezorConnected() {
		t.Skip("No Trezor device connected")
	}
	t.Log("Trying gocryptfs -init -trezor ...")
	//                                        vvvvvvvvvvvvv disable -extpass
	dir := test_helpers.InitFS(t, "-trezor", "-extpass", "")
	// The freshly created config file should have the Trezor feature flag set.
	_, c, err := configfile.LoadConfFile(dir+"/"+configfile.ConfDefaultName, nil)
	if err != nil {
		t.Fatal(err)
	}
	if !c.IsFeatureFlagSet(configfile.FlagTrezor) {
		t.Error("Trezor flag should be set but is not")
	}
}