diff --git a/entitlements/entitlements.go b/entitlements/entitlements.go index d9cc9ebe71f..9decccf4523 100644 --- a/entitlements/entitlements.go +++ b/entitlements/entitlements.go @@ -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() { diff --git a/entitlements/entitlements_test.go b/entitlements/entitlements_test.go index dca2788c182..f594d865626 100644 --- a/entitlements/entitlements_test.go +++ b/entitlements/entitlements_test.go @@ -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())) }) } }