github.com/bugraaydogar/snapd@v0.0.0-20210315170335-8c70bb858939/overlord/devicestate/fde/fde_test.go (about) 1 // -*- Mode: Go; indent-tabs-mode: t -*- 2 3 /* 4 * Copyright (C) 2020 Canonical Ltd 5 * 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License version 3 as 8 * published by the Free Software Foundation. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 * 18 */ 19 20 package fde_test 21 22 import ( 23 "io/ioutil" 24 "os" 25 "testing" 26 27 . "gopkg.in/check.v1" 28 29 "github.com/snapcore/snapd/overlord/devicestate/fde" 30 ) 31 32 func TestFde(t *testing.T) { TestingT(t) } 33 34 type fdeSuite struct{} 35 36 var _ = Suite(&fdeSuite{}) 37 38 func (s *fdeSuite) TestHasRevealKey(c *C) { 39 oldPath := os.Getenv("PATH") 40 defer func() { os.Setenv("PATH", oldPath) }() 41 42 mockRoot := c.MkDir() 43 os.Setenv("PATH", mockRoot+"/bin") 44 mockBin := mockRoot + "/bin/" 45 err := os.Mkdir(mockBin, 0755) 46 c.Assert(err, IsNil) 47 48 // no fde-reveal-key binary 49 c.Check(fde.HasRevealKey(), Equals, false) 50 51 // fde-reveal-key without +x 52 err = ioutil.WriteFile(mockBin+"fde-reveal-key", nil, 0644) 53 c.Assert(err, IsNil) 54 c.Check(fde.HasRevealKey(), Equals, false) 55 56 // correct fde-reveal-key, no logging 57 err = os.Chmod(mockBin+"fde-reveal-key", 0755) 58 c.Assert(err, IsNil) 59 }