mirror of
https://github.com/gravitational/teleport.git
synced 2026-10-11 22:49:54 +00:00
Prevent panic in BackfillFeatures (#62920)
Use the nil safe GetMonthlyRequestLimit getter to avoid panics.
This commit is contained in:
@@ -94,7 +94,7 @@ func BackfillFeatures(features *proto.Features) {
|
||||
// set default Identity fields to legacy feature value
|
||||
features.Entitlements[string(AccessLists)] = &proto.EntitlementInfo{Enabled: true, Limit: features.GetAccessList().GetCreateLimit()}
|
||||
features.Entitlements[string(AccessMonitoring)] = &proto.EntitlementInfo{Enabled: features.GetAccessMonitoring().GetEnabled(), Limit: features.GetAccessMonitoring().GetMaxReportRangeLimit()}
|
||||
features.Entitlements[string(AccessRequests)] = &proto.EntitlementInfo{Enabled: features.GetAccessRequests().MonthlyRequestLimit > 0, Limit: features.GetAccessRequests().GetMonthlyRequestLimit()}
|
||||
features.Entitlements[string(AccessRequests)] = &proto.EntitlementInfo{Enabled: features.GetAccessRequests().GetMonthlyRequestLimit() > 0, Limit: features.GetAccessRequests().GetMonthlyRequestLimit()}
|
||||
features.Entitlements[string(DeviceTrust)] = &proto.EntitlementInfo{Enabled: features.GetDeviceTrust().GetEnabled(), Limit: features.GetDeviceTrust().GetDevicesUsageLimit()}
|
||||
// override Identity Package features if Identity is enabled: set true and clear limit
|
||||
if features.GetIdentityGovernance() {
|
||||
|
||||
@@ -19,7 +19,9 @@ package entitlements
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/stretchr/testify/require"
|
||||
"google.golang.org/protobuf/testing/protocmp"
|
||||
|
||||
"github.com/gravitational/teleport/api/client/proto"
|
||||
apiutils "github.com/gravitational/teleport/api/utils"
|
||||
@@ -286,13 +288,28 @@ func TestBackfillFeatures(t *testing.T) {
|
||||
string(OktaUserSync): {Enabled: false},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "no entitlements",
|
||||
features: &proto.Features{},
|
||||
expected: func() map[string]*proto.EntitlementInfo {
|
||||
out := map[string]*proto.EntitlementInfo{
|
||||
string(AccessLists): {Enabled: true},
|
||||
}
|
||||
for _, e := range AllEntitlements {
|
||||
if _, ok := out[string(e)]; !ok {
|
||||
out[string(e)] = &proto.EntitlementInfo{}
|
||||
}
|
||||
}
|
||||
return out
|
||||
}(),
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
cloned := apiutils.CloneProtoMsg(tt.features)
|
||||
|
||||
BackfillFeatures(cloned)
|
||||
require.Equal(t, tt.expected, cloned.Entitlements)
|
||||
require.Empty(t, cmp.Diff(tt.expected, cloned.Entitlements, protocmp.Transform()))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user