Skip to content

Commit 19e8a50

Browse files
committed
Land 3847, specs for Rex::Oui
2 parents 32faa0b + 3aadaf6 commit 19e8a50

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed

spec/lib/rex/mac_oui_spec.rb

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
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(:oui_fullname) { 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 { oui_fullname }.to raise_error
32+
end
33+
end
34+
end
35+
36+
describe ".lookup_oui_company_name" do
37+
subject(:oui_company_name) { 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 { oui_company_name }.to raise_error
61+
end
62+
end
63+
end
64+
65+
describe ".check_mac" do
66+
context "when valid mac" do
67+
it { expect(described_class.check_mac('AA:BB:CC')).to be_nil }
68+
it { expect(described_class.check_mac('AABBCC')).to be_nil }
69+
it { expect(described_class.check_mac('AA:BB:CC:DD')).to be_nil }
70+
it { expect(described_class.check_mac('AABBCCDD')).to be_nil }
71+
it { expect(described_class.check_mac('AA:BB:CC:DD:EE')).to be_nil }
72+
it { expect(described_class.check_mac('AABBCCDDEE')).to be_nil }
73+
it { expect(described_class.check_mac('AA:BB:CC:DD:EE:FF')).to be_nil }
74+
it { expect(described_class.check_mac('AABBCCDDEEFF')).to be_nil }
75+
end
76+
77+
context "when invalid mac" do
78+
it { expect { described_class.check_mac('AA') }.to raise_error }
79+
it { expect { described_class.check_mac('AA:BB:CC:DD:JJ') }.to raise_error }
80+
it { expect { described_class.check_mac('AA:BB') }.to raise_error }
81+
it { expect { described_class.check_mac('AABB') }.to raise_error }
82+
it { expect { described_class.check_mac('AA:BB:CC:DD:EE:FF:AA') }.to raise_error }
83+
it { expect { described_class.check_mac('AABBCCDDEEFFAA') }.to raise_error }
84+
end
85+
end
86+
end

0 commit comments

Comments
 (0)