go.mondoo.com/cnquery@v0.0.0-20231005093811-59568235f6ea/providers/os/resources/sshd_test.go (about)

     1  // Copyright (c) Mondoo, Inc.
     2  // SPDX-License-Identifier: BUSL-1.1
     3  
     4  package resources_test
     5  
     6  import (
     7  	"testing"
     8  
     9  	"github.com/stretchr/testify/assert"
    10  	"go.mondoo.com/cnquery/providers-sdk/v1/testutils"
    11  )
    12  
    13  func TestResource_SSHD(t *testing.T) {
    14  	x.TestSimpleErrors(t, []testutils.SimpleTest{
    15  		{
    16  			Code:        "sshd.config('1').params['2'] == '3'",
    17  			ResultIndex: 0,
    18  			Expectation: "sshd config does not exist in 1",
    19  		},
    20  	})
    21  
    22  	t.Run("sshd file path", func(t *testing.T) {
    23  		res := x.TestQuery(t, "sshd.config.file.path")
    24  		assert.NotEmpty(t, res)
    25  		assert.NoError(t, res[0].Data.Error)
    26  	})
    27  
    28  	t.Run("sshd params", func(t *testing.T) {
    29  		res := x.TestQuery(t, "sshd.config.params")
    30  		assert.NotEmpty(t, res)
    31  		assert.NoError(t, res[0].Data.Error)
    32  	})
    33  
    34  	t.Run("sshd file error propagation", func(t *testing.T) {
    35  		res := x.TestQuery(t, "sshd.config('nope').params")
    36  		assert.Error(t, res[0].Data.Error)
    37  	})
    38  
    39  	t.Run("specific sshd param", func(t *testing.T) {
    40  		res := x.TestQuery(t, "sshd.config.params[\"UsePAM\"]")
    41  		assert.NotEmpty(t, res)
    42  		assert.Empty(t, res[0].Result().Error)
    43  		assert.Equal(t, "yes", res[0].Data.Value)
    44  	})
    45  
    46  	t.Run("parse ciphers", func(t *testing.T) {
    47  		res := x.TestQuery(t, "sshd.config.ciphers")
    48  		assert.NotEmpty(t, res)
    49  		assert.Empty(t, res[0].Result().Error)
    50  		assert.Equal(t, []interface{}{"chacha20-poly1305@openssh.com", "aes256-gcm@openssh.com", "aes128-gcm@openssh.com", "aes256-ctr", "aes192-ctr", "aes128-ctr"}, res[0].Data.Value)
    51  	})
    52  
    53  	t.Run("parse macs", func(t *testing.T) {
    54  		res := x.TestQuery(t, "sshd.config.macs")
    55  		assert.NotEmpty(t, res)
    56  		assert.Empty(t, res[0].Result().Error)
    57  		assert.Equal(t, []interface{}{"hmac-sha2-512-etm@openssh.com", "hmac-sha2-256-etm@openssh.com", "umac-128-etm@openssh.com", "hmac-sha2-512", "hmac-sha2-256"}, res[0].Data.Value)
    58  	})
    59  
    60  	t.Run("parse kexs", func(t *testing.T) {
    61  		res := x.TestQuery(t, "sshd.config.kexs")
    62  		assert.NotEmpty(t, res)
    63  		assert.Empty(t, res[0].Result().Error)
    64  		assert.Equal(t, []interface{}{"curve25519-sha256@libssh.org", "diffie-hellman-group-exchange-sha256"}, res[0].Data.Value)
    65  	})
    66  
    67  	t.Run("parse hostKeys", func(t *testing.T) {
    68  		res := x.TestQuery(t, "sshd.config.hostkeys")
    69  		assert.NotEmpty(t, res)
    70  		assert.Empty(t, res[0].Result().Error)
    71  		assert.Equal(t, []interface{}{"/etc/ssh/ssh_host_rsa_key", "/etc/ssh/ssh_host_ecdsa_key", "/etc/ssh/ssh_host_ed25519_key"}, res[0].Data.Value)
    72  	})
    73  }