-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
keygen_test.go
642 lines (537 loc) · 41.4 KB
/
keygen_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
package keygen
import (
"bytes"
"context"
"io"
"net/http"
"os"
"testing"
"time"
"github.com/denisbrodbeck/machineid"
"github.com/google/uuid"
"github.com/hashicorp/go-retryablehttp"
)
func init() {
log := Logger.(*logger)
log.Level = LogLevelDebug
if url := os.Getenv("KEYGEN_CUSTOM_DOMAIN"); url != "" {
APIURL = url
}
PublicKey = os.Getenv("KEYGEN_PUBLIC_KEY")
Environment = os.Getenv("KEYGEN_ENVIRONMENT_ID")
Account = os.Getenv("KEYGEN_ACCOUNT_ID")
Product = os.Getenv("KEYGEN_PRODUCT_ID")
LicenseKey = os.Getenv("KEYGEN_LICENSE_KEY")
Token = os.Getenv("KEYGEN_LICENSE_TOKEN")
Logger = log
}
func TestValidate(t *testing.T) {
ctx := context.Background()
fingerprint, err := machineid.ProtectedID(Account)
if err != nil {
t.Fatalf("Should fingerprint the current machine: err=%v", err)
}
if _, err := Validate(ctx); err != ErrValidationFingerprintMissing {
t.Fatalf("Should have a required scope: err=%v", err)
}
license, err := Validate(ctx, fingerprint)
if err == nil {
t.Fatalf("Should not be activated: err=%v", err)
}
switch err.(type) {
case *LicenseTokenError:
t.Fatalf("Should be a valid license token: err=%v", err)
case *LicenseKeyError:
t.Fatalf("Should be a valid license key: err=%v", err)
case *RateLimitError:
t.Fatalf("Should not be rate limited: err=%v", err)
case *NotAuthorizedError:
t.Fatalf("Should be authorized: err=%v", err)
case *NotFoundError:
t.Fatalf("Should exist: err=%v", err)
}
switch {
case err == ErrLicenseInvalid:
t.Fatalf("Should be a valid license: err=%v", err)
case err == ErrLicenseNotActivated:
switch {
case license.LastValidation.Code != ValidationCodeNoMachine:
t.Fatalf("Should store last validation code: code=%s", license.LastValidation.Code)
case license.LastValidation.Valid:
t.Fatalf("Should store last validation: valid=%t", license.LastValidation.Valid)
case license.ID == "":
t.Fatalf("Should have a correctly set license ID: license=%v", license)
}
if ts := license.LastValidated; ts == nil || time.Now().Add(time.Duration(-time.Second)).After(*ts) {
t.Fatalf("Should have a correct last validated timestamp: ts=%v", ts)
}
{
dataset, err := license.Verify()
switch {
case err == ErrLicenseKeyNotGenuine:
t.Fatalf("Should be a genuine license key: err=%v", err)
case err != nil:
t.Fatalf("Should not fail genuine check: err=%v", err)
}
t.Logf("dataset=%v", dataset)
}
// defaults
{
lic, err := license.Checkout(ctx)
if err != nil {
t.Fatalf("Should not fail checkout: err=%v", err)
}
err = lic.Verify()
switch {
case err == ErrLicenseFileNotGenuine:
t.Fatalf("Should be a genuine license file: err=%v", err)
case err != nil:
t.Fatalf("Should not fail genuine check: err=%v", err)
}
dataset, err := lic.Decrypt(license.Key)
if err != nil {
t.Fatalf("Should not fail decrypt: err=%v", err)
}
switch {
case dataset.License.ID != license.ID:
t.Fatalf("Should have the correct license ID: actual=%s expected=%s", dataset.License.ID, license.ID)
case len(dataset.Entitlements) == 0:
t.Fatalf("Should have at least 1 entitlement: entitlements=%v", dataset.Entitlements)
case dataset.Issued.IsZero():
t.Fatalf("Should have an issued timestamp: ts=%v", dataset.Issued)
case dataset.Expiry.IsZero():
t.Fatalf("Should have an expiry timestamp: ts=%v", dataset.Expiry)
case dataset.TTL == 0:
t.Fatalf("Should have a TTL: ttl=%d", dataset.TTL)
}
t.Logf("dataset=%+v", dataset)
}
// options
{
lic, err := license.Checkout(
ctx,
CheckoutInclude(),
CheckoutTTL(24*time.Hour),
)
if err != nil {
t.Fatalf("Should not fail checkout: err=%v", err)
}
err = lic.Verify()
switch {
case err == ErrLicenseFileNotGenuine:
t.Fatalf("Should be a genuine license file: err=%v", err)
case err != nil:
t.Fatalf("Should not fail genuine check: err=%v", err)
}
dataset, err := lic.Decrypt(license.Key)
if err != nil {
t.Fatalf("Should not fail decrypt: err=%v", err)
}
switch {
case dataset.License.ID != license.ID:
t.Fatalf("Should have the correct license ID: actual=%s expected=%s", dataset.License.ID, license.ID)
case len(dataset.Entitlements) != 0:
t.Fatalf("Should have no entitlements: entitlements=%v", dataset.Entitlements)
case dataset.Issued.IsZero():
t.Fatalf("Should have an issued timestamp: ts=%v", dataset.Issued)
case time.Until(dataset.Expiry) > 24*time.Hour+30*time.Second: // 30s for network lag
t.Fatalf("Should have an expiry timestamp: ts=%v", dataset.Expiry)
case dataset.TTL == 0:
t.Fatalf("Should have a TTL: ttl=%d", dataset.TTL)
}
t.Logf("dataset=%+v", dataset)
}
machine, err := license.Activate(ctx, fingerprint)
if err != nil {
t.Fatalf("Should not fail activation: err=%v", err)
}
// defaults
{
mic, err := machine.Checkout(ctx)
if err != nil {
t.Fatalf("Should not fail checkout: err=%v", err)
}
err = mic.Verify()
switch {
case err == ErrLicenseFileNotGenuine:
t.Fatalf("Should be a genuine machine file: err=%v", err)
case err != nil:
t.Fatalf("Should not fail genuine check: err=%v", err)
}
dataset, err := mic.Decrypt(license.Key + machine.Fingerprint)
if err != nil {
t.Fatalf("Should not fail decrypt: err=%v", err)
}
switch {
case dataset.Machine.ID != machine.ID:
t.Fatalf("Should have the correct machine ID: actual=%s expected=%s", dataset.Machine.ID, machine.ID)
case dataset.License.ID != license.ID:
t.Fatalf("Should have the correct license ID: actual=%s expected=%s", dataset.License.ID, license.ID)
case len(dataset.Entitlements) == 0:
t.Fatalf("Should have at least 1 entitlement: entitlements=%v", dataset.Entitlements)
case dataset.Issued.IsZero():
t.Fatalf("Should have an issued timestamp: ts=%v", dataset.Issued)
case dataset.Expiry.IsZero():
t.Fatalf("Should have an expiry timestamp: ts=%v", dataset.Expiry)
case dataset.TTL == 0:
t.Fatalf("Should have a TTL: ttl=%d", dataset.TTL)
}
t.Logf("dataset=%+v", dataset)
}
// options
{
mic, err := machine.Checkout(
ctx,
CheckoutInclude("license", "components"),
CheckoutTTL(24*time.Hour*365),
)
if err != nil {
t.Fatalf("Should not fail checkout: err=%v", err)
}
err = mic.Verify()
switch {
case err == ErrLicenseFileNotGenuine:
t.Fatalf("Should be a genuine machine file: err=%v", err)
case err != nil:
t.Fatalf("Should not fail genuine check: err=%v", err)
}
dataset, err := mic.Decrypt(license.Key + machine.Fingerprint)
if err != nil {
t.Fatalf("Should not fail decrypt: err=%v", err)
}
switch {
case dataset.Machine.ID != machine.ID:
t.Fatalf("Should have the correct machine ID: actual=%s expected=%s", dataset.Machine.ID, machine.ID)
case dataset.License.ID != license.ID:
t.Fatalf("Should have the correct license ID: actual=%s expected=%s", dataset.License.ID, license.ID)
case len(dataset.Entitlements) != 0:
t.Fatalf("Should have no entitlements: entitlements=%v", dataset.Entitlements)
case len(dataset.Components) != 0:
t.Fatalf("Should have no components: components=%v", dataset.Components)
case dataset.Issued.IsZero():
t.Fatalf("Should have an issued timestamp: ts=%v", dataset.Issued)
case time.Until(dataset.Expiry) < 24*time.Hour*364:
t.Fatalf("Should have an expiry timestamp: ts=%v", dataset.Expiry)
case dataset.TTL == 0:
t.Fatalf("Should have a TTL: ttl=%d", dataset.TTL)
}
t.Logf("dataset=%+v", dataset)
}
// _, err = license.Activate(fingerprint)
// switch {
// case err == nil:
// t.Fatalf("Should not be activated again: license=%v fingerprint=%s", license, fingerprint)
// case err != ErrMachineAlreadyActivated:
// t.Fatalf("Should fail duplicate activation: err=%v", err)
// }
_, err = license.Activate(ctx, uuid.New().String())
if err != ErrMachineLimitExceeded {
t.Fatalf("Should fail over-limit activation: license=%v err=%v", license, err)
}
// Check if there are any race conditions
for i := 0; i <= 5; i++ {
go license.Machine(ctx, machine.Fingerprint)
}
err = machine.Monitor(ctx)
if err != nil {
t.Fatalf("Should not fail to send first hearbeat ping: err=%v", err)
}
if machine.HeartbeatStatus != HeartbeatStatusCodeAlive {
t.Fatalf("Should have a heartbeat that is alive: license=%v machine=%v", license, machine)
}
if !machine.RequireHeartbeat {
t.Fatalf("Should require a heartbeat: license=%v machine=%v", license, machine)
}
processes := []*Process{}
for i := 0; i < 5; i++ {
process, err := machine.Spawn(ctx, uuid.New().String())
if err != nil {
t.Fatalf("Should not fail spawning process: err=%v", err)
}
if process.Status != ProcessStatusCodeAlive {
t.Fatalf("Should have a heartbeat that is alive: license=%v machine=%v process=%v", license, machine, process)
}
processes = append(processes, process)
}
_, err = machine.Spawn(ctx, uuid.New().String())
if err != ErrProcessLimitExceeded {
t.Fatalf("Should fail over-limit spawn: machine=%v err=%v", machine, err)
}
procs, err := machine.Processes(ctx)
if err != nil {
t.Fatalf("Should not fail listing processes: err=%v", err)
}
if len(procs) != len(processes) {
t.Fatalf("Should list all processes: actual=%v expected=%v", procs, processes)
}
for _, process := range processes {
err = process.Kill(ctx)
if err != nil {
t.Fatalf("Should not fail killing process: err=%v", err)
}
}
_, err = license.Machine(ctx, fingerprint)
if err != nil {
t.Fatalf("Should not fail to retrieve the current machine: err=%v", err)
}
_, err = license.Machine(ctx, "<invalid>")
if err == nil {
t.Fatalf("Should fail to retrieve invalid machine: err=%v", err)
}
machines, err := license.Machines(ctx)
if err != nil {
t.Fatalf("Should not fail to list machines: err=%v", err)
}
l, err := Validate(ctx, fingerprint)
if err != nil {
t.Fatalf("Should not fail revalidation: err=%v", err)
}
switch {
case l.LastValidation.Code != ValidationCodeValid:
t.Fatalf("Should store last revalidation code: code=%s", l.LastValidation.Code)
case !l.LastValidation.Valid:
t.Fatalf("Should store last revalidation: valid=%t", l.LastValidation.Valid)
}
for _, machine := range machines {
err = machine.Deactivate(ctx)
if err != nil {
t.Fatalf("Should not fail deactivation: err=%v", err)
}
}
err = license.Deactivate(ctx, fingerprint)
if e, ok := err.(*NotFoundError); !ok {
t.Fatalf("Should already be deactivated: err=%v", e)
}
entitlements, err := license.Entitlements(ctx)
if err != nil {
t.Fatalf("Should not fail to list entitlements: err=%v", err)
}
if len(entitlements) == 0 {
t.Fatalf("Should have entitlements: entitlements=%v", entitlements)
}
// Components
{
board := uuid.NewString()
disk := uuid.NewString()
cpu := uuid.NewString()
gpu := uuid.NewString()
machine, err := license.Activate(
ctx,
fingerprint,
Component{Name: "Board", Fingerprint: board},
Component{Name: "Drive", Fingerprint: disk},
Component{Name: "CPU", Fingerprint: cpu},
Component{Name: "GPU", Fingerprint: gpu},
)
if err != nil {
t.Fatalf("Should not fail reactivation: err=%v", err)
}
components, err := machine.Components(ctx)
if err != nil {
t.Fatalf("Should not fail to list components: err=%v", err)
}
if len(components) != 4 {
t.Fatalf("Should have components: components=%v", components)
}
license, err = Validate(ctx, fingerprint, board, disk, gpu, cpu)
if err != nil {
t.Fatalf("Should be valid: err=%v", err)
}
switch {
case license.LastValidation.Scope.Fingerprint != fingerprint:
t.Fatalf("Should be scoped to fingerprint: scope=%v", license.LastValidation)
case len(license.LastValidation.Scope.Components) != 4:
t.Fatalf("Should be scoped to components: scope=%v", license.LastValidation)
}
if err := license.Validate(ctx, fingerprint, uuid.NewString()); err != ErrComponentNotActivated {
t.Fatalf("Should be invalid: err=%v", err)
}
mic, err := machine.Checkout(
ctx,
CheckoutInclude("components", "license", "license.entitlements"),
)
if err != nil {
t.Fatalf("Should not fail checkout: err=%v", err)
}
err = mic.Verify()
switch {
case err == ErrLicenseFileNotGenuine:
t.Fatalf("Should be a genuine machine file: err=%v", err)
case err != nil:
t.Fatalf("Should not fail genuine check: err=%v", err)
}
dataset, err := mic.Decrypt(license.Key + machine.Fingerprint)
if err != nil {
t.Fatalf("Should not fail decrypt: err=%v", err)
}
switch {
case dataset.Machine.ID != machine.ID:
t.Fatalf("Should have the correct machine ID: actual=%s expected=%s", dataset.Machine.ID, machine.ID)
case dataset.License.ID != license.ID:
t.Fatalf("Should have the correct license ID: actual=%s expected=%s", dataset.License.ID, license.ID)
case len(dataset.Entitlements) == 0:
t.Fatalf("Should have entitlements: entitlements=%v", dataset.Entitlements)
case len(dataset.Components) != 4:
t.Fatalf("Should have components: components=%v", dataset.Components)
case dataset.Issued.IsZero():
t.Fatalf("Should have an issued timestamp: ts=%v", dataset.Issued)
case dataset.Expiry.IsZero():
t.Fatalf("Should have an expiry timestamp: ts=%v", dataset.Expiry)
case dataset.TTL == 0:
t.Fatalf("Should have a TTL: ttl=%d", dataset.TTL)
}
err = machine.Deactivate(ctx)
if err != nil {
t.Fatalf("Should not fail deactivation: err=%v", err)
}
}
t.Logf(
"license=%+v machines=%+v entitlements=%+v",
license,
machines,
entitlements,
)
case err != nil:
t.Fatalf("Should not fail validation: err=%v", err)
}
}
func TestLicenseFile(t *testing.T) {
lic := &LicenseFile{Certificate: "-----BEGIN LICENSE FILE-----\neyJlbmMiOiJDK2dneG5xRkJ6RURXMWc1YTBrUTE4OHBpdU9BL09vMkZDeUov\na2tlVk5QL3lJRTJGTVVXeXJZWUpzVGdmNXNIWFk3dko0My9Eb1JlRlluQ3VO\nSHprazFJOXZZdVpOWm9rWExSSHJvVkdxQXhBQ0pSN0R6dUJVTDk2bjI3VTcw\nNTRpR21DbjZOYmxVOVJzOUF0dGxRZ0kxZ2FNNUdaaE0walAzaGZvTnFkdzZu\nK3M2Y3M2Q2xRNGg5SmlEeTlvRGQzYmxFMEx4c0tYekhDS2graGtNSmtkbTZU\ndG9FWkU0eDdFOE4rWWNNM1hhdnJzSnNDL2k5MUdWQk9aT2pWZkdDNFg2dlV4\nK2RScGszT3dpMUF5QTh3MVRTazE3QVVaRlZrcVpiSEZyM2l0T3hxc0ZBbUNB\nWExVOTl4UzU2SGdWM0pZWGFVL2tKNTZETkhBOXNaTnVUcWxHR05sQXo5bUN0\nM1dGV1FNREQzdFdaelJqaUVRam9jOWppSEgvR3dFSlBZWjZPSmZVdXJuVnlr\ncllyTC92V3ZLeDRqRitJVS9rV1VPNmpBTnJM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WFOd1FrR1VrNVJtaG1kbFhIeWNEYWpIVWd3UVhlK0JF\nVTd0cHBvd3hEMUcwdXMwVG1wQTdrOHBFS3g5b2Evb3k1MFV6WTV1cTl1OXU1\nZlhqdWRaVkcyRG9sdmdOUTM0aXNTdU5LOTMzYkt3WXouTWdwT01nZTFsdWRJ\nbTZ1Mi41VXBDZ1lMNVJMWTRESjUyMnpmWWxRPT0iLCJzaWciOiJEK3h1czhp\nczZHbXI1ZzFVbjVwU1BSTUtpTGpqU2I5NGszbjM1QmpOWTQxNHo3SDFEeUZx\nYkVlQ2hhWExoajVqTEg2WG5PR0pFSDFYaXNNWUFMdjhCQT09IiwiYWxnIjoi\nYWVzLTI1Ni1nY20rZWQyNTUxOSJ9\n-----END LICENSE FILE-----\n"}
err := lic.Verify()
switch {
case err == ErrLicenseFileNotGenuine:
t.Fatalf("License file is not genuine: err=%v", err)
case err != nil:
t.Fatalf("License file verification failed: err=%v", err)
}
dataset, err := lic.Decrypt(LicenseKey)
switch {
case err == ErrLicenseFileExpired:
// noop
case err != nil:
t.Fatalf("License file decryption failed: err=%v", err)
}
t.Logf("dataset=%+v\n", dataset)
}
func TestMachineFile(t *testing.T) {
lic := &MachineFile{Certificate: "-----BEGIN MACHINE FILE-----\neyJlbmMiOiI0dFpUc2xpb3gxSUlyMlp2U1BjdWpnSmZUV0RadWdpU3ZaVDUy\nL2FTbS8vYlBHeUJTbTFockc5NWNRejRIbCt2b2lodzEzNk9ZaTRuUlhmQWEv\nS3pNMktXcm1tMHdaMWx6eG92QXErNkV6dUFnb3haT1VtZlJqVmx0ZGp1aXhr\nb2V3T0NvMjRRMFFtUU5uaC9EZDgzSnBYb3BOMnU1MEdqbE85RFFxQi9pM2pM\nLzE4Y2JUL01LdlQ3MlRxejkwcWM2aDVTY2k2TWRmUkhpZlcrVDQ5N01pZ1pU\nQ2dkMjNPTitBWVBDY2V3b2cyU0RqaENFWXhiKzFGaGc5Z3p5VmxXVFpNRTBl\ndUtHZ2R6dzVT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FlTSGsy\nMVlXY2lPeW0rQXRVQktxWTVjM1lkaWMwcnEwKzA4dTE1YzdvVElSNmVKYVlw\nOXNXeUNlSktsdHZrbGc2NmJMblBqT1QyTWMray9oZmh3ekF2UXJLZ2hOQT09\nLkhFYmswd2JnN2o1b3FpVUgucCtvWVZGR3FWL0oyd1ZCMzljeEcxQT09Iiwi\nc2lnIjoiTE5NVlBtNU5tK05rRXZISnRaMm5NRWlQTDZDaW5Ud0lYSWtJbGsx\nREZLZU5SR2hXcDBmc094MzAwdDAvYkpIeFcrMm1FSGU0UnFTMnpBV0Jhc2Vo\nQ1E9PSIsImFsZyI6ImFlcy0yNTYtZ2NtK2VkMjU1MTkifQ==\n-----END MACHINE FILE-----\n"}
err := lic.Verify()
switch {
case err == ErrMachineFileNotGenuine:
t.Fatalf("Machine file is not genuine: err=%v", err)
case err != nil:
t.Fatalf("Machine file verification failed: err=%v", err)
}
dataset, err := lic.Decrypt(LicenseKey + "39bb2cae-af5a-40c2-80f7-9e2ea0f90d17")
switch {
case err == ErrMachineFileExpired:
// noop
case err != nil:
t.Fatalf("Machine file decryption failed: err=%v", err)
}
t.Logf("dataset=%+v", dataset)
}
func TestLicenseFileNoTTL(t *testing.T) {
lic := &LicenseFile{Certificate: "-----BEGIN LICENSE FILE-----\neyJlbmMiOiJBTy9VZVBRMzJwbTlSeU43bzdWeEI4UlRhRmJPTVl2aWNTMzBY\neUkwQ1FwMloyRTRkRW9rd1g2c3RDZ0xyNUhaZElCUjVDTGx0REk4QjRuK2tE\nSDd4QjAwM2pTWVAvTTRoK0tmTTJNSFZEclZWVklJRm8xY0Nrb29wYWZCUVBw\nWDg4UTRrWWNLYWNua0E2MDRkRDl1L2YzWEh2MUZDZGdRYWxGOFhpZnV4QTE4\neVdXSCtTTlVPNVZZRDRqNDhKaDN4MS81TUtWN3pyNGJqd3Jubk85NGhZaUd4\nZ3c0VWYyM3dMUEZwTTBOaU9jLzRpZ0FPT2ZQOWU2bUVFSTgxa0hOTTlBell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WVDWWZ2Sm52b3cxcFZnZXc3SVpiLzdvQXFKY1BSMnVXYkZu\nTXdrS3ltamJhVDVQOVJOWmNDeDJ6THJqdlBqT3dMZitVSXBpZENOK0tJQ3hy\nSy9yZHFlcFZQN0ZpdmJzOTJ3aUQ4TkM5UmhtQXpCZzdTQT09LmJndnE2Uy9h\nb094SzFwTlMuYmdVcTEwcEI5Ti9EbUcvZExrNU1VQT09Iiwic2lnIjoiOFEw\nTmV3b0JzaTNlMlpBR3RQaG9mVFBIT0JZVUFOWHlYVEU0UHFpSzhCU0FWWUdB\nUUFNdkM1bXhNLzBLeXR3a1NSekRsR01NWVRERzBITXhYbEpvQlE9PSIsImFs\nZyI6ImFlcy0yNTYtZ2NtK2VkMjU1MTkifQ==\n-----END LICENSE FILE-----\n"}
err := lic.Verify()
switch {
case err == ErrLicenseFileNotGenuine:
t.Fatalf("License file is not genuine: err=%v", err)
case err != nil:
t.Fatalf("License file verification failed: err=%v", err)
}
dataset, err := lic.Decrypt(LicenseKey)
switch {
case err == ErrLicenseFileExpired:
t.Fatalf("License file should not be expired: err=%v", err)
case err != nil:
t.Fatalf("License file decryption failed: err=%v", err)
}
t.Logf("dataset=%+v", dataset)
}
func TestSignedKey(t *testing.T) {
license := &License{Scheme: SchemeCodeEd25519, Key: LicenseKey}
dataset, err := license.Verify()
switch {
case err == ErrLicenseKeyNotGenuine:
t.Fatalf("License key is not genuine: err=%v", err)
case err != nil:
t.Fatalf("License key verification failed: err=%v", err)
}
t.Logf("dataset=%s", dataset)
}
func TestUpgrade(t *testing.T) {
ctx := context.Background()
opts := UpgradeOptions{
PublicKey: os.Getenv("PERSONAL_PUBLIC_KEY"),
Filename: `test_{{.platform}}_{{.arch}}{{if .ext}}.{{.ext}}{{end}}`,
CurrentVersion: "1.0.0",
Channel: "stable",
}
upgrade, err := Upgrade(ctx, opts)
switch {
case err == ErrUpgradeNotAvailable:
t.Fatalf("Should have an upgrade available: err=%v", err)
case err != nil:
t.Fatalf("Should not fail upgrade: err=%v", err)
}
err = upgrade.Install(ctx)
if err != nil {
t.Fatalf("Should not fail installing upgrade: err=%v", err)
}
// Latest version
opts.CurrentVersion = "1.0.1"
_, err = Upgrade(ctx, opts)
if err != ErrUpgradeNotAvailable {
t.Fatalf("Should not have an upgrade available: err=%v", err)
}
// Future version
opts.CurrentVersion = "2.0.0"
_, err = Upgrade(ctx, opts)
if err != ErrUpgradeNotAvailable {
t.Fatalf("Should not have an upgrade available: err=%v", err)
}
// Invalid version
opts.CurrentVersion = "<not set>"
_, err = Upgrade(ctx, opts)
if err != ErrUpgradeNotAvailable {
t.Fatalf("Should not have an upgrade available: err=%v", err)
}
// Invalid product
opts.CurrentVersion = "1.0.0"
opts.Product = uuid.NewString()
_, err = Upgrade(ctx, opts)
if err != ErrUpgradeNotAvailable {
t.Fatalf("Should not have an upgrade available: err=%v", err)
}
t.Logf("upgrade=%v", upgrade)
}
func TestWebhook(t *testing.T) {
MaxClockDrift = -1
body := []byte(`{"data":{"id":"dfd66777-8a60-411c-b61c-ad51c671c0bd","type":"webhook-events","attributes":{"endpoint":"https://5173-2600-1700-3e90-a450-533-a11e-339-f87b.ngrok.io","payload":"{\"data\":{\"id\":\"1598f237-f82f-448a-91f7-18d2c7e6fd41\",\"type\":\"licenses\",\"attributes\":{\"name\":\"Floating Demo License\",\"key\":\"DEMO-DAD877-FCBF82-B83D5A-03E644-V3\",\"expiry\":\"2023-01-01T00:00:00.000Z\",\"status\":\"ACTIVE\",\"uses\":0,\"suspended\":false,\"scheme\":null,\"encrypted\":false,\"strict\":false,\"floating\":true,\"concurrent\":false,\"protected\":true,\"maxMachines\":10,\"maxProcesses\":null,\"maxCores\":null,\"maxUses\":null,\"requireHeartbeat\":false,\"requireCheckIn\":false,\"lastValidated\":\"2022-06-06T16:03:28.185Z\",\"lastCheckIn\":null,\"nextCheckIn\":null,\"metadata\":{\"token\":\"activ-cd4f3a6c17707b94bacab29ab489ddf5v3\"},\"created\":\"2021-04-20T16:14:46.713Z\",\"updated\":\"2022-06-06T16:03:28.190Z\"},\"relationships\":{\"account\":{\"links\":{\"related\":\"/v1/accounts/1fddcec8-8dd3-4d8d-9b16-215cac0f9b52\"},\"data\":{\"type\":\"accounts\",\"id\":\"1fddcec8-8dd3-4d8d-9b16-215cac0f9b52\"}},\"product\":{\"links\":{\"related\":\"/v1/accounts/1fddcec8-8dd3-4d8d-9b16-215cac0f9b52/licenses/1598f237-f82f-448a-91f7-18d2c7e6fd41/product\"},\"data\":{\"type\":\"products\",\"id\":\"42b9731d-21f2-4911-a066-d380a96c3a94\"}},\"policy\":{\"links\":{\"related\":\"/v1/accounts/1fddcec8-8dd3-4d8d-9b16-215cac0f9b52/licenses/1598f237-f82f-448a-91f7-18d2c7e6fd41/policy\"},\"data\":{\"type\":\"policies\",\"id\":\"d048c5e6-b813-4e94-a346-d70726397457\"}},\"group\":{\"links\":{\"related\":\"/v1/accounts/1fddcec8-8dd3-4d8d-9b16-215cac0f9b52/licenses/1598f237-f82f-448a-91f7-18d2c7e6fd41/group\"},\"data\":null},\"user\":{\"links\":{\"related\":\"/v1/accounts/1fddcec8-8dd3-4d8d-9b16-215cac0f9b52/licenses/1598f237-f82f-448a-91f7-18d2c7e6fd41/user\"},\"data\":null},\"machines\":{\"links\":{\"related\":\"/v1/accounts/1fddcec8-8dd3-4d8d-9b16-215cac0f9b52/licenses/1598f237-f82f-448a-91f7-18d2c7e6fd41/machines\"},\"meta\":{\"cores\":0,\"count\":1}},\"tokens\":{\"links\":{\"related\":\"/v1/accounts/1fddcec8-8dd3-4d8d-9b16-215cac0f9b52/licenses/1598f237-f82f-448a-91f7-18d2c7e6fd41/tokens\"}},\"entitlements\":{\"links\":{\"related\":\"/v1/accounts/1fddcec8-8dd3-4d8d-9b16-215cac0f9b52/licenses/1598f237-f82f-448a-91f7-18d2c7e6fd41/entitlements\"}}},\"links\":{\"self\":\"/v1/accounts/1fddcec8-8dd3-4d8d-9b16-215cac0f9b52/licenses/1598f237-f82f-448a-91f7-18d2c7e6fd41\"}},\"meta\":{\"ts\":\"2022-06-06T16:03:28.206Z\",\"valid\":true,\"detail\":\"is valid\",\"constant\":\"VALID\",\"scope\":{\"fingerprint\":\"cbce3fc7-0568-476d-a078-069a5d0500a2\",\"entitlements\":[\"DEMO_ENTITLEMENT\"]}}}","event":"license.validation.succeeded","status":"DELIVERING","lastResponseCode":null,"lastResponseBody":null,"created":"2022-06-06T16:03:28.243Z","updated":"2022-06-06T16:03:28.243Z"},"relationships":{"account":{"links":{"related":"/v1/accounts/1fddcec8-8dd3-4d8d-9b16-215cac0f9b52"},"data":{"type":"accounts","id":"1fddcec8-8dd3-4d8d-9b16-215cac0f9b52"}}},"links":{"self":"/v1/accounts/1fddcec8-8dd3-4d8d-9b16-215cac0f9b52/webhook-events/dfd66777-8a60-411c-b61c-ad51c671c0bd"},"meta":{"idempotencyToken":"99b89d681aecdff9a0435c9f507d00c5345a7c2d6e773f1756e4a9d42e4b14v3"}}}`)
url := `https://5173-2600-1700-3e90-a450-533-a11e-339-f87b.ngrok.io/webhooks`
req, err := http.NewRequest(http.MethodPost, url, bytes.NewReader(body))
if err != nil {
t.Fatalf("Should not fail creating a request: err=%v", err)
}
req.Header.Add("Keygen-Signature", `keyid="1fddcec8-8dd3-4d8d-9b16-215cac0f9b52", algorithm="ed25519", signature="oov4eX9ZC30U6l/OOOTH/IQF3NAlALlgBWQdh0LdG6WNtHbR95SoYJf2wOGMUGp2tYzNdSwlzPyepWozkKtXBg==", headers="(request-target) host date digest"`)
req.Header.Add("Digest", `sha-256=9QceiZktviddaBO8zKZe18/L2kZSFwpGDcmvFkvIH3k=`)
req.Header.Add("Date", `Mon, 06 Jun 2022 16:13:37 GMT`)
if err := VerifyWebhook(req); err != nil {
t.Fatalf("Should verify webhook: err=%v", err)
}
// Assert that the body can be read again
b, err := io.ReadAll(req.Body)
if err != nil {
t.Fatalf("Should read webhook: err=%v", err)
}
if !bytes.Equal(b, body) {
t.Fatalf("Body should match: actual=%s expected=%s", b, body)
}
}
func TestHTTPClient(t *testing.T) {
re := retryablehttp.NewClient()
re.Backoff = retryablehttp.LinearJitterBackoff
re.RetryMax = 5
HTTPClient = re.StandardClient()
}