Skip to content

Commit 701d647

Browse files
committed
Add specs for Rex::Oui
1 parent ebacb26 commit 701d647

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed

spec/lib/rex/mac_oui_spec.rb

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# -*- coding:binary -*-
2+
require 'spec_helper'
3+
4+
require 'rex/mac_oui'
5+
6+
describe Rex::Oui do
7+
describe ".lookup_oui_fullname" do
8+
subject { described_class.lookup_oui_fullname(mac) }
9+
10+
context "when valid mac for OUI with name" do
11+
let(:mac) { '000011' }
12+
let(:name) { 'Tektrnix' }
13+
it { is_expected.to eq(name) }
14+
end
15+
16+
context "when valid mac for OUI with name and long name" do
17+
let(:mac) { '00:00:0E:12:34:56' }
18+
let(:name) { 'Fujitsu' }
19+
let(:long_name) { 'FUJITSU LIMITED' }
20+
it { is_expected.to eq("#{name} / #{long_name}") }
21+
end
22+
23+
context "when valid mac format, without OUI" do
24+
let(:mac) { '11:22:33:44:55:66'}
25+
it { is_expected.to eq('UNKNOWN') }
26+
end
27+
28+
context "when invalid mac format" do
29+
let(:mac) { 'invalid' }
30+
it "raises an error" do
31+
expect { subject }.to raise_error
32+
end
33+
end
34+
end
35+
36+
describe ".lookup_oui_company_name" do
37+
subject { described_class.lookup_oui_company_name(mac) }
38+
39+
context "when valid mac for OUI with name" do
40+
let(:mac) { '000011' }
41+
let(:name) { 'Tektrnix' }
42+
it { is_expected.to eq(name) }
43+
end
44+
45+
context "when valid mac for OUI with name and long name" do
46+
let(:mac) { '00:00:0E:12:34:56' }
47+
let(:name) { 'Fujitsu' }
48+
let(:long_name) { 'FUJITSU LIMITED' }
49+
it { is_expected.to eq(long_name) }
50+
end
51+
52+
context "when valid mac format, without OUI" do
53+
let(:mac) { '11:22:33:44:55:66'}
54+
it { is_expected.to eq('UNKNOWN') }
55+
end
56+
57+
context "when invalid mac format" do
58+
let(:mac) { 'invalid' }
59+
it "raises an error" do
60+
expect { subject }.to raise_error
61+
end
62+
end
63+
end
64+
65+
describe ".check_mac" do
66+
context "when valid mac" do
67+
it "returns nil" do
68+
expect(described_class.check_mac('AA:BB:CC')).to be_nil
69+
expect(described_class.check_mac('AABBCC')).to be_nil
70+
expect(described_class.check_mac('AA:BB:CC:DD')).to be_nil
71+
expect(described_class.check_mac('AABBCCDD')).to be_nil
72+
expect(described_class.check_mac('AA:BB:CC:DD:EE')).to be_nil
73+
expect(described_class.check_mac('AABBCCDDEE')).to be_nil
74+
expect(described_class.check_mac('AA:BB:CC:DD:EE:FF')).to be_nil
75+
expect(described_class.check_mac('AABBCCDDEEFF')).to be_nil
76+
end
77+
end
78+
79+
context "when invalid mac" do
80+
it "raises an error" do
81+
expect { described_class.check_mac('AA') }.to raise_error
82+
expect { described_class.check_mac('AA:BB:CC:DD:JJ') }.to raise_error
83+
expect { described_class.check_mac('AA:BB') }.to raise_error
84+
expect { described_class.check_mac('AABB') }.to raise_error
85+
expect { described_class.check_mac('AA:BB:CC:DD:EE:FF:AA') }.to raise_error
86+
expect { described_class.check_mac('AABBCCDDEEFFAA') }.to raise_error
87+
end
88+
end
89+
end
90+
end

0 commit comments

Comments
 (0)