mirror of
https://github.com/fleetdm/fleet
synced 2026-04-21 21:47:20 +00:00
Fixes #31444 The changes are primarily in tests. The only changes in production code are a couple validations/checks for invalid values in: - mysql/apple_mdm.go - mysql/hosts.go - mysql/queries.go # Checklist for submitter If some of the following don't apply, delete the relevant line. - [x] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. See [Changes files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files) for more information. ## Testing - [x] Added/updated automated tests - [x] QA'd all new/changed functionality manually <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Improved handling of timestamp and default values across various features to prevent database errors and warnings. * Enhanced validation and data consistency for Apple Business Manager tokens and MDM profiles. * Updated test data and logic to comply with stricter database constraints and realistic scenarios, including date handling and field lengths. * **Chores** * Updated test setups to reflect schema changes, improve data integrity, and avoid future compatibility issues. * Standardized SQL mode and timestamp usage in test environments. * Refined test data for VPP apps, software installers, and device enrollments for better reliability. * **Tests** * Expanded and updated tests to cover new fields, stricter validation, and more accurate simulation of real-world conditions. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
65 lines
1.2 KiB
Go
65 lines
1.2 KiB
Go
package mysql
|
|
|
|
import (
|
|
"crypto/x509"
|
|
"crypto/x509/pkix"
|
|
"math/big"
|
|
"testing"
|
|
"time"
|
|
|
|
scep_depot "github.com/fleetdm/fleet/v4/server/mdm/scep/depot"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func setup(t *testing.T) scep_depot.Depot {
|
|
ds := CreateNamedMySQLDS(t, t.Name())
|
|
depot, err := ds.NewSCEPDepot()
|
|
require.NoError(t, err)
|
|
return depot
|
|
}
|
|
|
|
func TestAppleMDMSCEPSerial(t *testing.T) {
|
|
depot := setup(t)
|
|
tests := []struct {
|
|
name string
|
|
want *big.Int
|
|
wantErr bool
|
|
}{
|
|
{
|
|
name: "two is the default value.",
|
|
want: big.NewInt(2),
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
got, err := depot.Serial()
|
|
require.NoError(t, err)
|
|
require.Equal(t, tt.want, got)
|
|
}
|
|
}
|
|
|
|
func TestAppleMDMPutAndHasCN(t *testing.T) {
|
|
depot := setup(t)
|
|
|
|
name := "Fleet Identity"
|
|
serial, err := depot.Serial()
|
|
require.NoError(t, err)
|
|
cert := x509.Certificate{
|
|
SerialNumber: serial,
|
|
Subject: pkix.Name{
|
|
CommonName: name,
|
|
},
|
|
NotBefore: time.Now(),
|
|
NotAfter: time.Now().Add(365 * 24 * time.Hour),
|
|
}
|
|
|
|
err = depot.Put(name, &cert)
|
|
require.NoError(t, err)
|
|
|
|
has, err := depot.HasCN(name, 0, &cert, false)
|
|
require.NoError(t, err)
|
|
require.True(t, has)
|
|
|
|
has, err = depot.HasCN("non-existent", 0, &cert, true)
|
|
require.NoError(t, err)
|
|
require.False(t, has)
|
|
}
|