go.mondoo.com/cnquery@v0.0.0-20231005093811-59568235f6ea/providers/os/resources/authorizedkeys_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  )
    11  
    12  func TestResource_AuthorizedKeys(t *testing.T) {
    13  	t.Run("view authorized keys file", func(t *testing.T) {
    14  		res := x.TestQuery(t, "authorizedkeys('/home/chris/.ssh/authorized_keys').content")
    15  		assert.NotEmpty(t, res)
    16  		assert.Equal(t, 745, len(res[0].Data.Value.(string)))
    17  	})
    18  
    19  	t.Run("test authorized keys type", func(t *testing.T) {
    20  		res := x.TestQuery(t, "authorizedkeys('/home/chris/.ssh/authorized_keys').list[0].type")
    21  		assert.NotEmpty(t, res)
    22  		assert.Empty(t, res[0].Result().Error)
    23  		assert.Equal(t, "ssh-rsa", res[0].Data.Value)
    24  	})
    25  
    26  	t.Run("test authorized keys type", func(t *testing.T) {
    27  		res := x.TestQuery(t, "authorizedkeys('/home/chris/.ssh/authorized_keys').list[0].label")
    28  		assert.NotEmpty(t, res)
    29  		assert.Empty(t, res[0].Result().Error)
    30  		assert.Equal(t, "chris@lollyrock.com", res[0].Data.Value)
    31  	})
    32  
    33  	t.Run("test that the user exists", func(t *testing.T) {
    34  		res := x.TestQuery(t, "users.where( name == 'chris' ).list[0].authorizedkeys.list[0].type")
    35  		assert.NotEmpty(t, res)
    36  		assert.Empty(t, res[0].Result().Error)
    37  		assert.Equal(t, "ssh-rsa", res[0].Data.Value)
    38  	})
    39  }