diff --git a/server/datastore/mysql/apple_mdm.go b/server/datastore/mysql/apple_mdm.go index 1e6dfff4161a..7e3dc61158e7 100644 --- a/server/datastore/mysql/apple_mdm.go +++ b/server/datastore/mysql/apple_mdm.go @@ -4411,7 +4411,7 @@ INSERT INTO mdm_apple_declarations ( checksum, secrets_updated_at, uploaded_at) -(SELECT ?,?,?,?,?,UNHEX(MD5(raw_json)),?,CURRENT_TIMESTAMP() FROM DUAL WHERE +(SELECT ?,?,?,?,?,UNHEX(MD5(?)),?,CURRENT_TIMESTAMP() FROM DUAL WHERE NOT EXISTS ( SELECT 1 FROM mdm_windows_configuration_profiles WHERE name = ? AND team_id = ? ) AND NOT EXISTS ( @@ -4433,7 +4433,7 @@ INSERT INTO mdm_apple_declarations ( checksum, secrets_updated_at, uploaded_at) -(SELECT ?,?,?,?,?,UNHEX(MD5(raw_json)),?,CURRENT_TIMESTAMP() FROM DUAL WHERE +(SELECT ?,?,?,?,?,UNHEX(MD5(?)),?,CURRENT_TIMESTAMP() FROM DUAL WHERE NOT EXISTS ( SELECT 1 FROM mdm_windows_configuration_profiles WHERE name = ? AND team_id = ? ) AND NOT EXISTS ( @@ -4461,7 +4461,8 @@ func (ds *Datastore) insertOrUpsertMDMAppleDeclaration(ctx context.Context, insO err := ds.withTx(ctx, func(tx sqlx.ExtContext) error { res, err := tx.ExecContext(ctx, insOrUpsertStmt, - declUUID, tmID, declaration.Identifier, declaration.Name, declaration.RawJSON, declaration.SecretsUpdatedAt, + declUUID, tmID, declaration.Identifier, declaration.Name, declaration.RawJSON, declaration.RawJSON, + declaration.SecretsUpdatedAt, declaration.Name, tmID, declaration.Name, tmID) if err != nil { switch { diff --git a/server/datastore/mysql/microsoft_mdm.go b/server/datastore/mysql/microsoft_mdm.go index 360a975a3c76..60fe562552ba 100644 --- a/server/datastore/mysql/microsoft_mdm.go +++ b/server/datastore/mysql/microsoft_mdm.go @@ -1777,6 +1777,7 @@ WHERE team_id = ? ` + // For Windows profiles, if team_id and name are the same, we do an update. Otherwise, we do an insert. const insertNewOrEditedProfile = ` INSERT INTO mdm_windows_configuration_profiles ( diff --git a/server/service/mdm_test.go b/server/service/mdm_test.go index 65b9b8511eff..d7cf53fca5d3 100644 --- a/server/service/mdm_test.go +++ b/server/service/mdm_test.go @@ -2113,8 +2113,8 @@ func TestBatchSetMDMProfilesLabels(t *testing.T) { ds.ValidateEmbeddedSecretsFunc = func(ctx context.Context, documents []string) error { return nil } - ds.ExpandEmbeddedSecretsFunc = func(ctx context.Context, document string) (string, error) { - return document, nil + ds.ExpandEmbeddedSecretsAndUpdatedAtFunc = func(ctx context.Context, document string) (string, *time.Time, error) { + return document, nil, nil } profiles := []fleet.MDMProfileBatchPayload{