go.mondoo.com/cnquery@v0.0.0-20231005093811-59568235f6ea/providers/os/resources/registrykey_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_Registrykey(t *testing.T) { 13 t.Run("non existent registry key", func(t *testing.T) { 14 res := testWindowsQuery(t, "registrykey('HKEY_LOCAL_MACHINE\\Software\\Policies\\Microsoft\\Windows\\Personalization').exists") 15 assert.NotEmpty(t, res) 16 assert.Empty(t, res[0].Result().Error) 17 assert.Equal(t, false, res[0].Data.Value) 18 }) 19 20 t.Run("registry key path", func(t *testing.T) { 21 res := testWindowsQuery(t, "registrykey('HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System').path") 22 assert.NotEmpty(t, res) 23 assert.Empty(t, res[0].Result().Error) 24 assert.Equal(t, "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System", res[0].Data.Value) 25 }) 26 27 t.Run("existing registry key", func(t *testing.T) { 28 res := testWindowsQuery(t, "registrykey('HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System').exists") 29 assert.NotEmpty(t, res) 30 assert.Empty(t, res[0].Result().Error) 31 assert.Equal(t, true, res[0].Data.Value) 32 }) 33 34 t.Run("registry key properties", func(t *testing.T) { 35 res := testWindowsQuery(t, "registrykey('HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System').properties") 36 assert.NotEmpty(t, res) 37 assert.Empty(t, res[0].Result().Error) 38 assert.Equal(t, 24, len(res[0].Data.Value.(map[string]interface{}))) 39 }) 40 41 t.Run("registry key children", func(t *testing.T) { 42 res := testWindowsQuery(t, "registrykey('HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System').children") 43 assert.NotEmpty(t, res) 44 assert.Empty(t, res[0].Result().Error) 45 assert.Equal(t, "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System\\Audit", res[0].Data.Value.([]interface{})[0]) 46 }) 47 }