-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathmap_spec.rb
More file actions
174 lines (133 loc) · 4.97 KB
/
map_spec.rb
File metadata and controls
174 lines (133 loc) · 4.97 KB
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
require 'spec_helper'
describe VRT::Map do
let(:vrt) { VRT }
let(:dir) { vrt::DIR }
let(:sample_map) { described_class.new('999.999') }
before do
VRT.unload!
allow(vrt).to receive(:current_version).and_return('2.0')
end
after { VRT.unload! }
context 'with no argument' do
let(:current_map) { described_class.new }
it 'creates a VRT Map using the current version' do
expect(current_map.version).to eq('2.0')
end
end
context 'with an argument' do
it 'creates a VRT Map using a specific version' do
expect(sample_map.version).to eq('999.999')
end
end
describe '#build_structure' do
it 'builds a valid hash for the VRT structure on instantiation' do
expect(sample_map.structure).to include(:server_side_injection)
expect(sample_map.structure[:server_side_injection]).to be_a(VRT::Node)
end
end
context 'when the structure is queried' do
let(:good_query) { 'server_side_injection.sql_injection.blind' }
let(:sneaky_query) { 'server_side_injection.sql_injection.blind.sneaky_guy' }
let(:bad_query) { 'ssl_attack_breach_poodle_etc.unsafe_cross_origin_resource_sharing.critical_impact' }
it 'finds a category when given a query string' do
node = sample_map.find_node(good_query)
expect(node).to be_a(VRT::Node)
expect(node.id).to eq(:blind)
end
it 'can determine the validity of a given query string' do
expect(sample_map.valid?(good_query)).to be_truthy
expect(sample_map.valid?(sneaky_query)).to be_falsey
expect(sample_map.valid?(bad_query)).to be_falsey
end
end
describe '#find_node' do
subject { sample_map.find_node(vrt_id) }
context 'when vrt_id is nil' do
let(:vrt_id) { nil }
it { is_expected.to be_nil }
end
context 'when vrt_id is not a valid identifier' do
let(:vrt_id) { "I'm not valid" }
it { is_expected.to be_nil }
end
context 'when vrt_id is not a string' do
let(:vrt_id) { 55 }
it { is_expected.to be_nil }
end
context 'when vrt_id is a valid identifier' do
context 'vrt_id does not exist in version' do
let(:vrt_id) { 'cool_new_concept' }
it { is_expected.to be_nil }
end
context 'vrt_id exists in version' do
context 'vrt_id is category level' do
let(:vrt_id) { 'server_security_misconfiguration' }
it { is_expected.to be_a(VRT::Node) }
end
context 'vrt_id is a variant' do
let(:vrt_id) { 'server_security_misconfiguration.using_default_credentials.production_server' }
it { is_expected.to be_a(VRT::Node) }
end
end
end
end
describe '#get_lineage' do
context 'with a complex hierarchy' do
let(:id) { 'server_security_misconfiguration.using_default_credentials.production_server' }
it 'returns a formatted lineage string' do
expect(sample_map.get_lineage(id)).to eq(
'Server Security Misconfiguration (1.1) > Using Default Credentials > Production Server'
)
end
context 'when specifying max depth' do
it 'returns a formatted lineage string with the correct max depth' do
expect(sample_map.get_lineage(id, max_depth: 'subcategory')).to eq(
'Server Security Misconfiguration (1.1) > Using Default Credentials'
)
end
it 'returns a formatted lineage string with the correct max depth' do
expect(sample_map.get_lineage(id, max_depth: 'category')).to eq(
'Server Security Misconfiguration (1.1)'
)
end
end
end
context 'with a single-level element' do
let(:id) { 'insecure_direct_object_references_idor' }
it 'returns a formatted lineage string' do
expect(sample_map.get_lineage(id)).to eq 'Insecure Direct Object References (IDOR)'
end
end
end
describe '#valid?' do
subject { sample_map.valid?(string) }
context 'when uppercase characters' do
let(:string) { 'server_Security_misconfiguration' }
it { is_expected.to be_falsey }
end
context 'with all lowercase' do
let(:string) { 'server_security_misconfiguration' }
it { is_expected.to be_truthy }
end
context 'with invalid string' do
let(:string) { '12112asdas2312dcdwsdf-^?' }
it { is_expected.to be_falsey }
end
context 'when ending in a .' do
let(:string) { 'server_security_misconfiguration.' }
it { is_expected.to be_falsey }
end
context 'when a nested node' do
let(:string) { 'server_security_misconfiguration.unsafe_cross_origin_resource_sharing' }
it { is_expected.to be_truthy }
end
context 'when an invalid nested node' do
let(:string) { 'server_security_misconfiguration.meep_meep_meep' }
it { is_expected.to be_falsey }
end
context 'when contains numbers' do
let(:string) { 'sensitive_data_exposure.token_leakage_via_referer.untrusted_3rd_party' }
it { is_expected.to be_truthy }
end
end
end