@@ -31,7 +31,7 @@ func TestEntitlements(t *testing.T) {
31
31
t .Run ("Defaults" , func (t * testing.T ) {
32
32
t .Parallel ()
33
33
db := databasefake .New ()
34
- entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, coderdenttest .Keys , all )
34
+ entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, 1 , coderdenttest .Keys , all )
35
35
require .NoError (t , err )
36
36
require .False (t , entitlements .HasLicense )
37
37
require .False (t , entitlements .Trial )
@@ -47,7 +47,7 @@ func TestEntitlements(t *testing.T) {
47
47
JWT : coderdenttest .GenerateLicense (t , coderdenttest.LicenseOptions {}),
48
48
Exp : time .Now ().Add (time .Hour ),
49
49
})
50
- entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, coderdenttest .Keys , map [string ]bool {})
50
+ entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, 1 , coderdenttest .Keys , map [string ]bool {})
51
51
require .NoError (t , err )
52
52
require .True (t , entitlements .HasLicense )
53
53
require .False (t , entitlements .Trial )
@@ -71,7 +71,7 @@ func TestEntitlements(t *testing.T) {
71
71
}),
72
72
Exp : time .Now ().Add (time .Hour ),
73
73
})
74
- entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, coderdenttest .Keys , map [string ]bool {})
74
+ entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, 1 , coderdenttest .Keys , map [string ]bool {})
75
75
require .NoError (t , err )
76
76
require .True (t , entitlements .HasLicense )
77
77
require .False (t , entitlements .Trial )
@@ -96,14 +96,17 @@ func TestEntitlements(t *testing.T) {
96
96
}),
97
97
Exp : time .Now ().Add (time .Hour ),
98
98
})
99
- entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, coderdenttest .Keys , all )
99
+ entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, 1 , coderdenttest .Keys , all )
100
100
require .NoError (t , err )
101
101
require .True (t , entitlements .HasLicense )
102
102
require .False (t , entitlements .Trial )
103
103
for _ , featureName := range codersdk .FeatureNames {
104
104
if featureName == codersdk .FeatureUserLimit {
105
105
continue
106
106
}
107
+ if featureName == codersdk .FeatureHighAvailability {
108
+ continue
109
+ }
107
110
niceName := strings .Title (strings .ReplaceAll (featureName , "_" , " " ))
108
111
require .Equal (t , codersdk .EntitlementGracePeriod , entitlements .Features [featureName ].Entitlement )
109
112
require .Contains (t , entitlements .Warnings , fmt .Sprintf ("%s is enabled but your license for this feature is expired." , niceName ))
@@ -116,14 +119,17 @@ func TestEntitlements(t *testing.T) {
116
119
JWT : coderdenttest .GenerateLicense (t , coderdenttest.LicenseOptions {}),
117
120
Exp : time .Now ().Add (time .Hour ),
118
121
})
119
- entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, coderdenttest .Keys , all )
122
+ entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, 1 , coderdenttest .Keys , all )
120
123
require .NoError (t , err )
121
124
require .True (t , entitlements .HasLicense )
122
125
require .False (t , entitlements .Trial )
123
126
for _ , featureName := range codersdk .FeatureNames {
124
127
if featureName == codersdk .FeatureUserLimit {
125
128
continue
126
129
}
130
+ if featureName == codersdk .FeatureHighAvailability {
131
+ continue
132
+ }
127
133
niceName := strings .Title (strings .ReplaceAll (featureName , "_" , " " ))
128
134
// Ensures features that are not entitled are properly disabled.
129
135
require .False (t , entitlements .Features [featureName ].Enabled )
@@ -142,7 +148,7 @@ func TestEntitlements(t *testing.T) {
142
148
}),
143
149
Exp : time .Now ().Add (time .Hour ),
144
150
})
145
- entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, coderdenttest .Keys , map [string ]bool {})
151
+ entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, 1 , coderdenttest .Keys , map [string ]bool {})
146
152
require .NoError (t , err )
147
153
require .True (t , entitlements .HasLicense )
148
154
require .Contains (t , entitlements .Warnings , "Your deployment has 2 active users but is only licensed for 1." )
@@ -164,7 +170,7 @@ func TestEntitlements(t *testing.T) {
164
170
}),
165
171
Exp : time .Now ().Add (time .Hour ),
166
172
})
167
- entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, coderdenttest .Keys , map [string ]bool {})
173
+ entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, 1 , coderdenttest .Keys , map [string ]bool {})
168
174
require .NoError (t , err )
169
175
require .True (t , entitlements .HasLicense )
170
176
require .Empty (t , entitlements .Warnings )
@@ -187,7 +193,7 @@ func TestEntitlements(t *testing.T) {
187
193
}),
188
194
})
189
195
190
- entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, coderdenttest .Keys , map [string ]bool {})
196
+ entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, 1 , coderdenttest .Keys , map [string ]bool {})
191
197
require .NoError (t , err )
192
198
require .True (t , entitlements .HasLicense )
193
199
require .False (t , entitlements .Trial )
@@ -202,7 +208,7 @@ func TestEntitlements(t *testing.T) {
202
208
AllFeatures : true ,
203
209
}),
204
210
})
205
- entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, coderdenttest .Keys , all )
211
+ entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, 1 , coderdenttest .Keys , all )
206
212
require .NoError (t , err )
207
213
require .True (t , entitlements .HasLicense )
208
214
require .False (t , entitlements .Trial )
@@ -214,4 +220,52 @@ func TestEntitlements(t *testing.T) {
214
220
require .Equal (t , codersdk .EntitlementEntitled , entitlements .Features [featureName ].Entitlement )
215
221
}
216
222
})
223
+
224
+ t .Run ("MultipleReplicasNoLicense" , func (t * testing.T ) {
225
+ t .Parallel ()
226
+ db := databasefake .New ()
227
+ entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, 2 , coderdenttest .Keys , all )
228
+ require .NoError (t , err )
229
+ require .False (t , entitlements .HasLicense )
230
+ require .Len (t , entitlements .Warnings , 1 )
231
+ require .Equal (t , "You have multiple replicas but high availability is an Enterprise feature. Contact sales to get a license." , entitlements .Warnings [0 ])
232
+ })
233
+
234
+ t .Run ("MultipleReplicasNotEntitled" , func (t * testing.T ) {
235
+ t .Parallel ()
236
+ db := databasefake .New ()
237
+ db .InsertLicense (context .Background (), database.InsertLicenseParams {
238
+ Exp : time .Now ().Add (time .Hour ),
239
+ JWT : coderdenttest .GenerateLicense (t , coderdenttest.LicenseOptions {
240
+ AuditLog : true ,
241
+ }),
242
+ })
243
+ entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, 2 , coderdenttest .Keys , map [string ]bool {
244
+ codersdk .FeatureHighAvailability : true ,
245
+ })
246
+ require .NoError (t , err )
247
+ require .True (t , entitlements .HasLicense )
248
+ require .Len (t , entitlements .Warnings , 1 )
249
+ require .Equal (t , "You have multiple replicas but your license is not entitled to high availability." , entitlements .Warnings [0 ])
250
+ })
251
+
252
+ t .Run ("MultipleReplicasGrace" , func (t * testing.T ) {
253
+ t .Parallel ()
254
+ db := databasefake .New ()
255
+ db .InsertLicense (context .Background (), database.InsertLicenseParams {
256
+ JWT : coderdenttest .GenerateLicense (t , coderdenttest.LicenseOptions {
257
+ HighAvailability : true ,
258
+ GraceAt : time .Now ().Add (- time .Hour ),
259
+ ExpiresAt : time .Now ().Add (time .Hour ),
260
+ }),
261
+ Exp : time .Now ().Add (time .Hour ),
262
+ })
263
+ entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, 2 , coderdenttest .Keys , map [string ]bool {
264
+ codersdk .FeatureHighAvailability : true ,
265
+ })
266
+ require .NoError (t , err )
267
+ require .True (t , entitlements .HasLicense )
268
+ require .Len (t , entitlements .Warnings , 1 )
269
+ require .Equal (t , "You have multiple replicas but your license for high availability is expired." , entitlements .Warnings [0 ])
270
+ })
217
271
}
0 commit comments