CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

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