github.com/david-imola/snapd@v0.0.0-20210611180407-2de8ddeece6d/sandbox/seccomp/seccomp_test.go (about)

     1  // -*- Mode: Go; indent-tabs-mode: t -*-
     2  
     3  /*
     4   * Copyright (C) 2018 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 seccomp_test
    21  
    22  import (
    23  	"io"
    24  
    25  	. "gopkg.in/check.v1"
    26  
    27  	"github.com/snapcore/snapd/sandbox/seccomp"
    28  )
    29  
    30  type seccompSuite struct{}
    31  
    32  var _ = Suite(&seccompSuite{})
    33  
    34  func (s *seccompSuite) TestInterfaceSystemKey(c *C) {
    35  	reset := seccomp.MockActions([]string{})
    36  	defer reset()
    37  	c.Check(seccomp.Actions(), DeepEquals, []string{})
    38  
    39  	reset = seccomp.MockActions([]string{"allow", "errno", "kill", "log", "trace", "trap"})
    40  	defer reset()
    41  	c.Check(seccomp.Actions(), DeepEquals, []string{"allow", "errno", "kill", "log", "trace", "trap"})
    42  }
    43  
    44  func (s *seccompSuite) TestSecCompSupportsAction(c *C) {
    45  	reset := seccomp.MockActions([]string{})
    46  	defer reset()
    47  	c.Check(seccomp.SupportsAction("log"), Equals, false)
    48  
    49  	reset = seccomp.MockActions([]string{"allow", "errno", "kill", "log", "trace", "trap"})
    50  	defer reset()
    51  	c.Check(seccomp.SupportsAction("log"), Equals, true)
    52  }
    53  
    54  func (s *seccompSuite) TestProbe(c *C) {
    55  	seccomp.FreshSecCompProbe()
    56  	r1 := seccomp.MockIoutilReadfile(func(string) ([]byte, error) {
    57  		return []byte("a b\n"), nil
    58  	})
    59  	defer r1()
    60  
    61  	c.Check(seccomp.Actions(), DeepEquals, []string{"a", "b"})
    62  
    63  	r2 := seccomp.MockIoutilReadfile(func(string) ([]byte, error) {
    64  		return nil, io.ErrUnexpectedEOF
    65  	})
    66  	defer r2()
    67  
    68  	c.Check(seccomp.Actions(), DeepEquals, []string{"a", "b"})
    69  }