forked from Homebrew/brew
/
audit_spec.rb
1026 lines (784 loc) · 28.5 KB
/
audit_spec.rb
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
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# typed: false
# frozen_string_literal: true
require "cask/audit"
describe Cask::Audit, :cask do
def include_msg?(problems, msg)
if msg.is_a?(Regexp)
Array(problems).any? { |problem| problem[:message] =~ msg }
else
Array(problems).any? { |problem| problem[:message] == msg }
end
end
matcher :pass do
match do |audit|
!audit.errors? && !audit.warnings?
end
end
matcher :fail_with do |message|
match do |audit|
include_msg?(audit.errors, message)
end
end
matcher :warn_with do |message|
match do |audit|
include_msg?(audit.warnings, message)
end
end
let(:cask) { instance_double(Cask::Cask) }
let(:new_cask) { nil }
let(:online) { nil }
let(:strict) { nil }
let(:token_conflicts) { nil }
let(:audit) {
described_class.new(cask, online: online,
strict: strict,
new_cask: new_cask,
token_conflicts: token_conflicts)
}
describe "#new" do
context "when `new_cask` is specified" do
let(:new_cask) { true }
it "implies `online`" do
expect(audit).to be_online
end
it "implies `strict`" do
expect(audit).to be_strict
end
it "implies `token_conflicts`" do
expect(audit.token_conflicts?).to be true
end
end
context "when `online` is specified" do
let(:online) { true }
it "implies `appcast`" do
expect(audit.appcast?).to be true
end
it "implies `download`" do
expect(audit.download).to be_truthy
end
end
end
describe "#result" do
subject { audit.result }
context "when there are errors" do
before do
audit.add_error "bad"
end
it { is_expected.to match(/failed/) }
end
context "when there are warnings" do
before do
audit.add_warning "eh"
end
it { is_expected.to match(/warning/) }
end
context "when there are errors and warnings" do
before do
audit.add_error "bad"
audit.add_warning "eh"
end
it { is_expected.to match(/failed/) }
end
context "when there are no errors or warnings" do
it { is_expected.to match(/passed/) }
end
end
describe "#run!" do
subject(:run) { audit.run! }
def tmp_cask(name, text)
path = Pathname.new "#{dir}/#{name}.rb"
path.open("w") do |f|
f.write text
end
Cask::CaskLoader.load(path)
end
let(:dir) { mktmpdir }
let(:cask) { Cask::CaskLoader.load(cask_token) }
describe "required stanzas" do
%w[version sha256 url name homepage].each do |stanza|
context "when missing #{stanza}" do
let(:cask_token) { "missing-#{stanza}" }
it { is_expected.to fail_with(/#{stanza} stanza is required/) }
end
end
end
describe "token validation" do
let(:strict) { true }
let(:cask) do
tmp_cask cask_token.to_s, <<~RUBY
cask '#{cask_token}' do
version '1.0'
sha256 '8dd95daa037ac02455435446ec7bc737b34567afe9156af7d20b2a83805c1d8a'
url "https://brew.sh/"
name 'Audit'
homepage 'https://brew.sh/'
app 'Audit.app'
end
RUBY
end
context "when cask token is not lowercase" do
let(:cask_token) { "Upper-Case" }
it "fails" do
expect(run).to fail_with(/lowercase/)
end
end
context "when cask token is not ascii" do
let(:cask_token) { "ascii⌘" }
it "fails" do
expect(run).to fail_with(/contains non-ascii characters/)
end
end
context "when cask token has +" do
let(:cask_token) { "app++" }
it "fails" do
expect(run).to fail_with(/\+ should be replaced by -plus-/)
end
end
context "when cask token has @" do
let(:cask_token) { "app@stuff" }
it "fails" do
expect(run).to fail_with(/@ should be replaced by -at-/)
end
end
context "when cask token has whitespace" do
let(:cask_token) { "app stuff" }
it "fails" do
expect(run).to fail_with(/whitespace should be replaced by hyphens/)
end
end
context "when cask token has underscores" do
let(:cask_token) { "app_stuff" }
it "fails" do
expect(run).to fail_with(/underscores should be replaced by hyphens/)
end
end
context "when cask token has non-alphanumeric characters" do
let(:cask_token) { "app(stuff)" }
it "fails" do
expect(run).to fail_with(/alphanumeric characters and hyphens/)
end
end
context "when cask token has double hyphens" do
let(:cask_token) { "app--stuff" }
it "fails" do
expect(run).to fail_with(/should not contain double hyphens/)
end
end
context "when cask token has leading hyphens" do
let(:cask_token) { "-app" }
it "fails" do
expect(run).to fail_with(/should not have leading or trailing hyphens/)
end
end
context "when cask token has trailing hyphens" do
let(:cask_token) { "app-" }
it "fails" do
expect(run).to fail_with(/should not have leading or trailing hyphens/)
end
end
end
describe "token bad words" do
let(:new_cask) { true }
let(:online) { false }
let(:cask) do
tmp_cask cask_token.to_s, <<~RUBY
cask "#{cask_token}" do
version "1.0"
sha256 "8dd95daa037ac02455435446ec7bc737b34567afe9156af7d20b2a83805c1d8a"
url "https://brew.sh/v\#{version}.zip"
name "Audit"
desc "Cask for testing tokens"
homepage "https://brew.sh/"
app "Audit.app"
end
RUBY
end
context "when cask token contains .app" do
let(:cask_token) { "token.app" }
it "fails" do
expect(run).to fail_with(/token contains .app/)
end
end
context "when cask token contains version designation" do
let(:cask_token) { "token-beta" }
it "fails if the cask is from an official tap" do
allow(cask).to receive(:tap).and_return(Tap.fetch("homebrew/cask"))
expect(run).to fail_with(/token contains version designation/)
end
it "does not fail if the cask is from the `cask-versions` tap" do
allow(cask).to receive(:tap).and_return(Tap.fetch("homebrew/cask-versions"))
expect(run).to pass
end
end
context "when cask token contains launcher" do
let(:cask_token) { "token-launcher" }
it "fails" do
expect(run).to fail_with(/token mentions launcher/)
end
end
context "when cask token contains desktop" do
let(:cask_token) { "token-desktop" }
it "fails" do
expect(run).to fail_with(/token mentions desktop/)
end
end
context "when cask token contains platform" do
let(:cask_token) { "token-osx" }
it "fails" do
expect(run).to fail_with(/token mentions platform/)
end
end
context "when cask token contains architecture" do
let(:cask_token) { "token-x86" }
it "fails" do
expect(run).to fail_with(/token mentions architecture/)
end
end
context "when cask token contains framework" do
let(:cask_token) { "token-java" }
it "fails" do
expect(run).to fail_with(/cask token mentions framework/)
end
end
context "when cask token is framework" do
let(:cask_token) { "java" }
it "does not fail" do
expect(run).to pass
end
end
context "when cask token is in tap_migrations.json and" do
let(:cask_token) { "token-migrated" }
let(:tap) { Tap.fetch("homebrew/cask") }
before do
allow(tap).to receive(:tap_migrations).and_return({ cask_token => "homebrew/core" })
allow(cask).to receive(:tap).and_return(tap)
end
context "when `new_cask` is true" do
let(:new_cask) { true }
it "fails" do
expect(run).to fail_with("#{cask_token} is listed in tap_migrations.json")
end
end
context "when `new_cask` is false" do
let(:new_cask) { false }
it "does not fail" do
expect(run).to pass
end
end
end
end
describe "locale validation" do
let(:cask) do
tmp_cask "locale-cask-test", <<~RUBY
cask 'locale-cask-test' do
version '1.0'
url "https://brew.sh/"
name 'Audit'
homepage 'https://brew.sh/'
app 'Audit.app'
language 'en', default: true do
sha256 '96574251b885c12b48a3495e843e434f9174e02bb83121b578e17d9dbebf1ffb'
'zh-CN'
end
language 'zh-CN' do
sha256 '96574251b885c12b48a3495e843e434f9174e02bb83121b578e17d9dbebf1ffb'
'zh-CN'
end
language 'ZH-CN' do
sha256 '96574251b885c12b48a3495e843e434f9174e02bb83121b578e17d9dbebf1ffb'
'zh-CN'
end
language 'zh-' do
sha256 '96574251b885c12b48a3495e843e434f9174e02bb83121b578e17d9dbebf1ffb'
'zh-CN'
end
language 'zh-cn' do
sha256 '96574251b885c12b48a3495e843e434f9174e02bb83121b578e17d9dbebf1ffb'
'zh-CN'
end
end
RUBY
end
context "when cask locale is invalid" do
it "error with invalid locale" do
expect(run).to fail_with(/Locale 'ZH-CN' is invalid\./)
expect(run).to fail_with(/Locale 'zh-' is invalid\./)
expect(run).to fail_with(/Locale 'zh-cn' is invalid\./)
end
end
end
describe "pkg allow_untrusted checks" do
let(:message) { "allow_untrusted is not permitted in official Homebrew Cask taps" }
context "when the Cask has no pkg stanza" do
let(:cask_token) { "basic-cask" }
it { is_expected.not_to fail_with(message) }
end
context "when the Cask does not have allow_untrusted" do
let(:cask_token) { "with-uninstall-pkgutil" }
it { is_expected.not_to fail_with(message) }
end
context "when the Cask has allow_untrusted" do
let(:cask_token) { "with-allow-untrusted" }
it { is_expected.to fail_with(message) }
end
end
describe "when the Cask stanza requires uninstall" do
let(:message) { "installer and pkg stanzas require an uninstall stanza" }
context "when the Cask does not require an uninstall" do
let(:cask_token) { "basic-cask" }
it { is_expected.not_to fail_with(message) }
end
context "when the pkg Cask has an uninstall" do
let(:cask_token) { "with-uninstall-pkgutil" }
it { is_expected.not_to fail_with(message) }
end
context "when the installer Cask has an uninstall" do
let(:cask_token) { "installer-with-uninstall" }
it { is_expected.not_to fail_with(message) }
end
context "when the installer Cask does not have an uninstall" do
let(:cask_token) { "with-installer-manual" }
it { is_expected.to fail_with(message) }
end
context "when the pkg Cask does not have an uninstall" do
let(:cask_token) { "pkg-without-uninstall" }
it { is_expected.to fail_with(message) }
end
end
describe "preflight stanza checks" do
let(:message) { "only a single preflight stanza is allowed" }
context "when the Cask has no preflight stanza" do
let(:cask_token) { "with-zap-rmdir" }
it { is_expected.not_to fail_with(message) }
end
context "when the Cask has only one preflight stanza" do
let(:cask_token) { "with-preflight" }
it { is_expected.not_to fail_with(message) }
end
context "when the Cask has multiple preflight stanzas" do
let(:cask_token) { "with-preflight-multi" }
it { is_expected.to fail_with(message) }
end
end
describe "postflight stanza checks" do
let(:message) { "only a single postflight stanza is allowed" }
context "when the Cask has no postflight stanza" do
let(:cask_token) { "with-zap-rmdir" }
it { is_expected.not_to fail_with(message) }
end
context "when the Cask has only one postflight stanza" do
let(:cask_token) { "with-postflight" }
it { is_expected.not_to fail_with(message) }
end
context "when the Cask has multiple postflight stanzas" do
let(:cask_token) { "with-postflight-multi" }
it { is_expected.to fail_with(message) }
end
end
describe "uninstall stanza checks" do
let(:message) { "only a single uninstall stanza is allowed" }
context "when the Cask has no uninstall stanza" do
let(:cask_token) { "with-zap-rmdir" }
it { is_expected.not_to fail_with(message) }
end
context "when the Cask has only one uninstall stanza" do
let(:cask_token) { "with-uninstall-rmdir" }
it { is_expected.not_to fail_with(message) }
end
context "when the Cask has multiple uninstall stanzas" do
let(:cask_token) { "with-uninstall-multi" }
it { is_expected.to fail_with(message) }
end
end
describe "uninstall_preflight stanza checks" do
let(:message) { "only a single uninstall_preflight stanza is allowed" }
context "when the Cask has no uninstall_preflight stanza" do
let(:cask_token) { "with-zap-rmdir" }
it { is_expected.not_to fail_with(message) }
end
context "when the Cask has only one uninstall_preflight stanza" do
let(:cask_token) { "with-uninstall-preflight" }
it { is_expected.not_to fail_with(message) }
end
context "when the Cask has multiple uninstall_preflight stanzas" do
let(:cask_token) { "with-uninstall-preflight-multi" }
it { is_expected.to fail_with(message) }
end
end
describe "uninstall_postflight stanza checks" do
let(:message) { "only a single uninstall_postflight stanza is allowed" }
context "when the Cask has no uninstall_postflight stanza" do
let(:cask_token) { "with-zap-rmdir" }
it { is_expected.not_to fail_with(message) }
end
context "when the Cask has only one uninstall_postflight stanza" do
let(:cask_token) { "with-uninstall-postflight" }
it { is_expected.not_to fail_with(message) }
end
context "when the Cask has multiple uninstall_postflight stanzas" do
let(:cask_token) { "with-uninstall-postflight-multi" }
it { is_expected.to fail_with(message) }
end
end
describe "zap stanza checks" do
let(:message) { "only a single zap stanza is allowed" }
context "when the Cask has no zap stanza" do
let(:cask_token) { "with-uninstall-rmdir" }
it { is_expected.not_to fail_with(message) }
end
context "when the Cask has only one zap stanza" do
let(:cask_token) { "with-zap-rmdir" }
it { is_expected.not_to fail_with(message) }
end
context "when the Cask has multiple zap stanzas" do
let(:cask_token) { "with-zap-multi" }
it { is_expected.to fail_with(message) }
end
end
describe "version checks" do
let(:message) { "you should use version :latest instead of version 'latest'" }
context "when version is 'latest'" do
let(:cask_token) { "version-latest-string" }
it { is_expected.to fail_with(message) }
end
context "when version is :latest" do
let(:cask_token) { "version-latest-with-checksum" }
it { is_expected.not_to fail_with(message) }
end
end
describe "sha256 checks" do
context "when version is :latest and sha256 is not :no_check" do
let(:cask_token) { "version-latest-with-checksum" }
it { is_expected.to fail_with("you should use sha256 :no_check when version is :latest") }
end
context "when sha256 is not a legal SHA-256 digest" do
let(:cask_token) { "invalid-sha256" }
it { is_expected.to fail_with("sha256 string must be of 64 hexadecimal characters") }
end
context "when sha256 is sha256 for empty string" do
let(:cask_token) { "sha256-for-empty-string" }
it { is_expected.to fail_with(/cannot use the sha256 for an empty string/) }
end
end
describe "hosting with livecheck checks" do
let(:message) { /please add a livecheck/ }
context "when the download does not use hosting with a livecheck" do
let(:cask_token) { "basic-cask" }
it { is_expected.not_to fail_with(message) }
end
context "when the download is hosted on SourceForge and has a livecheck" do
let(:cask_token) { "sourceforge-with-appcast" }
it { is_expected.not_to fail_with(message) }
end
context "when the download is hosted on SourceForge and does not have a livecheck" do
let(:cask_token) { "sourceforge-correct-url-format" }
let(:online) { true }
it { is_expected.to fail_with(message) }
end
context "when the download is hosted on DevMate and has a livecheck" do
let(:cask_token) { "devmate-with-appcast" }
it { is_expected.not_to fail_with(message) }
end
context "when the download is hosted on DevMate and does not have a livecheck" do
let(:cask_token) { "devmate-without-appcast" }
it { is_expected.to fail_with(message) }
end
context "when the download is hosted on HockeyApp and has a livecheck" do
let(:cask_token) { "hockeyapp-with-appcast" }
it { is_expected.not_to fail_with(message) }
end
context "when the download is hosted on HockeyApp and does not have a livecheck" do
let(:cask_token) { "hockeyapp-without-appcast" }
it { is_expected.to fail_with(message) }
end
end
describe "latest with appcast checks" do
let(:message) { "Casks with an `appcast` should not use `version :latest`." }
context "when the Cask is :latest and does not have an appcast" do
let(:cask_token) { "version-latest" }
it { is_expected.not_to fail_with(message) }
end
context "when the Cask is versioned and has an appcast" do
let(:cask_token) { "with-appcast" }
it { is_expected.not_to fail_with(message) }
end
context "when the Cask is :latest and has an appcast" do
let(:cask_token) { "latest-with-appcast" }
it { is_expected.to fail_with(message) }
end
end
describe "denylist checks" do
context "when the Cask is not on the denylist" do
let(:cask_token) { "adobe-air" }
it { is_expected.to pass }
end
context "when the Cask is on the denylist and" do
context "when it's in the official Homebrew tap" do
let(:cask_token) { "adobe-illustrator" }
it { is_expected.to fail_with(/#{cask_token} is not allowed: \w+/) }
end
context "when it isn't in the official Homebrew tap" do
let(:cask_token) { "pharo" }
it { is_expected.to pass }
end
end
end
describe "latest with auto_updates checks" do
let(:message) { "Casks with `version :latest` should not use `auto_updates`." }
context "when the Cask is :latest and does not have auto_updates" do
let(:cask_token) { "version-latest" }
it { is_expected.to pass }
end
context "when the Cask is versioned and does not have auto_updates" do
let(:cask_token) { "basic-cask" }
it { is_expected.to pass }
end
context "when the Cask is versioned and has auto_updates" do
let(:cask_token) { "auto-updates" }
it { is_expected.to pass }
end
context "when the Cask is :latest and has auto_updates" do
let(:cask_token) { "latest-with-auto-updates" }
it { is_expected.to fail_with(message) }
end
end
describe "preferred download URL formats" do
let(:message) { /URL format incorrect/ }
context "with incorrect SourceForge URL format" do
let(:cask_token) { "sourceforge-incorrect-url-format" }
it { is_expected.to fail_with(message) }
end
context "with correct SourceForge URL format" do
let(:cask_token) { "sourceforge-correct-url-format" }
it { is_expected.not_to fail_with(message) }
end
context "with correct SourceForge URL format for version :latest" do
let(:cask_token) { "sourceforge-version-latest-correct-url-format" }
it { is_expected.not_to fail_with(message) }
end
context "with incorrect OSDN URL format" do
let(:cask_token) { "osdn-incorrect-url-format" }
it { is_expected.to fail_with(message) }
end
context "with correct OSDN URL format" do
let(:cask_token) { "osdn-correct-url-format" }
it { is_expected.not_to fail_with(message) }
end
end
describe "generic artifact checks" do
context "with relative target" do
let(:cask_token) { "generic-artifact-relative-target" }
it { is_expected.to fail_with(/target must be.*absolute/) }
end
context "with user-relative target" do
let(:cask_token) { "generic-artifact-user-relative-target" }
it { is_expected.not_to fail_with(/target must be.*absolute/) }
end
context "with absolute target" do
let(:cask_token) { "generic-artifact-absolute-target" }
it { is_expected.not_to fail_with(/target must be.*absolute/) }
end
end
describe "url checks" do
context "with a block" do
let(:cask_token) { "booby-trap" }
context "when loading the cask" do
it "does not evaluate the block" do
expect { cask }.not_to raise_error
end
end
context "when doing an offline audit" do
let(:online) { false }
it "does not evaluate the block" do
expect(run).not_to pass
end
end
context "when doing and online audit" do
let(:online) { true }
it "evaluates the block" do
expect(run).to fail_with(/Boom/)
end
end
end
end
describe "token conflicts" do
let(:cask_token) { "with-binary" }
let(:token_conflicts) { true }
context "when cask token conflicts with a core formula" do
let(:formula_names) { %w[with-binary other-formula] }
it "warns about duplicates" do
expect(audit).to receive(:core_formula_names).and_return(formula_names)
expect(run).to warn_with(/possible duplicate/)
end
end
context "when cask token does not conflict with a core formula" do
let(:formula_names) { %w[other-formula] }
it { is_expected.to pass }
end
end
describe "audit of downloads" do
let(:cask_token) { "with-binary" }
let(:cask) { Cask::CaskLoader.load(cask_token) }
let(:download_double) { instance_double(Cask::Download) }
let(:message) { "Download Failed" }
before do
allow(audit).to receive(:download).and_return(download_double)
allow(audit).to receive(:check_https_availability)
end
it "when download and verification succeed it does not fail" do
expect(download_double).to receive(:fetch)
expect(run).to pass
end
it "when download fails it fails" do
expect(download_double).to receive(:fetch).and_raise(StandardError.new(message))
expect(run).to fail_with(/#{message}/)
end
end
context "when an exception is raised" do
let(:cask) { instance_double(Cask::Cask) }
it "fails the audit" do
expect(cask).to receive(:tap).and_raise(StandardError.new)
expect(run).to fail_with(/exception while auditing/)
end
end
describe "without description" do
let(:cask_token) { "without-description" }
let(:cask) do
tmp_cask cask_token.to_s, <<~RUBY
cask '#{cask_token}' do
version '1.0'
sha256 '8dd95daa037ac02455435446ec7bc737b34567afe9156af7d20b2a83805c1d8a'
url "https://brew.sh/"
name 'Audit'
homepage 'https://brew.sh/'
app 'Audit.app'
end
RUBY
end
context "when `new_cask` is true" do
let(:new_cask) { true }
it "fails" do
expect(run).to fail_with(/should have a description/)
end
end
context "when `new_cask` is false" do
let(:new_cask) { false }
it "warns" do
expect(run).to warn_with(/should have a description/)
end
end
end
context "with description" do
let(:cask_token) { "with-description" }
let(:cask) do
tmp_cask cask_token.to_s, <<~RUBY
cask "#{cask_token}" do
version "1.0"
sha256 "8dd95daa037ac02455435446ec7bc737b34567afe9156af7d20b2a83805c1d8a"
url "https://brew.sh/\#{version}.zip"
name "Audit"
desc "Cask Auditor"
homepage "https://brew.sh/"
app "Audit.app"
end
RUBY
end
it "passes" do
expect(run).to pass
end
end
context "when the url matches the homepage" do
let(:cask_token) { "foo" }
let(:cask) do
tmp_cask cask_token.to_s, <<~RUBY
cask '#{cask_token}' do
version '1.0'
sha256 '8dd95daa037ac02455435446ec7bc737b34567afe9156af7d20b2a83805c1d8a'
url 'https://foo.brew.sh/foo.zip'
name 'Audit'
desc 'Audit Description'
homepage 'https://foo.brew.sh'
app 'Audit.app'
end
RUBY
end
it { is_expected.to pass }
end
context "when the url does not match the homepage" do
let(:cask_token) { "foo" }
let(:cask) do
tmp_cask cask_token.to_s, <<~RUBY
cask '#{cask_token}' do
version "1.8.0_72,8.13.0.5"
sha256 "8dd95daa037ac02455435446ec7bc737b34567afe9156af7d20b2a83805c1d8a"
url "https://brew.sh/foo-\#{version.after_comma}.zip"
name "Audit"
desc "Audit Description"
homepage "https://foo.example.org"
app "Audit.app"
end
RUBY
end
it { is_expected.to fail_with(/a 'verified' parameter has to be added/) }
end
context "when the url does not match the homepage with verified" do
let(:cask_token) { "foo" }
let(:cask) do
tmp_cask cask_token.to_s, <<~RUBY
cask "#{cask_token}" do
version "1.8.0_72,8.13.0.5"
sha256 "8dd95daa037ac02455435446ec7bc737b34567afe9156af7d20b2a83805c1d8a"
url "https://brew.sh/foo-\#{version.after_comma}.zip", verified: "brew.sh"
name "Audit"
desc "Audit Description"
homepage "https://foo.example.org"
app "Audit.app"
end
RUBY
end
it { is_expected.to pass }
end
context "when there is no homepage" do
let(:cask_token) { "foo" }
let(:cask) do
tmp_cask cask_token.to_s, <<~RUBY
cask '#{cask_token}' do
version '1.8.0_72,8.13.0.5'
sha256 '8dd95daa037ac02455435446ec7bc737b34567afe9156af7d20b2a83805c1d8a'
url 'https://brew.sh/foo.zip'
name 'Audit'
desc 'Audit Description'
app 'Audit.app'
end
RUBY
end
it { is_expected.to fail_with(/a homepage stanza is required/) }
end
context "when url is lazy" do
let(:strict) { true }
let(:cask_token) { "with-lazy" }
let(:cask) do
tmp_cask cask_token.to_s, <<~RUBY