diff --git a/internal/license/service.go b/internal/license/service.go index f66b8d99b3..0050c3b2dc 100644 --- a/internal/license/service.go +++ b/internal/license/service.go @@ -106,10 +106,11 @@ func InjectTestService(res *service.Resources) { // InjectCustomLicenseBytes attempts to parse a Redpanda Enterprise license // from a slice of bytes and, if successful, stores it within the provided // resources pointer for enterprise components to reference. -func InjectCustomLicenseBytes(res *service.Resources, licenseBytes []byte) error { +func InjectCustomLicenseBytes(res *service.Resources, conf Config, licenseBytes []byte) error { s := &Service{ logger: res.Logger(), loadedLicense: &atomic.Pointer[RedpandaLicense]{}, + conf: conf, } license, err := s.validateLicense(licenseBytes) @@ -128,6 +129,7 @@ func InjectCustomLicenseBytes(res *service.Resources, licenseBytes []byte) error ).Debug("Successfully loaded Redpanda license") s.loadedLicense.Store(&license) + setSharedService(res, s) return nil } diff --git a/internal/license/service_test.go b/internal/license/service_test.go index c1e73688d2..eac776683a 100644 --- a/internal/license/service_test.go +++ b/internal/license/service_test.go @@ -249,3 +249,21 @@ func TestLicenseEnterpriseNoLicense(t *testing.T) { assert.False(t, loaded.AllowsEnterpriseFeatures()) } + +func TestInjectedLicense(t *testing.T) { + key, lic := createLicense(t, RedpandaLicense{ + Version: 1, + Type: 1, + Expiry: time.Now().Add(time.Hour).Unix(), + }) + + res := service.MockResources() + require.NoError(t, InjectCustomLicenseBytes(res, Config{ + customPublicKeyPem: key, + }, []byte(lic))) + + loaded, err := LoadFromResources(res) + require.NoError(t, err) + + assert.True(t, loaded.AllowsEnterpriseFeatures()) +} diff --git a/public/license/license.go b/public/license/license.go index c44b1c36d3..656a8b72e4 100644 --- a/public/license/license.go +++ b/public/license/license.go @@ -38,5 +38,5 @@ func LocateLicense(res *service.Resources, opts ...LocateLicenseOptFunc) { // from a slice of bytes and, if successful, stores it within the provided // resources pointer for enterprise components to reference. func StoreCustomLicenseBytes(res *service.Resources, licenseBytes []byte) error { - return license.InjectCustomLicenseBytes(res, licenseBytes) + return license.InjectCustomLicenseBytes(res, license.Config{}, licenseBytes) }