Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/spec/lib/rex/mac_oui_spec.rb
Views: 11779
# -*- coding:binary -*-1require 'spec_helper'23RSpec.describe Rex::Oui do4describe ".lookup_oui_fullname" do5subject(:oui_fullname) { described_class.lookup_oui_fullname(mac) }67context "when valid mac for OUI with name" do8let(:mac) { '000011' }9let(:name) { 'Tektrnix' }10it { is_expected.to eq(name) }11end1213context "when valid mac for OUI with name and long name" do14let(:mac) { '00:00:0E:12:34:56' }15let(:name) { 'Fujitsu' }16let(:long_name) { 'FUJITSU LIMITED' }17it { is_expected.to eq("#{name} / #{long_name}") }18end1920context "when valid mac format, without OUI" do21let(:mac) { '11:22:33:44:55:66'}22it { is_expected.to eq('UNKNOWN') }23end2425context "when invalid mac format" do26let(:mac) { 'invalid' }27it "raises an error" do28expect { oui_fullname }.to raise_error(RuntimeError)29end30end31end3233describe ".lookup_oui_company_name" do34subject(:oui_company_name) { described_class.lookup_oui_company_name(mac) }3536context "when valid mac for OUI with name" do37let(:mac) { '000011' }38let(:name) { 'Tektrnix' }39it { is_expected.to eq(name) }40end4142context "when valid mac for OUI with name and long name" do43let(:mac) { '00:00:0E:12:34:56' }44let(:name) { 'Fujitsu' }45let(:long_name) { 'FUJITSU LIMITED' }46it { is_expected.to eq(long_name) }47end4849context "when valid mac format, without OUI" do50let(:mac) { '11:22:33:44:55:66'}51it { is_expected.to eq('UNKNOWN') }52end5354context "when invalid mac format" do55let(:mac) { 'invalid' }56it "raises an error" do57expect { oui_company_name }.to raise_error(RuntimeError)58end59end60end6162describe ".check_mac" do63context "when valid mac" do64it { expect(described_class.check_mac('AA:BB:CC')).to be_nil }65it { expect(described_class.check_mac('AABBCC')).to be_nil }66it { expect(described_class.check_mac('AA:BB:CC:DD')).to be_nil }67it { expect(described_class.check_mac('AABBCCDD')).to be_nil }68it { expect(described_class.check_mac('AA:BB:CC:DD:EE')).to be_nil }69it { expect(described_class.check_mac('AABBCCDDEE')).to be_nil }70it { expect(described_class.check_mac('AA:BB:CC:DD:EE:FF')).to be_nil }71it { expect(described_class.check_mac('AABBCCDDEEFF')).to be_nil }72end7374context "when invalid mac" do75it { expect { described_class.check_mac('AA') }.to raise_error(RuntimeError) }76it { expect { described_class.check_mac('AA:BB:CC:DD:JJ') }.to raise_error(RuntimeError) }77it { expect { described_class.check_mac('AA:BB') }.to raise_error(RuntimeError) }78it { expect { described_class.check_mac('AABB') }.to raise_error(RuntimeError) }79it { expect { described_class.check_mac('AA:BB:CC:DD:EE:FF:AA') }.to raise_error(RuntimeError) }80it { expect { described_class.check_mac('AABBCCDDEEFFAA') }.to raise_error(RuntimeError) }81end82end83end848586