blob: 55c0e5f440dbd1635279c012e19da677e82f73fd (
plain)
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
|
describe Hbc::Verify::Checksum, :cask do
let(:cask) { double("cask") }
let(:downloaded_path) { double("downloaded_path") }
let(:verification) { described_class.new(cask, downloaded_path) }
before do
allow(cask).to receive(:sha256).and_return(sha256)
end
around do |example|
shutup { example.run }
end
describe ".me?" do
subject { described_class.me?(cask) }
context "sha256 is :no_check" do
let(:sha256) { :no_check }
it { is_expected.to be false }
end
context "sha256 is nil" do
let(:sha256) { nil }
it { is_expected.to be true }
end
context "sha256 is empty" do
let(:sha256) { "" }
it { is_expected.to be true }
end
context "sha256 is a valid shasum" do
let(:sha256) { "deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef" }
it { is_expected.to be true }
end
end
describe "#verify" do
subject { verification.verify }
let(:computed) { "deadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef" }
before do
allow(verification).to receive(:computed).and_return(computed)
end
context "sha256 matches computed" do
let(:sha256) { computed }
it "does not raise an error" do
expect { subject }.not_to raise_error
end
end
context "sha256 is :no_check" do
let(:sha256) { :no_check }
it "does not raise an error" do
expect { subject }.not_to raise_error
end
end
context "sha256 does not match computed" do
let(:sha256) { "d3adb33fd3adb33fd3adb33fd3adb33fd3adb33fd3adb33fd3adb33fd3adb33f" }
it "raises an error" do
expect { subject }.to raise_error(Hbc::CaskSha256MismatchError)
end
end
context "sha256 is nil" do
let(:sha256) { nil }
it "raises an error" do
expect { subject }.to raise_error(Hbc::CaskSha256MissingError)
end
end
context "sha256 is empty" do
let(:sha256) { "" }
it "raises an error" do
expect { subject }.to raise_error(Hbc::CaskSha256MissingError)
end
end
end
end
|