-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathdetector_win_test.go
More file actions
142 lines (115 loc) · 4.03 KB
/
detector_win_test.go
File metadata and controls
142 lines (115 loc) · 4.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// Copyright (c) Mondoo, Inc.
// SPDX-License-Identifier: BUSL-1.1
package detector
import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.mondoo.com/mql/v13/providers-sdk/v1/inventory"
"go.mondoo.com/mql/v13/providers/os/connection/mock"
)
func TestDetectIntuneDeviceID(t *testing.T) {
// Hash of the encoded Intune PowerShell command
const intuneCommandHash = "ee17502eeba7988928f8b668d05e2cb9e35bdc4cf9ebcde632470d87aa6a6905"
intuneEnrolledMock := &mock.TomlData{
Commands: map[string]*mock.Command{
intuneCommandHash: {
Stdout: `{"EnrollmentGUID":"12345678-1234-1234-1234-123456789012","EntDMID":"abcdef12-3456-7890-abcd-ef1234567890"}`,
},
},
}
intuneNotEnrolledMock := &mock.TomlData{
Commands: map[string]*mock.Command{
intuneCommandHash: {
Stdout: "",
},
},
}
t.Run("workstation should detect Intune device ID", func(t *testing.T) {
conn, err := mock.New(0, &inventory.Asset{}, mock.WithData(intuneEnrolledMock))
require.NoError(t, err)
pf := &inventory.Platform{
Title: "Windows 10 Enterprise",
Labels: map[string]string{
"windows.mondoo.com/product-type": "1",
},
}
detectIntuneDeviceID(pf, conn)
assert.Equal(t, "abcdef12-3456-7890-abcd-ef1234567890", pf.Labels["windows.mondoo.com/intune-device-id"])
})
t.Run("workstation not enrolled should not set label", func(t *testing.T) {
conn, err := mock.New(0, &inventory.Asset{}, mock.WithData(intuneNotEnrolledMock))
require.NoError(t, err)
pf := &inventory.Platform{
Title: "Windows 10 Enterprise",
Labels: map[string]string{
"windows.mondoo.com/product-type": "1",
},
}
detectIntuneDeviceID(pf, conn)
_, exists := pf.Labels["windows.mondoo.com/intune-device-id"]
assert.False(t, exists)
})
t.Run("Windows 11 multi-session should detect Intune device ID", func(t *testing.T) {
conn, err := mock.New(0, &inventory.Asset{}, mock.WithData(intuneEnrolledMock))
require.NoError(t, err)
pf := &inventory.Platform{
Title: "Windows 11 Enterprise Multi-Session",
Labels: map[string]string{
"windows.mondoo.com/product-type": "3",
},
}
detectIntuneDeviceID(pf, conn)
assert.Equal(t, "abcdef12-3456-7890-abcd-ef1234567890", pf.Labels["windows.mondoo.com/intune-device-id"])
})
t.Run("Windows Server should skip Intune detection", func(t *testing.T) {
conn, err := mock.New(0, &inventory.Asset{}, mock.WithData(intuneEnrolledMock))
require.NoError(t, err)
pf := &inventory.Platform{
Title: "Windows Server 2022 Datacenter",
Labels: map[string]string{
"windows.mondoo.com/product-type": "3",
},
}
detectIntuneDeviceID(pf, conn)
_, exists := pf.Labels["windows.mondoo.com/intune-device-id"]
assert.False(t, exists)
})
t.Run("Windows Server 2025 should skip Intune detection", func(t *testing.T) {
conn, err := mock.New(0, &inventory.Asset{}, mock.WithData(intuneEnrolledMock))
require.NoError(t, err)
pf := &inventory.Platform{
Title: "Windows Server 2025 Datacenter",
Labels: map[string]string{
"windows.mondoo.com/product-type": "3",
},
}
detectIntuneDeviceID(pf, conn)
_, exists := pf.Labels["windows.mondoo.com/intune-device-id"]
assert.False(t, exists)
})
t.Run("domain controller should skip Intune detection", func(t *testing.T) {
conn, err := mock.New(0, &inventory.Asset{}, mock.WithData(intuneEnrolledMock))
require.NoError(t, err)
pf := &inventory.Platform{
Title: "Windows Server 2022 Datacenter",
Labels: map[string]string{
"windows.mondoo.com/product-type": "2",
},
}
detectIntuneDeviceID(pf, conn)
_, exists := pf.Labels["windows.mondoo.com/intune-device-id"]
assert.False(t, exists)
})
t.Run("empty product-type should skip Intune detection", func(t *testing.T) {
conn, err := mock.New(0, &inventory.Asset{}, mock.WithData(intuneEnrolledMock))
require.NoError(t, err)
pf := &inventory.Platform{
Title: "Windows",
Labels: map[string]string{},
}
detectIntuneDeviceID(pf, conn)
_, exists := pf.Labels["windows.mondoo.com/intune-device-id"]
assert.False(t, exists)
})
}