@@ -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 {}, 1 , coderdenttest .Keys , all )
34
+ entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, 1 , 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 {}, 1 , coderdenttest .Keys , map [string ]bool {})
50
+ entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, 1 , 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 {}, 1 , coderdenttest .Keys , map [string ]bool {})
74
+ entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, 1 , 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,7 +96,7 @@ 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 {}, 1 , coderdenttest .Keys , all )
99
+ entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, 1 , 1 , coderdenttest .Keys , all )
100
100
require .NoError (t , err )
101
101
require .True (t , entitlements .HasLicense )
102
102
require .False (t , entitlements .Trial )
@@ -107,6 +107,9 @@ func TestEntitlements(t *testing.T) {
107
107
if featureName == codersdk .FeatureHighAvailability {
108
108
continue
109
109
}
110
+ if featureName == codersdk .FeatureMultipleGitAuth {
111
+ continue
112
+ }
110
113
niceName := strings .Title (strings .ReplaceAll (featureName , "_" , " " ))
111
114
require .Equal (t , codersdk .EntitlementGracePeriod , entitlements .Features [featureName ].Entitlement )
112
115
require .Contains (t , entitlements .Warnings , fmt .Sprintf ("%s is enabled but your license for this feature is expired." , niceName ))
@@ -119,7 +122,7 @@ func TestEntitlements(t *testing.T) {
119
122
JWT : coderdenttest .GenerateLicense (t , coderdenttest.LicenseOptions {}),
120
123
Exp : time .Now ().Add (time .Hour ),
121
124
})
122
- entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, 1 , coderdenttest .Keys , all )
125
+ entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, 1 , 1 , coderdenttest .Keys , all )
123
126
require .NoError (t , err )
124
127
require .True (t , entitlements .HasLicense )
125
128
require .False (t , entitlements .Trial )
@@ -130,6 +133,9 @@ func TestEntitlements(t *testing.T) {
130
133
if featureName == codersdk .FeatureHighAvailability {
131
134
continue
132
135
}
136
+ if featureName == codersdk .FeatureMultipleGitAuth {
137
+ continue
138
+ }
133
139
niceName := strings .Title (strings .ReplaceAll (featureName , "_" , " " ))
134
140
// Ensures features that are not entitled are properly disabled.
135
141
require .False (t , entitlements .Features [featureName ].Enabled )
@@ -152,7 +158,7 @@ func TestEntitlements(t *testing.T) {
152
158
}),
153
159
Exp : time .Now ().Add (time .Hour ),
154
160
})
155
- entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, 1 , coderdenttest .Keys , map [string ]bool {})
161
+ entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, 1 , 1 , coderdenttest .Keys , map [string ]bool {})
156
162
require .NoError (t , err )
157
163
require .True (t , entitlements .HasLicense )
158
164
require .Contains (t , entitlements .Warnings , "Your deployment has 2 active users but is only licensed for 1." )
@@ -174,7 +180,7 @@ func TestEntitlements(t *testing.T) {
174
180
}),
175
181
Exp : time .Now ().Add (time .Hour ),
176
182
})
177
- entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, 1 , coderdenttest .Keys , map [string ]bool {})
183
+ entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, 1 , 1 , coderdenttest .Keys , map [string ]bool {})
178
184
require .NoError (t , err )
179
185
require .True (t , entitlements .HasLicense )
180
186
require .Empty (t , entitlements .Warnings )
@@ -197,7 +203,7 @@ func TestEntitlements(t *testing.T) {
197
203
}),
198
204
})
199
205
200
- entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, 1 , coderdenttest .Keys , map [string ]bool {})
206
+ entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, 1 , 1 , coderdenttest .Keys , map [string ]bool {})
201
207
require .NoError (t , err )
202
208
require .True (t , entitlements .HasLicense )
203
209
require .False (t , entitlements .Trial )
@@ -212,7 +218,7 @@ func TestEntitlements(t *testing.T) {
212
218
AllFeatures : true ,
213
219
}),
214
220
})
215
- entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, 1 , coderdenttest .Keys , all )
221
+ entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, 1 , 1 , coderdenttest .Keys , all )
216
222
require .NoError (t , err )
217
223
require .True (t , entitlements .HasLicense )
218
224
require .False (t , entitlements .Trial )
@@ -228,7 +234,7 @@ func TestEntitlements(t *testing.T) {
228
234
t .Run ("MultipleReplicasNoLicense" , func (t * testing.T ) {
229
235
t .Parallel ()
230
236
db := databasefake .New ()
231
- entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, 2 , coderdenttest .Keys , all )
237
+ entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, 2 , 1 , coderdenttest .Keys , all )
232
238
require .NoError (t , err )
233
239
require .False (t , entitlements .HasLicense )
234
240
require .Len (t , entitlements .Errors , 1 )
@@ -244,7 +250,7 @@ func TestEntitlements(t *testing.T) {
244
250
AuditLog : true ,
245
251
}),
246
252
})
247
- entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, 2 , coderdenttest .Keys , map [string ]bool {
253
+ entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, 2 , 1 , coderdenttest .Keys , map [string ]bool {
248
254
codersdk .FeatureHighAvailability : true ,
249
255
})
250
256
require .NoError (t , err )
@@ -264,12 +270,60 @@ func TestEntitlements(t *testing.T) {
264
270
}),
265
271
Exp : time .Now ().Add (time .Hour ),
266
272
})
267
- entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, 2 , coderdenttest .Keys , map [string ]bool {
273
+ entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, 2 , 1 , coderdenttest .Keys , map [string ]bool {
268
274
codersdk .FeatureHighAvailability : true ,
269
275
})
270
276
require .NoError (t , err )
271
277
require .True (t , entitlements .HasLicense )
272
278
require .Len (t , entitlements .Warnings , 1 )
273
279
require .Equal (t , "You have multiple replicas but your license for high availability is expired. Reduce to one replica or workspace connections will stop working." , entitlements .Warnings [0 ])
274
280
})
281
+
282
+ t .Run ("MultipleGitAuthNoLicense" , func (t * testing.T ) {
283
+ t .Parallel ()
284
+ db := databasefake .New ()
285
+ entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, 1 , 2 , coderdenttest .Keys , all )
286
+ require .NoError (t , err )
287
+ require .False (t , entitlements .HasLicense )
288
+ require .Len (t , entitlements .Errors , 1 )
289
+ require .Equal (t , "You have multiple Git authorizations configured but this is an Enterprise feature. Reduce to one." , entitlements .Errors [0 ])
290
+ })
291
+
292
+ t .Run ("MultipleGitAuthNotEntitled" , func (t * testing.T ) {
293
+ t .Parallel ()
294
+ db := databasefake .New ()
295
+ db .InsertLicense (context .Background (), database.InsertLicenseParams {
296
+ Exp : time .Now ().Add (time .Hour ),
297
+ JWT : coderdenttest .GenerateLicense (t , coderdenttest.LicenseOptions {
298
+ AuditLog : true ,
299
+ }),
300
+ })
301
+ entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, 1 , 2 , coderdenttest .Keys , map [string ]bool {
302
+ codersdk .FeatureMultipleGitAuth : true ,
303
+ })
304
+ require .NoError (t , err )
305
+ require .True (t , entitlements .HasLicense )
306
+ require .Len (t , entitlements .Errors , 1 )
307
+ require .Equal (t , "You have multiple Git authorizations configured but your license is limited at one." , entitlements .Errors [0 ])
308
+ })
309
+
310
+ t .Run ("MultipleGitAuthGrace" , func (t * testing.T ) {
311
+ t .Parallel ()
312
+ db := databasefake .New ()
313
+ db .InsertLicense (context .Background (), database.InsertLicenseParams {
314
+ JWT : coderdenttest .GenerateLicense (t , coderdenttest.LicenseOptions {
315
+ MultipleGitAuth : true ,
316
+ GraceAt : time .Now ().Add (- time .Hour ),
317
+ ExpiresAt : time .Now ().Add (time .Hour ),
318
+ }),
319
+ Exp : time .Now ().Add (time .Hour ),
320
+ })
321
+ entitlements , err := license .Entitlements (context .Background (), db , slog.Logger {}, 1 , 2 , coderdenttest .Keys , map [string ]bool {
322
+ codersdk .FeatureMultipleGitAuth : true ,
323
+ })
324
+ require .NoError (t , err )
325
+ require .True (t , entitlements .HasLicense )
326
+ require .Len (t , entitlements .Warnings , 1 )
327
+ require .Equal (t , "You have multiple Git authorizations configured but your license is expired. Reduce to one." , entitlements .Warnings [0 ])
328
+ })
275
329
}
0 commit comments