fleet/server/platform/mysql/common_test.go
Robert Fairburn 73dba23392
Allow MySQL IAM authentication when a custom TLS CA/TLS config is set (#39808)
# 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

For unreleased bug fixes in a release candidate, one of:

- [x] Confirmed that the fix is not expected to adversely impact load
test results


Note: this solves https://github.com/fleetdm/fleet/issues/39832

---------

Co-authored-by: Scott Gress <scott@fleetdm.com>
Co-authored-by: Scott Gress <scottmgress@gmail.com>
2026-02-18 08:15:29 -06:00

71 lines
1.6 KiB
Go

package mysql
import (
"net/url"
"strings"
"testing"
"github.com/stretchr/testify/require"
)
func TestGenerateMysqlConnectionString_IAMDefaultsToRDSMysqlTLS(t *testing.T) {
t.Parallel()
dsn := generateMysqlConnectionString(MysqlConfig{
Protocol: "tcp",
Address: "db.example.com:3306",
Username: "fleet_iam",
Database: "fleet",
Region: "us-east-2",
})
params := dsnParams(t, dsn)
require.Equal(t, "true", params.Get("allowCleartextPasswords"))
require.Equal(t, "rdsmysql", params.Get("tls"))
}
func TestGenerateMysqlConnectionString_IAMWithCustomTLSConfig(t *testing.T) {
t.Parallel()
dsn := generateMysqlConnectionString(MysqlConfig{
Protocol: "tcp",
Address: "db.example.com:3306",
Username: "fleet_iam",
Database: "fleet",
Region: "us-east-2",
TLSConfig: "custom",
})
params := dsnParams(t, dsn)
require.Equal(t, "true", params.Get("allowCleartextPasswords"))
require.Equal(t, "custom", params.Get("tls"))
}
func TestGenerateMysqlConnectionString_NonIAMWithCustomTLSConfig(t *testing.T) {
t.Parallel()
dsn := generateMysqlConnectionString(MysqlConfig{
Protocol: "tcp",
Address: "db.example.com:3306",
Username: "fleet",
Password: "some-password",
Database: "fleet",
TLSConfig: "custom",
})
params := dsnParams(t, dsn)
require.Empty(t, params.Get("allowCleartextPasswords"))
require.Equal(t, "custom", params.Get("tls"))
}
func dsnParams(t *testing.T, dsn string) url.Values {
t.Helper()
parts := strings.SplitN(dsn, "?", 2)
require.Len(t, parts, 2, "dsn has no query string: %s", dsn)
params, err := url.ParseQuery(parts[1])
require.NoError(t, err)
return params
}