2023-02-15 18:01:44 +00:00
package service
import (
2024-10-16 16:12:48 +00:00
"context"
"encoding/json"
2023-11-15 21:04:24 +00:00
"os"
"path/filepath"
2023-02-15 18:01:44 +00:00
"testing"
"github.com/fleetdm/fleet/v4/pkg/spec"
2024-01-26 16:00:58 +00:00
"github.com/fleetdm/fleet/v4/server/fleet"
2024-10-16 16:12:48 +00:00
"github.com/stretchr/testify/assert"
2023-02-15 18:01:44 +00:00
"github.com/stretchr/testify/require"
)
func TestExtractAppConfigMacOSCustomSettings ( t * testing . T ) {
cases := [ ] struct {
desc string
yaml string
2024-01-26 16:00:58 +00:00
want [ ] fleet . MDMProfileSpec
2023-02-15 18:01:44 +00:00
} {
{
"no settings" ,
`
apiVersion : v1
kind : config
spec :
` ,
nil ,
} ,
{
"no custom settings" ,
`
apiVersion : v1
kind : config
spec :
org_info :
org_name : "Fleet"
2023-02-28 20:34:46 +00:00
mdm :
macos_settings :
2023-02-15 18:01:44 +00:00
` ,
nil ,
} ,
{
"empty custom settings" ,
`
apiVersion : v1
kind : config
spec :
org_info :
org_name : "Fleet"
2023-02-28 20:34:46 +00:00
mdm :
macos_settings :
custom_settings :
2023-02-15 18:01:44 +00:00
` ,
2024-01-26 16:00:58 +00:00
[ ] fleet . MDMProfileSpec { } ,
2023-02-15 18:01:44 +00:00
} ,
{
"custom settings specified" ,
`
apiVersion : v1
kind : config
2024-01-26 16:00:58 +00:00
spec :
org_info :
org_name : "Fleet"
mdm :
macos_settings :
custom_settings :
- path : "a"
labels :
- "foo"
- bar
- path : "b"
` ,
[ ] fleet . MDMProfileSpec { { Path : "a" , Labels : [ ] string { "foo" , "bar" } } , { Path : "b" } } ,
} ,
{
"empty and invalid custom settings" ,
`
apiVersion : v1
kind : config
spec :
org_info :
org_name : "Fleet"
mdm :
macos_settings :
custom_settings :
- path : "a"
labels :
- path : ""
labels :
- "foo"
- path : 4
labels :
- "foo"
- "bar"
- path : "c"
labels :
- baz
` ,
[ ] fleet . MDMProfileSpec { { Path : "a" } , { Path : "c" , Labels : [ ] string { "baz" } } } ,
} ,
{
"old custom settings specified" ,
`
apiVersion : v1
kind : config
2023-02-15 18:01:44 +00:00
spec :
org_info :
org_name : "Fleet"
2023-02-28 20:34:46 +00:00
mdm :
macos_settings :
custom_settings :
- "a"
- "b"
2023-02-15 18:01:44 +00:00
` ,
2024-01-26 16:00:58 +00:00
[ ] fleet . MDMProfileSpec { { Path : "a" } , { Path : "b" } } ,
2023-02-15 18:01:44 +00:00
} ,
{
2024-01-26 16:00:58 +00:00
"old empty and invalid custom settings" ,
2023-02-15 18:01:44 +00:00
`
apiVersion : v1
kind : config
spec :
org_info :
org_name : "Fleet"
2023-02-28 20:34:46 +00:00
mdm :
macos_settings :
custom_settings :
- "a"
- ""
- 4
- "c"
2023-02-15 18:01:44 +00:00
` ,
2024-01-26 16:00:58 +00:00
[ ] fleet . MDMProfileSpec { { Path : "a" } , { Path : "c" } } ,
2023-02-15 18:01:44 +00:00
} ,
}
for _ , c := range cases {
t . Run ( c . desc , func ( t * testing . T ) {
specs , err := spec . GroupFromBytes ( [ ] byte ( c . yaml ) )
require . NoError ( t , err )
if specs . AppConfig != nil {
got := extractAppCfgMacOSCustomSettings ( specs . AppConfig )
require . Equal ( t , c . want , got )
}
} )
}
}
2023-11-29 14:32:42 +00:00
func TestExtractAppConfigWindowsCustomSettings ( t * testing . T ) {
cases := [ ] struct {
desc string
yaml string
2024-01-26 16:00:58 +00:00
want [ ] fleet . MDMProfileSpec
2023-11-29 14:32:42 +00:00
} {
{
"no settings" ,
`
apiVersion : v1
kind : config
spec :
` ,
nil ,
} ,
{
"no custom settings" ,
`
apiVersion : v1
kind : config
spec :
org_info :
org_name : "Fleet"
mdm :
windows_settings :
` ,
nil ,
} ,
{
"empty custom settings" ,
`
apiVersion : v1
kind : config
spec :
org_info :
org_name : "Fleet"
mdm :
windows_settings :
custom_settings :
` ,
2024-01-26 16:00:58 +00:00
[ ] fleet . MDMProfileSpec { } ,
2023-11-29 14:32:42 +00:00
} ,
{
"custom settings specified" ,
`
apiVersion : v1
kind : config
2024-01-26 16:00:58 +00:00
spec :
org_info :
org_name : "Fleet"
mdm :
windows_settings :
custom_settings :
- path : "a"
labels :
- "foo"
- bar
- path : "b"
` ,
[ ] fleet . MDMProfileSpec { { Path : "a" , Labels : [ ] string { "foo" , "bar" } } , { Path : "b" } } ,
} ,
{
"empty and invalid custom settings" ,
`
apiVersion : v1
kind : config
spec :
org_info :
org_name : "Fleet"
mdm :
windows_settings :
custom_settings :
- path : "a"
labels :
- path : ""
labels :
- "foo"
- path : 4
labels :
- "foo"
- "bar"
- path : "c"
labels :
- baz
` ,
[ ] fleet . MDMProfileSpec { { Path : "a" } , { Path : "c" , Labels : [ ] string { "baz" } } } ,
} ,
{
"old custom settings specified" ,
`
apiVersion : v1
kind : config
2023-11-29 14:32:42 +00:00
spec :
org_info :
org_name : "Fleet"
mdm :
windows_settings :
custom_settings :
- "a"
- "b"
` ,
2024-01-26 16:00:58 +00:00
[ ] fleet . MDMProfileSpec { { Path : "a" } , { Path : "b" } } ,
2023-11-29 14:32:42 +00:00
} ,
{
2024-01-26 16:00:58 +00:00
"old empty and invalid custom settings" ,
2023-11-29 14:32:42 +00:00
`
apiVersion : v1
kind : config
spec :
org_info :
org_name : "Fleet"
mdm :
windows_settings :
custom_settings :
- "a"
- ""
- 4
- "c"
` ,
2024-01-26 16:00:58 +00:00
[ ] fleet . MDMProfileSpec { { Path : "a" } , { Path : "c" } } ,
2023-11-29 14:32:42 +00:00
} ,
}
for _ , c := range cases {
t . Run ( c . desc , func ( t * testing . T ) {
specs , err := spec . GroupFromBytes ( [ ] byte ( c . yaml ) )
require . NoError ( t , err )
if specs . AppConfig != nil {
got := extractAppCfgWindowsCustomSettings ( specs . AppConfig )
require . Equal ( t , c . want , got )
}
} )
}
}
2023-11-15 21:04:24 +00:00
func TestExtractTeamSpecsMDMCustomSettings ( t * testing . T ) {
2023-02-15 18:01:44 +00:00
cases := [ ] struct {
desc string
yaml string
2024-06-14 17:48:00 +00:00
want map [ string ] profileSpecsByPlatform
2023-02-15 18:01:44 +00:00
} {
{
"no settings" ,
`
apiVersion : v1
kind : team
spec :
team :
` ,
nil ,
} ,
{
"no custom settings" ,
`
apiVersion : v1
kind : team
spec :
team :
name : Fleet
2023-02-28 20:34:46 +00:00
mdm :
macos_settings :
2023-11-29 14:32:42 +00:00
windows_settings :
2023-02-15 18:01:44 +00:00
-- -
apiVersion : v1
kind : team
spec :
team :
name : Fleet2
2023-02-28 20:34:46 +00:00
mdm :
macos_settings :
2023-11-29 14:32:42 +00:00
windows_settings :
2023-02-15 18:01:44 +00:00
` ,
nil ,
} ,
{
"empty custom settings" ,
`
apiVersion : v1
kind : team
spec :
team :
name : "Fleet"
2023-02-28 20:34:46 +00:00
mdm :
macos_settings :
custom_settings :
2023-11-29 14:32:42 +00:00
windows_settings :
custom_settings :
2023-02-15 18:01:44 +00:00
-- -
apiVersion : v1
kind : team
spec :
team :
name : "Fleet2"
2023-02-28 20:34:46 +00:00
mdm :
macos_settings :
custom_settings :
2023-11-29 14:32:42 +00:00
windows_settings :
custom_settings :
2023-02-15 18:01:44 +00:00
` ,
2024-06-14 17:48:00 +00:00
map [ string ] profileSpecsByPlatform { "Fleet" : { windows : [ ] fleet . MDMProfileSpec { } , macos : [ ] fleet . MDMProfileSpec { } } , "Fleet2" : { windows : [ ] fleet . MDMProfileSpec { } , macos : [ ] fleet . MDMProfileSpec { } } } ,
2023-02-15 18:01:44 +00:00
} ,
{
"custom settings specified" ,
`
apiVersion : v1
kind : team
2024-01-26 16:00:58 +00:00
spec :
team :
name : "Fleet"
mdm :
macos_settings :
custom_settings :
- path : "a"
labels :
- "foo"
- bar
- path : "b"
windows_settings :
custom_settings :
- path : "c"
- path : "d"
labels :
- "foo"
- baz
` ,
2024-06-14 17:48:00 +00:00
map [ string ] profileSpecsByPlatform { "Fleet" : {
macos : [ ] fleet . MDMProfileSpec {
{ Path : "a" , Labels : [ ] string { "foo" , "bar" } } ,
{ Path : "b" } ,
} ,
windows : [ ] fleet . MDMProfileSpec {
{ Path : "c" } ,
{ Path : "d" , Labels : [ ] string { "foo" , "baz" } } ,
} ,
2024-01-26 16:00:58 +00:00
} } ,
} ,
{
"old custom settings specified" ,
`
apiVersion : v1
kind : team
2023-02-15 18:01:44 +00:00
spec :
team :
name : "Fleet"
2023-02-28 20:34:46 +00:00
mdm :
macos_settings :
custom_settings :
- "a"
- "b"
2023-11-29 14:32:42 +00:00
windows_settings :
custom_settings :
- "c"
- "d"
2023-02-15 18:01:44 +00:00
` ,
2024-06-14 17:48:00 +00:00
map [ string ] profileSpecsByPlatform { "Fleet" : {
macos : [ ] fleet . MDMProfileSpec { { Path : "a" } , { Path : "b" } } ,
windows : [ ] fleet . MDMProfileSpec {
{ Path : "c" } ,
{ Path : "d" } ,
} ,
} } ,
2023-02-15 18:01:44 +00:00
} ,
{
"invalid custom settings" ,
`
apiVersion : v1
kind : team
2024-01-26 16:00:58 +00:00
spec :
team :
name : "Fleet"
mdm :
macos_settings :
custom_settings :
- path : "a"
labels :
- "y"
- path : ""
- path : 42
labels :
- "x"
- path : "c"
windows_settings :
custom_settings :
- path : "x"
- path : ""
labels :
- "x"
- path : 24
- path : "y"
` ,
2024-06-14 17:48:00 +00:00
map [ string ] profileSpecsByPlatform { } ,
2024-01-26 16:00:58 +00:00
} ,
{
"old invalid custom settings" ,
`
apiVersion : v1
kind : team
2023-02-15 18:01:44 +00:00
spec :
team :
name : "Fleet"
2023-02-28 20:34:46 +00:00
mdm :
macos_settings :
custom_settings :
- "a"
- ""
- 42
- "c"
2023-11-29 14:32:42 +00:00
windows_settings :
custom_settings :
- "x"
- ""
- 24
- "y"
2023-02-15 18:01:44 +00:00
` ,
2024-06-14 17:48:00 +00:00
map [ string ] profileSpecsByPlatform { } ,
2023-02-15 18:01:44 +00:00
} ,
}
for _ , c := range cases {
t . Run ( c . desc , func ( t * testing . T ) {
specs , err := spec . GroupFromBytes ( [ ] byte ( c . yaml ) )
require . NoError ( t , err )
if len ( specs . Teams ) > 0 {
2024-06-14 17:48:00 +00:00
gotSpecs := extractTmSpecsMDMCustomSettings ( specs . Teams )
for k , wantProfs := range c . want {
gotProfs , ok := gotSpecs [ k ]
require . True ( t , ok )
require . Equal ( t , wantProfs . macos , gotProfs . macos )
require . Equal ( t , wantProfs . windows , gotProfs . windows )
}
2023-02-15 18:01:44 +00:00
}
} )
}
}
2023-05-11 13:36:28 +00:00
2023-11-15 21:04:24 +00:00
func TestGetProfilesContents ( t * testing . T ) {
tempDir := t . TempDir ( )
2024-01-26 16:00:58 +00:00
darwinProfile := mobileconfigForTest ( "bar" , "I" )
2024-05-28 16:44:43 +00:00
darwinProfileWithFooEnv := ` < ? xml version = "1.0" encoding = "UTF-8" ? >
< ! DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd" >
< plist version = "1.0" >
< dict >
< key > PayloadContent < / key >
< array / >
< key > PayloadDisplayName < / key >
< string > bar < / string >
< key > PayloadIdentifier < / key >
< string > 123 < / string >
< key > PayloadType < / key >
< string > Configuration < / string >
< key > PayloadUUID < / key >
< string > 123 < / string >
< key > PayloadVersion < / key >
< integer > 1 < / integer >
< key > someConfig < / key >
< integer > $ FOO < / integer >
< / dict >
< / plist > `
2024-01-26 16:00:58 +00:00
windowsProfile := syncMLForTest ( "./some/path" )
2024-05-28 16:44:43 +00:00
windowsProfileWithBarEnv := ` < Add >
< Item >
< Target >
< LocURI > . / some / path < / LocURI >
< / Target >
< / Item >
< / Add >
< Replace >
< Item >
< Target >
< LocURI > $ { BAR } / some / path < / LocURI >
< / Target >
< / Item >
< / Replace > `
2023-11-15 21:04:24 +00:00
tests := [ ] struct {
2024-06-14 17:48:00 +00:00
name string
baseDir string
macSetupFiles [ ] [ 2 ] string
winSetupFiles [ ] [ 2 ] string
labels [ ] string
environment map [ string ] string
expandEnv bool
expectError bool
want [ ] fleet . MDMProfileBatchPayload
wantErr string
2023-11-15 21:04:24 +00:00
} {
{
name : "invalid darwin xml" ,
baseDir : tempDir ,
2024-06-14 17:48:00 +00:00
macSetupFiles : [ ] [ 2 ] string {
2023-11-15 21:04:24 +00:00
{ "foo.mobileconfig" , ` <?xml version="1.0" encoding="UTF-8"?> ` } ,
} ,
2024-01-26 16:00:58 +00:00
expectError : true ,
want : [ ] fleet . MDMProfileBatchPayload { { Name : "foo" } } ,
2023-11-15 21:04:24 +00:00
} ,
{
name : "windows and darwin files" ,
baseDir : tempDir ,
2024-06-14 17:48:00 +00:00
macSetupFiles : [ ] [ 2 ] string {
2024-01-26 16:00:58 +00:00
{ "bar.mobileconfig" , string ( darwinProfile ) } ,
} ,
2024-06-14 17:48:00 +00:00
winSetupFiles : [ ] [ 2 ] string {
{ "foo.xml" , string ( windowsProfile ) } ,
} ,
2024-01-26 16:00:58 +00:00
expectError : false ,
want : [ ] fleet . MDMProfileBatchPayload {
{ Name : "foo" , Contents : windowsProfile } ,
{ Name : "bar" , Contents : darwinProfile } ,
} ,
} ,
{
name : "windows and darwin files with labels" ,
baseDir : tempDir ,
2024-06-14 17:48:00 +00:00
macSetupFiles : [ ] [ 2 ] string {
2024-01-26 16:00:58 +00:00
{ "bar.mobileconfig" , string ( darwinProfile ) } ,
} ,
2024-06-14 17:48:00 +00:00
winSetupFiles : [ ] [ 2 ] string {
{ "foo.xml" , string ( windowsProfile ) } ,
} ,
2024-01-26 16:00:58 +00:00
labels : [ ] string { "foo" , "bar" } ,
expectError : false ,
want : [ ] fleet . MDMProfileBatchPayload {
{ Name : "foo" , Contents : windowsProfile , Labels : [ ] string { "foo" , "bar" } } ,
{ Name : "bar" , Contents : darwinProfile , Labels : [ ] string { "foo" , "bar" } } ,
2023-11-15 21:04:24 +00:00
} ,
} ,
{
name : "darwin files with file name != PayloadDisplayName" ,
baseDir : tempDir ,
2024-06-14 17:48:00 +00:00
macSetupFiles : [ ] [ 2 ] string {
2024-01-26 16:00:58 +00:00
{ "bar.mobileconfig" , string ( darwinProfile ) } ,
} ,
2024-06-14 17:48:00 +00:00
winSetupFiles : [ ] [ 2 ] string {
{ "foo.xml" , string ( windowsProfile ) } ,
} ,
2024-01-26 16:00:58 +00:00
expectError : false ,
want : [ ] fleet . MDMProfileBatchPayload {
{ Name : "foo" , Contents : windowsProfile } ,
{ Name : "bar" , Contents : darwinProfile } ,
2023-11-15 21:04:24 +00:00
} ,
} ,
{
name : "duplicate names across windows and darwin" ,
baseDir : tempDir ,
2024-06-14 17:48:00 +00:00
macSetupFiles : [ ] [ 2 ] string {
2023-11-15 21:04:24 +00:00
{ "bar.mobileconfig" , string ( mobileconfigForTest ( "baz" , "I" ) ) } ,
} ,
2024-06-14 17:48:00 +00:00
winSetupFiles : [ ] [ 2 ] string {
{ "baz.xml" , string ( windowsProfile ) } ,
} ,
2023-11-15 21:04:24 +00:00
expectError : true ,
} ,
{
name : "duplicate file names" ,
baseDir : tempDir ,
2024-06-14 17:48:00 +00:00
winSetupFiles : [ ] [ 2 ] string {
2024-01-26 16:00:58 +00:00
{ "baz.xml" , string ( windowsProfile ) } ,
{ "baz.xml" , string ( windowsProfile ) } ,
2023-11-15 21:04:24 +00:00
} ,
expectError : true ,
} ,
2024-05-28 16:44:43 +00:00
{
name : "with environment variables" ,
baseDir : tempDir ,
2024-06-14 17:48:00 +00:00
macSetupFiles : [ ] [ 2 ] string {
2024-05-28 16:44:43 +00:00
{ "bar.mobileconfig" , darwinProfileWithFooEnv } ,
2024-06-14 17:48:00 +00:00
} ,
winSetupFiles : [ ] [ 2 ] string {
2024-05-28 16:44:43 +00:00
{ "foo.xml" , windowsProfileWithBarEnv } ,
} ,
environment : map [ string ] string { "FOO" : "42" , "BAR" : "24" } ,
expandEnv : true ,
expectError : false ,
want : [ ] fleet . MDMProfileBatchPayload {
{
Name : "bar" ,
Contents : [ ] byte ( ` < ? xml version = "1.0" encoding = "UTF-8" ? >
< ! DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd" >
< plist version = "1.0" >
< dict >
< key > PayloadContent < / key >
< array / >
< key > PayloadDisplayName < / key >
< string > bar < / string >
< key > PayloadIdentifier < / key >
< string > 123 < / string >
< key > PayloadType < / key >
< string > Configuration < / string >
< key > PayloadUUID < / key >
< string > 123 < / string >
< key > PayloadVersion < / key >
< integer > 1 < / integer >
< key > someConfig < / key >
< integer > 42 < / integer >
< / dict >
< / plist > ` ) ,
} ,
{
Name : "foo" ,
Contents : [ ] byte ( ` < Add >
< Item >
< Target >
< LocURI > . / some / path < / LocURI >
< / Target >
< / Item >
< / Add >
< Replace >
< Item >
< Target >
< LocURI > 24 / some / path < / LocURI >
< / Target >
< / Item >
< / Replace > ` ) ,
} ,
} ,
} ,
{
name : "with environment variables but not set" ,
baseDir : tempDir ,
2024-06-14 17:48:00 +00:00
macSetupFiles : [ ] [ 2 ] string {
2024-05-28 16:44:43 +00:00
{ "bar.mobileconfig" , darwinProfileWithFooEnv } ,
2024-06-14 17:48:00 +00:00
} ,
winSetupFiles : [ ] [ 2 ] string {
2024-05-28 16:44:43 +00:00
{ "foo.xml" , windowsProfileWithBarEnv } ,
} ,
environment : map [ string ] string { } ,
expandEnv : true ,
expectError : true ,
} ,
2024-06-14 17:48:00 +00:00
{
name : "with unprocessable json" ,
baseDir : tempDir ,
macSetupFiles : [ ] [ 2 ] string {
{ "bar.json" , string ( windowsProfile ) } ,
} ,
expectError : true ,
wantErr : "Couldn't edit macos_settings.custom_settings (bar.json): Declaration profiles should include valid JSON" ,
} ,
{
name : "with unprocessable xml" ,
baseDir : tempDir ,
winSetupFiles : [ ] [ 2 ] string {
{ "bar.xml" , string ( darwinProfile ) } ,
} ,
expectError : true ,
wantErr : "Couldn't edit windows_settings.custom_settings (bar.xml): Windows configuration profiles can only have <Replace> or <Add> top level elements" ,
} ,
{
name : "with unsupported extension" ,
baseDir : tempDir ,
macSetupFiles : [ ] [ 2 ] string {
{ "bar.cfg" , string ( darwinProfile ) } ,
} ,
expectError : true ,
wantErr : "Couldn't edit macos_settings.custom_settings (bar.cfg): macOS configuration profiles must be .mobileconfig or .json files" ,
} ,
2023-11-15 21:04:24 +00:00
}
for _ , tt := range tests {
t . Run ( tt . name , func ( t * testing . T ) {
2024-05-28 16:44:43 +00:00
if tt . expandEnv {
if len ( tt . environment ) > 0 {
for k , v := range tt . environment {
os . Setenv ( k , v )
}
t . Cleanup ( func ( ) {
for k := range tt . environment {
os . Unsetenv ( k )
}
} )
}
}
2024-06-14 17:48:00 +00:00
macPaths := [ ] fleet . MDMProfileSpec { }
for _ , fileSpec := range tt . macSetupFiles {
2023-11-15 21:04:24 +00:00
filePath := filepath . Join ( tempDir , fileSpec [ 0 ] )
2024-05-28 16:44:43 +00:00
require . NoError ( t , os . WriteFile ( filePath , [ ] byte ( fileSpec [ 1 ] ) , 0 o644 ) )
2024-06-14 17:48:00 +00:00
macPaths = append ( macPaths , fleet . MDMProfileSpec { Path : filePath , Labels : tt . labels } )
2023-11-15 21:04:24 +00:00
}
2024-06-14 17:48:00 +00:00
winPaths := [ ] fleet . MDMProfileSpec { }
for _ , fileSpec := range tt . winSetupFiles {
filePath := filepath . Join ( tempDir , fileSpec [ 0 ] )
require . NoError ( t , os . WriteFile ( filePath , [ ] byte ( fileSpec [ 1 ] ) , 0 o644 ) )
winPaths = append ( winPaths , fleet . MDMProfileSpec { Path : filePath , Labels : tt . labels } )
}
profileContents , err := getProfilesContents ( tt . baseDir , macPaths , winPaths , tt . expandEnv )
2023-11-15 21:04:24 +00:00
if tt . expectError {
require . Error ( t , err )
2024-06-14 17:48:00 +00:00
if tt . wantErr != "" {
require . Contains ( t , err . Error ( ) , tt . wantErr )
}
2023-11-15 21:04:24 +00:00
} else {
require . NoError ( t , err )
require . NotNil ( t , profileContents )
2024-01-26 16:00:58 +00:00
require . Len ( t , profileContents , len ( tt . want ) )
require . ElementsMatch ( t , tt . want , profileContents )
2023-11-15 21:04:24 +00:00
}
} )
}
}
2024-10-16 16:12:48 +00:00
func TestGitOpsErrors ( t * testing . T ) {
t . Parallel ( )
ctx := context . Background ( )
client , err := NewClient ( "https://foo.bar" , true , "" , "" )
require . NoError ( t , err )
tests := [ ] struct {
name string
rawJSON string
wantErr string
} {
{
name : "invalid integrations value" ,
rawJSON : ` { "integrations": false } ` ,
wantErr : "org_settings.integrations" ,
} ,
{
name : "invalid ndes_scep_proxy value" ,
rawJSON : ` { "integrations": { "ndes_scep_proxy": [] } } ` ,
wantErr : "org_settings.integrations.ndes_scep_proxy" ,
} ,
}
for _ , tt := range tests {
t . Run ( tt . name , func ( t * testing . T ) {
config := & spec . GitOps { }
config . OrgSettings = make ( map [ string ] interface { } )
err = json . Unmarshal ( [ ] byte ( tt . rawJSON ) , & config . OrgSettings )
require . NoError ( t , err )
config . OrgSettings [ "secrets" ] = [ ] * fleet . EnrollSecret { }
_ , err = client . DoGitOps ( ctx , config , "/filename" , nil , false , nil , nil , nil , nil )
assert . ErrorContains ( t , err , tt . wantErr )
} )
}
}