File tree Expand file tree Collapse file tree 3 files changed +47
-1
lines changed Expand file tree Collapse file tree 3 files changed +47
-1
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ def add_boundary(data, license_name)
20
20
21
21
def remove_boundary ( data )
22
22
after_boundary = data . split ( BOUNDARY_START ) . last
23
- after_boundary . split ( BOUNDARY_END ) . first
23
+ after_boundary & .split ( BOUNDARY_END ) & .first
24
24
end
25
25
26
26
private
Original file line number Diff line number Diff line change @@ -42,6 +42,7 @@ def encrypt(data)
42
42
43
43
def decrypt ( data )
44
44
raise KeyError , "Provided key is not a public key." unless key . public?
45
+ raise DecryptionError , "Provided data is nil" if data . nil?
45
46
46
47
json_data = Base64 . decode64 ( data . chomp )
47
48
Original file line number Diff line number Diff line change 1
1
# frozen_string_literal: true
2
2
3
3
RSpec . describe Code0 ::License do
4
+ described_class . encryption_key = OpenSSL ::PKey ::RSA . generate ( 2048 )
5
+
4
6
let ( :license_data ) { default_license_data }
5
7
let ( :license ) { described_class . new ( license_data ) }
6
8
let ( :default_license_data ) do
31
33
)
32
34
end
33
35
36
+ describe ".load" do
37
+ subject ( :load ) { described_class . load ( data ) }
38
+
39
+ shared_examples "raises decryption error" do |example_name |
40
+ it ( example_name ) { expect { load } . to raise_error ( Code0 ::License ::Encryptor ::DecryptionError ) }
41
+ end
42
+
43
+ context "when data is nil" do
44
+ let ( :data ) { nil }
45
+
46
+ it { expect { load } . to raise_error ( Code0 ::License ::ValidationError ) }
47
+ end
48
+
49
+ it_behaves_like "raises decryption error" , "when data is an empty string" do
50
+ let ( :data ) { "" }
51
+ end
52
+
53
+ it_behaves_like "raises decryption error" , "when data is a start boundary" do
54
+ let ( :data ) do
55
+ <<~DATA
56
+ --------BEGIN CODE0 LICENSE--------
57
+ DATA
58
+ end
59
+ end
60
+
61
+ it_behaves_like "raises decryption error" , "when data is an end boundary" do
62
+ let ( :data ) do
63
+ <<~DATA
64
+ ---------END CODE0 LICENSE---------
65
+ DATA
66
+ end
67
+ end
68
+
69
+ it_behaves_like "raises decryption error" , "when data is a boundary" do
70
+ let ( :data ) do
71
+ <<~DATA
72
+ --------BEGIN CODE0 LICENSE--------
73
+ ---------END CODE0 LICENSE---------
74
+ DATA
75
+ end
76
+ end
77
+ end
78
+
34
79
describe "#valid?" do
35
80
subject { license . valid? }
36
81
You can’t perform that action at this time.
0 commit comments