-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdevice_posture_test.go
150 lines (124 loc) · 3.96 KB
/
device_posture_test.go
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
143
144
145
146
147
148
149
150
// Copyright (c) David Bond, Tailscale Inc, & Contributors
// SPDX-License-Identifier: MIT
package tailscale
import (
"context"
"encoding/json"
"net/http"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestClient_DevicePosture_CreateIntegration(t *testing.T) {
t.Parallel()
client, server := NewTestHarness(t)
server.ResponseCode = http.StatusOK
req := CreatePostureIntegrationRequest{
Provider: PostureIntegrationProviderIntune,
CloudID: "cloudid",
ClientID: "clientid",
TenantID: "tenantid",
ClientSecret: "clientsecret",
}
resp := &PostureIntegration{
ID: "1",
Provider: PostureIntegrationProviderIntune,
CloudID: "cloudid",
ClientID: "clientid",
TenantID: "tenantid",
}
server.ResponseBody = resp
integration, err := client.DevicePosture().CreateIntegration(context.Background(), req)
require.NoError(t, err)
assert.Equal(t, http.MethodPost, server.Method)
assert.Equal(t, "/api/v2/tailnet/example.com/posture/integrations", server.Path)
assert.Equal(t, resp, integration)
var actualRequest CreatePostureIntegrationRequest
err = json.Unmarshal(server.Body.Bytes(), &actualRequest)
require.NoError(t, err)
assert.Equal(t, req, actualRequest)
}
func TestClient_DevicePosture_UpdateIntegration(t *testing.T) {
t.Parallel()
client, server := NewTestHarness(t)
server.ResponseCode = http.StatusOK
req := UpdatePostureIntegrationRequest{
CloudID: "cloudid",
ClientID: "clientid",
TenantID: "tenantid",
ClientSecret: PointerTo("clientsecret"),
}
resp := &PostureIntegration{
ID: "1",
Provider: PostureIntegrationProviderIntune,
CloudID: "cloudid",
ClientID: "clientid",
TenantID: "tenantid",
}
server.ResponseBody = resp
actualResp, err := client.DevicePosture().UpdateIntegration(context.Background(), "1", req)
assert.NoError(t, err)
assert.Equal(t, http.MethodPatch, server.Method)
assert.Equal(t, "/api/v2/posture/integrations/1", server.Path)
assert.Equal(t, resp, actualResp)
var actualRequest UpdatePostureIntegrationRequest
err = json.Unmarshal(server.Body.Bytes(), &actualRequest)
require.NoError(t, err)
assert.Equal(t, req, actualRequest)
}
func TestClient_DevicePosture_DeleteIntegration(t *testing.T) {
t.Parallel()
client, server := NewTestHarness(t)
server.ResponseCode = http.StatusOK
err := client.DevicePosture().DeleteIntegration(context.Background(), "1")
assert.NoError(t, err)
assert.Equal(t, http.MethodDelete, server.Method)
assert.Equal(t, "/api/v2/posture/integrations/1", server.Path)
}
func TestClient_DevicePosture_GetIntegration(t *testing.T) {
t.Parallel()
client, server := NewTestHarness(t)
server.ResponseCode = http.StatusOK
resp := &PostureIntegration{
ID: "1",
Provider: PostureIntegrationProviderIntune,
CloudID: "cloudid1",
ClientID: "clientid1",
TenantID: "tenantid1",
}
server.ResponseBody = resp
actualResp, err := client.DevicePosture().GetIntegration(context.Background(), "1")
assert.NoError(t, err)
assert.Equal(t, http.MethodGet, server.Method)
assert.Equal(t, "/api/v2/posture/integrations/1", server.Path)
assert.Equal(t, resp, actualResp)
}
func TestClient_DevicePosture_ListIntegrations(t *testing.T) {
t.Parallel()
client, server := NewTestHarness(t)
server.ResponseCode = http.StatusOK
resp := []PostureIntegration{
{
ID: "1",
Provider: PostureIntegrationProviderIntune,
CloudID: "cloudid1",
ClientID: "clientid1",
TenantID: "tenantid1",
},
{
ID: "2",
Provider: PostureIntegrationProviderJamfPro,
CloudID: "cloudid2",
ClientID: "clientid2",
TenantID: "tenantid2",
},
}
server.ResponseBody = map[string][]PostureIntegration{
"integrations": resp,
}
actualResp, err := client.DevicePosture().ListIntegrations(context.Background())
assert.NoError(t, err)
assert.Equal(t, http.MethodGet, server.Method)
assert.Equal(t, "/api/v2/tailnet/example.com/posture/integrations", server.Path)
assert.Equal(t, resp, actualResp)
}