1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-29 13:04:28 +01:00

Finished Dot11 tests.

This commit is contained in:
Matias Fontanini
2012-08-26 12:49:04 -03:00
parent ab9beab5bf
commit ba17ca3045
20 changed files with 934 additions and 203 deletions

103
tests/src/dot11/ack.cpp Normal file
View File

@@ -0,0 +1,103 @@
#include <gtest/gtest.h>
#include <algorithm>
#include <memory>
#include <stdint.h>
#include "dot11.h"
#include "tests/dot11.h"
using namespace std;
using namespace Tins;
typedef Dot11::address_type address_type;
class Dot11AckTest : public testing::Test {
public:
static const address_type empty_addr, hwaddr;
static const uint8_t expected_packet[];
};
const address_type Dot11AckTest::empty_addr;
const uint8_t Dot11AckTest::expected_packet[] = {
'\xd5', '\x01', 'O', '#', '\x00', '\x01', '\x02', '\x03', '\x04', '\x05'
};
void test_equals(const Dot11Ack &dot1, const Dot11Ack &dot2) {
test_equals(
static_cast<const Dot11&>(dot1),
static_cast<const Dot11&>(dot2)
);
}
void test_equals_expected(const Dot11Ack &dot11) {
EXPECT_EQ(dot11.protocol(), 1);
EXPECT_EQ(dot11.type(), Dot11::CONTROL);
EXPECT_EQ(dot11.subtype(), Dot11::ACK);
EXPECT_EQ(dot11.to_ds(), 1);
EXPECT_EQ(dot11.from_ds(), 0);
EXPECT_EQ(dot11.more_frag(), 0);
EXPECT_EQ(dot11.retry(), 0);
EXPECT_EQ(dot11.power_mgmt(), 0);
EXPECT_EQ(dot11.wep(), 0);
EXPECT_EQ(dot11.order(), 0);
EXPECT_EQ(dot11.duration_id(), 0x234f);
EXPECT_EQ(dot11.subtype(), Dot11::ACK);
EXPECT_EQ(dot11.addr1(), "00:01:02:03:04:05");
}
TEST_F(Dot11AckTest, Constructor) {
Dot11Ack dot11;
test_equals_empty(static_cast<const Dot11&>(dot11));
EXPECT_EQ(dot11.protocol(), 0);
EXPECT_EQ(dot11.type(), Dot11::CONTROL);
EXPECT_EQ(dot11.subtype(), Dot11::ACK);
EXPECT_EQ(dot11.to_ds(), 0);
EXPECT_EQ(dot11.from_ds(), 0);
EXPECT_EQ(dot11.more_frag(), 0);
EXPECT_EQ(dot11.retry(), 0);
EXPECT_EQ(dot11.power_mgmt(), 0);
EXPECT_EQ(dot11.wep(), 0);
EXPECT_EQ(dot11.order(), 0);
EXPECT_EQ(dot11.duration_id(), 0);
EXPECT_EQ(dot11.addr1(), empty_addr);
}
TEST_F(Dot11AckTest, ConstructorFromBuffer) {
Dot11Ack dot11(expected_packet, sizeof(expected_packet));
test_equals_expected(dot11);
}
TEST_F(Dot11AckTest, CopyConstructor) {
Dot11Ack dot1(expected_packet, sizeof(expected_packet));
Dot11Ack dot2(dot1);
test_equals(dot1, dot2);
}
TEST_F(Dot11AckTest, CopyAssignmentOperator) {
Dot11Ack dot1(expected_packet, sizeof(expected_packet));
Dot11Ack dot2;
dot2 = dot1;
test_equals(dot1, dot2);
}
TEST_F(Dot11AckTest, ClonePDU) {
Dot11Ack dot1(expected_packet, sizeof(expected_packet));
std::auto_ptr<Dot11Ack> dot2(dot1.clone_pdu());
test_equals(dot1, *dot2);
}
TEST_F(Dot11AckTest, FromBytes) {
std::auto_ptr<PDU> dot11(Dot11::from_bytes(expected_packet, sizeof(expected_packet)));
ASSERT_TRUE(dot11.get());
const Dot11Ack *inner = dot11->find_inner_pdu<Dot11Ack>();
ASSERT_TRUE(inner);
test_equals_expected(*inner);
}
TEST_F(Dot11AckTest, Serialize) {
Dot11Ack pdu(expected_packet, sizeof(expected_packet));
PDU::serialization_type buffer = pdu.serialize();
ASSERT_EQ(sizeof(expected_packet), buffer.size());
EXPECT_TRUE(std::equal(buffer.begin(), buffer.end(), expected_packet));
}

View File

@@ -65,6 +65,12 @@ TEST_F(Dot11AssocRequestTest, CopyAssignmentOperator) {
test_equals(dot1, dot2);
}
TEST_F(Dot11AssocRequestTest, ListenInterval) {
Dot11AssocRequest dot11;
dot11.listen_interval(0x92fd);
EXPECT_EQ(dot11.listen_interval(), 0x92fd);
}
TEST_F(Dot11AssocRequestTest, ClonePDU) {
Dot11AssocRequest dot1(expected_packet, sizeof(expected_packet));
std::auto_ptr<Dot11AssocRequest> dot2(dot1.clone_pdu());
@@ -79,3 +85,10 @@ TEST_F(Dot11AssocRequestTest, FromBytes) {
test_equals_expected(*inner);
}
TEST_F(Dot11AssocRequestTest, Serialize) {
Dot11AssocRequest pdu(expected_packet, sizeof(expected_packet));
PDU::serialization_type buffer = pdu.serialize();
ASSERT_EQ(sizeof(expected_packet), buffer.size());
EXPECT_TRUE(std::equal(buffer.begin(), buffer.end(), expected_packet));
}

View File

@@ -67,6 +67,18 @@ TEST_F(Dot11AssocResponseTest, CopyAssignmentOperator) {
test_equals(dot1, dot2);
}
TEST_F(Dot11AssocResponseTest, StatusCode) {
Dot11AssocResponse dot11;
dot11.status_code(0x92f3);
EXPECT_EQ(dot11.status_code(), 0x92f3);
}
TEST_F(Dot11AssocResponseTest, AID) {
Dot11AssocResponse dot11;
dot11.aid(0x92f3);
EXPECT_EQ(dot11.aid(), 0x92f3);
}
TEST_F(Dot11AssocResponseTest, ClonePDU) {
Dot11AssocResponse dot1(expected_packet, sizeof(expected_packet));
std::auto_ptr<Dot11AssocResponse> dot2(dot1.clone_pdu());
@@ -82,3 +94,10 @@ TEST_F(Dot11AssocResponseTest, FromBytes) {
test_equals_expected(*inner);
}
TEST_F(Dot11AssocResponseTest, Serialize) {
Dot11AssocResponse pdu(expected_packet, sizeof(expected_packet));
PDU::serialization_type buffer = pdu.serialize();
ASSERT_EQ(sizeof(expected_packet), buffer.size());
EXPECT_TRUE(std::equal(buffer.begin(), buffer.end(), expected_packet));
}

View File

@@ -69,6 +69,24 @@ TEST_F(Dot11AuthenticationTest, CopyAssignmentOperator) {
test_equals(dot1, dot2);
}
TEST_F(Dot11AuthenticationTest, StatusCode) {
Dot11Authentication dot11;
dot11.status_code(0x92f3);
EXPECT_EQ(dot11.status_code(), 0x92f3);
}
TEST_F(Dot11AuthenticationTest, AuthSequenceNumber) {
Dot11Authentication dot11;
dot11.auth_seq_number(0x92f3);
EXPECT_EQ(dot11.auth_seq_number(), 0x92f3);
}
TEST_F(Dot11AuthenticationTest, AuthAlgorithm) {
Dot11Authentication dot11;
dot11.auth_algorithm(0x92f3);
EXPECT_EQ(dot11.auth_algorithm(), 0x92f3);
}
TEST_F(Dot11AuthenticationTest, ClonePDU) {
Dot11Authentication dot1(expected_packet, sizeof(expected_packet));
std::auto_ptr<Dot11Authentication> dot2(dot1.clone_pdu());
@@ -83,3 +101,10 @@ TEST_F(Dot11AuthenticationTest, FromBytes) {
test_equals_expected(*inner);
}
TEST_F(Dot11AuthenticationTest, Serialize) {
Dot11Authentication pdu(expected_packet, sizeof(expected_packet));
PDU::serialization_type buffer = pdu.serialize();
ASSERT_EQ(sizeof(expected_packet), buffer.size());
EXPECT_TRUE(std::equal(buffer.begin(), buffer.end(), expected_packet));
}

View File

@@ -249,30 +249,30 @@ TEST_F(Dot11BeaconTest, Country) {
TEST_F(Dot11BeaconTest, FHParameters) {
Dot11Beacon dot11;
std::pair<uint8_t, uint8_t> data(0x42, 0x1f);
dot11.fh_parameters(data.first, data.second);
EXPECT_EQ(data, dot11.fh_parameters());
std::pair<uint8_t, uint8_t> tim(0x42, 0x1f);
dot11.fh_parameters(tim.first, tim.second);
EXPECT_EQ(tim, dot11.fh_parameters());
}
TEST_F(Dot11BeaconTest, FHPattern) {
Dot11Beacon dot11;
Dot11Beacon::fh_pattern_type data, output;
data.flag = 0x67;
data.number_of_sets = 0x42;
data.modulus = 0x1f;
data.offset = 0x3a;
data.random_table.push_back(23);
data.random_table.push_back(15);
data.random_table.push_back(129);
Dot11Beacon::fh_pattern_type tim, output;
tim.flag = 0x67;
tim.number_of_sets = 0x42;
tim.modulus = 0x1f;
tim.offset = 0x3a;
tim.random_table.push_back(23);
tim.random_table.push_back(15);
tim.random_table.push_back(129);
dot11.fh_pattern_table(data);
dot11.fh_pattern_table(tim);
output = dot11.fh_pattern_table();
EXPECT_EQ(data.flag, data.flag);
EXPECT_EQ(data.number_of_sets, data.number_of_sets);
EXPECT_EQ(data.modulus, data.modulus);
EXPECT_EQ(data.offset, data.offset);
EXPECT_EQ(data.random_table, data.random_table);
EXPECT_EQ(tim.flag, tim.flag);
EXPECT_EQ(tim.number_of_sets, tim.number_of_sets);
EXPECT_EQ(tim.modulus, tim.modulus);
EXPECT_EQ(tim.offset, tim.offset);
EXPECT_EQ(tim.random_table, tim.random_table);
}
TEST_F(Dot11BeaconTest, PowerConstraint) {
@@ -283,33 +283,33 @@ TEST_F(Dot11BeaconTest, PowerConstraint) {
TEST_F(Dot11BeaconTest, ChannelSwitch) {
Dot11Beacon dot11;
Dot11Beacon::channel_switch_type data(13, 42, 98), output;
dot11.channel_switch(data);
Dot11Beacon::channel_switch_type tim(13, 42, 98), output;
dot11.channel_switch(tim);
output = dot11.channel_switch();
EXPECT_EQ(output.switch_mode, data.switch_mode);
EXPECT_EQ(output.new_channel, data.new_channel);
EXPECT_EQ(output.switch_count, data.switch_count);
EXPECT_EQ(output.switch_mode, tim.switch_mode);
EXPECT_EQ(output.new_channel, tim.new_channel);
EXPECT_EQ(output.switch_count, tim.switch_count);
}
TEST_F(Dot11BeaconTest, Quiet) {
Dot11Beacon dot11;
Dot11Beacon::quiet_type data(13, 42, 0x928f, 0xf1ad), output;
dot11.quiet(data);
Dot11Beacon::quiet_type tim(13, 42, 0x928f, 0xf1ad), output;
dot11.quiet(tim);
output = dot11.quiet();
EXPECT_EQ(output.quiet_count, data.quiet_count);
EXPECT_EQ(output.quiet_period, data.quiet_period);
EXPECT_EQ(output.quiet_duration, data.quiet_duration);
EXPECT_EQ(output.quiet_offset, data.quiet_offset);
EXPECT_EQ(output.quiet_count, tim.quiet_count);
EXPECT_EQ(output.quiet_period, tim.quiet_period);
EXPECT_EQ(output.quiet_duration, tim.quiet_duration);
EXPECT_EQ(output.quiet_offset, tim.quiet_offset);
}
TEST_F(Dot11BeaconTest, TPCReport) {
Dot11Beacon dot11;
std::pair<uint8_t, uint8_t> data(42, 193);
dot11.tpc_report(data.first, data.second);
EXPECT_EQ(dot11.tpc_report(), data);
std::pair<uint8_t, uint8_t> tim(42, 193);
dot11.tpc_report(tim.first, tim.second);
EXPECT_EQ(dot11.tpc_report(), tim);
}
TEST_F(Dot11BeaconTest, ERPInformation) {
@@ -320,33 +320,33 @@ TEST_F(Dot11BeaconTest, ERPInformation) {
TEST_F(Dot11BeaconTest, BSSLoad) {
Dot11Beacon dot11;
Dot11Beacon::bss_load_type data(0x129f, 42, 0xf5a2), output;
dot11.bss_load(data);
Dot11Beacon::bss_load_type tim(0x129f, 42, 0xf5a2), output;
dot11.bss_load(tim);
output = dot11.bss_load();
EXPECT_EQ(data.station_count, output.station_count);
EXPECT_EQ(data.channel_utilization, output.channel_utilization);
EXPECT_EQ(data.available_capacity, output.available_capacity);
EXPECT_EQ(tim.station_count, output.station_count);
EXPECT_EQ(tim.channel_utilization, output.channel_utilization);
EXPECT_EQ(tim.available_capacity, output.available_capacity);
}
TEST_F(Dot11BeaconTest, TIM) {
Dot11Beacon dot11;
Dot11Beacon::tim_type data, output;
data.dtim_count = 42;
data.dtim_period = 59;
data.bitmap_control = 191;
Dot11Beacon::tim_type tim, output;
tim.dtim_count = 42;
tim.dtim_period = 59;
tim.bitmap_control = 191;
data.partial_virtual_bitmap.push_back(92);
data.partial_virtual_bitmap.push_back(182);
data.partial_virtual_bitmap.push_back(212);
tim.partial_virtual_bitmap.push_back(92);
tim.partial_virtual_bitmap.push_back(182);
tim.partial_virtual_bitmap.push_back(212);
dot11.tim(data);
dot11.tim(tim);
output = dot11.tim();
EXPECT_EQ(data.dtim_count, output.dtim_count);
EXPECT_EQ(data.dtim_period, output.dtim_period);
EXPECT_EQ(data.bitmap_control, output.bitmap_control);
EXPECT_EQ(data.partial_virtual_bitmap, output.partial_virtual_bitmap);
EXPECT_EQ(tim.dtim_count, output.dtim_count);
EXPECT_EQ(tim.dtim_period, output.dtim_period);
EXPECT_EQ(tim.bitmap_control, output.bitmap_control);
EXPECT_EQ(tim.partial_virtual_bitmap, output.partial_virtual_bitmap);
}
TEST_F(Dot11BeaconTest, ChallengeText) {
@@ -355,3 +355,63 @@ TEST_F(Dot11BeaconTest, ChallengeText) {
EXPECT_EQ(dot11.challenge_text(), "libtins ftw");
}
TEST_F(Dot11BeaconTest, PCAPLoad1) {
const uint8_t buffer[] = {
'\x80', '\x00', '\x00', '\x00', '\xff', '\xff', '\xff', '\xff',
'\xff', '\xff', '\xf4', '\xec', '8', '\xfe', 'M', '\x92', '\xf4',
'\xec', '8', '\xfe', 'M', '\x92', '\xe0', '\xea', '\x80', '\xd1',
'\xd4', '\xce', ',', '\x00', '\x00', '\x00', 'd', '\x00', '1',
'\x04', '\x00', '\x07', 'S', 'e', 'g', 'u', 'n', 'd', 'o', '\x01',
'\x08', '\x82', '\x84', '\x8b', '\x96', '\x0c', '\x12', '\x18', '$',
'\x03', '\x01', '\x01', '\x05', '\x04', '\x00', '\x01', '\x00',
'\x00', '\x07', '\x06', 'U', 'S', ' ', '\x01', '\r', '\x14', '*',
'\x01', '\x00', '0', '\x14', '\x01', '\x00', '\x00', '\x0f', '\xac',
'\x04', '\x01', '\x00', '\x00', '\x0f', '\xac', '\x04', '\x01',
'\x00', '\x00', '\x0f', '\xac', '\x02', '\x00', '\x00', '2', '\x04',
'0', 'H', '`', 'l', '\xdd', '\x18', '\x00', 'P', '\xf2', '\x02',
'\x01', '\x01', '\x03', '\x00', '\x03', '\xa4', '\x00', '\x00',
'\'', '\xa4', '\x00', '\x00', 'B', 'C', '^', '\x00', 'b', '2',
'/', '\x00', '\xdd', '\t', '\x00', '\x03', '\x7f', '\x01', '\x01',
'\x00', '\x00', '\xff', '\x7f'
};
typedef Dot11Beacon::country_params::container_type country_container;
Dot11Beacon dot11(buffer, sizeof(buffer));
float rates[] = { 1.0f, 2.0f, 5.5f, 11.0f, 6.0f, 9.0f, 12.0f, 18.0f},
ext_rates[] = { 24.0f, 36.0f, 48.0f, 54.0f };
Dot11Beacon::rates_type rates_parsed = dot11.supported_rates();
Dot11Beacon::rates_type ext_rates_parsed = dot11.extended_supported_rates();
Dot11Beacon::tim_type tim(0, 1, 0, Dot11Beacon::tim_type::container_type(1)),
tim_parsed = dot11.tim();
Dot11Beacon::country_params country("US ",
country_container(1, 1),
country_container(1, 13),
country_container(1, 20)),
country_parsed = dot11.country();
EXPECT_EQ(dot11.ssid(), "Segundo");
ASSERT_EQ(rates_parsed.size(), sizeof(rates) / sizeof(float));
EXPECT_TRUE(std::equal(rates_parsed.begin(), rates_parsed.end(), rates));
ASSERT_EQ(ext_rates_parsed.size(), sizeof(ext_rates) / sizeof(float));
EXPECT_TRUE(std::equal(ext_rates_parsed.begin(), ext_rates_parsed.end(), ext_rates));
EXPECT_EQ(1, dot11.ds_parameter_set());
EXPECT_EQ(tim.dtim_count, tim_parsed.dtim_count);
EXPECT_EQ(tim.dtim_period, tim_parsed.dtim_period);
EXPECT_EQ(tim.bitmap_control, tim_parsed.bitmap_control);
EXPECT_EQ(tim.partial_virtual_bitmap, tim_parsed.partial_virtual_bitmap);
EXPECT_EQ(country.country, country_parsed.country);
EXPECT_EQ(country.first_channel, country_parsed.first_channel);
EXPECT_EQ(country.number_channels, country_parsed.number_channels);
EXPECT_EQ(country.max_transmit_power, country_parsed.max_transmit_power);
EXPECT_EQ(dot11.erp_information(), 0);
PDU::serialization_type serialized = dot11.serialize();
ASSERT_EQ(sizeof(buffer), serialized.size());
EXPECT_TRUE(std::equal(serialized.begin(), serialized.end(), buffer));
}
TEST_F(Dot11BeaconTest, Serialize) {
Dot11Beacon pdu(expected_packet, sizeof(expected_packet));
PDU::serialization_type buffer = pdu.serialize();
ASSERT_EQ(sizeof(expected_packet), buffer.size());
EXPECT_TRUE(std::equal(buffer.begin(), buffer.end(), expected_packet));
}

View File

@@ -0,0 +1,98 @@
#include <gtest/gtest.h>
#include <algorithm>
#include <memory>
#include <stdint.h>
#include "dot11.h"
#include "tests/dot11.h"
/* PLZ PLZ I need some BLOCK ACK REQUEST packet dump,
* in order to check the constructor from buffer.
*/
using namespace std;
using namespace Tins;
typedef Dot11::address_type address_type;
class Dot11BlockAckRequestTest : public testing::Test {
public:
static const address_type empty_addr, hwaddr;
static const uint8_t expected_packet[];
};
/*const uint8_t Dot11BlockAckRequestTest::expected_packet[] = {
'\x00', '\x00', ' ', '\x00', 'o', 'H', '\x00', '\x00', 's', 'H', '\xbf', '4', '\x00', '\x00', '\x00', '\x00', '\x10', '\x02', 'l', '\t', '\xdf', '\x00', '\xdc', '\xe0', '\x01', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\xfb', '\x00', '\xcf', '\x01', '\x00', '!', 'k', '\x02', '\xe5', '\x99', '\x00', '\x1c', '\xa0', '\xa8', '\r', 'U', '\x04', '\x00', '\xcf', '!', '\xc7', '\xf3', '\x00', ';'
};*/
void test_equals(const Dot11BlockAckRequest &dot1, const Dot11BlockAckRequest &dot2) {
EXPECT_EQ(dot1.fragment_number(), dot2.fragment_number());
EXPECT_EQ(dot1.start_sequence(), dot2.start_sequence());
EXPECT_EQ(dot1.bar_control(), dot2.bar_control());
}
void test_equals_expected(const Dot11BlockAckRequest &dot11) {
EXPECT_EQ(dot11.type(), Dot11::CONTROL);
EXPECT_EQ(dot11.subtype(), Dot11::BLOCK_ACK_REQ);
EXPECT_EQ(dot11.fragment_number(), 6);
EXPECT_EQ(dot11.start_sequence(), 0x294);
EXPECT_EQ(dot11.bar_control(), 0x92f);
}
TEST_F(Dot11BlockAckRequestTest, Constructor) {
Dot11BlockAckRequest dot11;
test_equals_empty(static_cast<const Dot11ControlTA&>(dot11));
EXPECT_EQ(dot11.subtype(), Dot11::BLOCK_ACK_REQ);
EXPECT_EQ(dot11.fragment_number(), 0);
EXPECT_EQ(dot11.start_sequence(), 0);
EXPECT_EQ(dot11.bar_control(), 0);
}
/*TEST_F(Dot11BlockAckRequestTest, ConstructorFromBuffer) {
Dot11BlockAckRequest dot11(expected_packet, sizeof(expected_packet));
test_equals_expected(dot11);
}*/
TEST_F(Dot11BlockAckRequestTest, CopyConstructor) {
Dot11BlockAckRequest dot1;
dot1.fragment_number(6);
dot1.start_sequence(0x294);
dot1.bar_control(0x92f);
Dot11BlockAckRequest dot2(dot1);
test_equals(dot1, dot2);
}
TEST_F(Dot11BlockAckRequestTest, CopyAssignmentOperator) {
Dot11BlockAckRequest dot1;
dot1.fragment_number(6);
dot1.start_sequence(0x294);
dot1.bar_control(0x92f);
Dot11BlockAckRequest dot2;
dot2 = dot1;
test_equals(dot1, dot2);
}
TEST_F(Dot11BlockAckRequestTest, ClonePDU) {
Dot11BlockAckRequest dot1;
dot1.fragment_number(6);
dot1.start_sequence(0x294);
dot1.bar_control(0x92f);
std::auto_ptr<Dot11BlockAckRequest> dot2(dot1.clone_pdu());
test_equals(dot1, *dot2);
}
/*TEST_F(Dot11BlockAckRequestTest, FromBytes) {
std::auto_ptr<PDU> dot11(Dot11::from_bytes(expected_packet, sizeof(expected_packet)));
ASSERT_TRUE(dot11.get());
const Dot11BlockAckRequest *inner = dot11->find_inner_pdu<Dot11BlockAckRequest>();
ASSERT_TRUE(inner);
test_equals_expected(*inner);
}*/
/*TEST_F(Dot11BlockAckRequestTest, Serialize) {
Dot11BlockAckRequest pdu(expected_packet, sizeof(expected_packet));
PDU::serialization_type buffer = pdu.serialize();
ASSERT_EQ(sizeof(expected_packet), buffer.size());
EXPECT_TRUE(std::equal(buffer.begin(), buffer.end(), expected_packet));
}*/

80
tests/src/dot11/cfend.cpp Normal file
View File

@@ -0,0 +1,80 @@
#include <gtest/gtest.h>
#include <algorithm>
#include <memory>
#include <stdint.h>
#include "dot11.h"
#include "tests/dot11.h"
using namespace std;
using namespace Tins;
typedef Dot11::address_type address_type;
class Dot11CFEndTest : public testing::Test {
public:
static const address_type empty_addr, hwaddr;
static const uint8_t expected_packet[];
};
const uint8_t Dot11CFEndTest::expected_packet[] = {
'\xe5', '\x01', 'O', '#', '\x00', '\x01', '\x02', '\x03', '\x04',
'\x05', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06'
};
void test_equals(const Dot11CFEnd &dot1, const Dot11CFEnd &dot2) {
test_equals(
static_cast<const Dot11ControlTA&>(dot1),
static_cast<const Dot11ControlTA&>(dot2)
);
}
void test_equals_expected(const Dot11CFEnd &dot11) {
test_equals_expected(static_cast<const Dot11ControlTA&>(dot11));
EXPECT_EQ(dot11.subtype(), Dot11::CF_END);
}
TEST_F(Dot11CFEndTest, Constructor) {
Dot11CFEnd dot11;
test_equals_empty(static_cast<const Dot11ControlTA&>(dot11));
EXPECT_EQ(dot11.subtype(), Dot11::CF_END);
}
TEST_F(Dot11CFEndTest, ConstructorFromBuffer) {
Dot11CFEnd dot11(expected_packet, sizeof(expected_packet));
test_equals_expected(dot11);
}
TEST_F(Dot11CFEndTest, CopyConstructor) {
Dot11CFEnd dot1(expected_packet, sizeof(expected_packet));
Dot11CFEnd dot2(dot1);
test_equals(dot1, dot2);
}
TEST_F(Dot11CFEndTest, CopyAssignmentOperator) {
Dot11CFEnd dot1(expected_packet, sizeof(expected_packet));
Dot11CFEnd dot2;
dot2 = dot1;
test_equals(dot1, dot2);
}
TEST_F(Dot11CFEndTest, ClonePDU) {
Dot11CFEnd dot1(expected_packet, sizeof(expected_packet));
std::auto_ptr<Dot11CFEnd> dot2(dot1.clone_pdu());
test_equals(dot1, *dot2);
}
TEST_F(Dot11CFEndTest, FromBytes) {
std::auto_ptr<PDU> dot11(Dot11::from_bytes(expected_packet, sizeof(expected_packet)));
ASSERT_TRUE(dot11.get());
const Dot11CFEnd *inner = dot11->find_inner_pdu<Dot11CFEnd>();
ASSERT_TRUE(inner);
test_equals_expected(*inner);
}
TEST_F(Dot11CFEndTest, Serialize) {
Dot11CFEnd pdu(expected_packet, sizeof(expected_packet));
PDU::serialization_type buffer = pdu.serialize();
ASSERT_EQ(sizeof(expected_packet), buffer.size());
EXPECT_TRUE(std::equal(buffer.begin(), buffer.end(), expected_packet));
}

View File

@@ -0,0 +1,81 @@
#include <gtest/gtest.h>
#include <algorithm>
#include <memory>
#include <stdint.h>
#include "dot11.h"
#include "tests/dot11.h"
using namespace std;
using namespace Tins;
typedef Dot11::address_type address_type;
class Dot11EndCFAckTest : public testing::Test {
public:
static const address_type empty_addr, hwaddr;
static const uint8_t expected_packet[];
};
const uint8_t Dot11EndCFAckTest::expected_packet[] = {
'\xf5', '\x01', 'O', '#', '\x00', '\x01', '\x02', '\x03', '\x04',
'\x05', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06'
};
void test_equals(const Dot11EndCFAck &dot1, const Dot11EndCFAck &dot2) {
test_equals(
static_cast<const Dot11ControlTA&>(dot1),
static_cast<const Dot11ControlTA&>(dot2)
);
}
void test_equals_expected(const Dot11EndCFAck &dot11) {
test_equals_expected(static_cast<const Dot11ControlTA&>(dot11));
EXPECT_EQ(dot11.subtype(), Dot11::CF_END_ACK);
}
TEST_F(Dot11EndCFAckTest, Constructor) {
Dot11EndCFAck dot11;
test_equals_empty(static_cast<const Dot11ControlTA&>(dot11));
EXPECT_EQ(dot11.subtype(), Dot11::CF_END_ACK);
}
TEST_F(Dot11EndCFAckTest, ConstructorFromBuffer) {
Dot11EndCFAck dot11(expected_packet, sizeof(expected_packet));
test_equals_expected(dot11);
}
TEST_F(Dot11EndCFAckTest, CopyConstructor) {
Dot11EndCFAck dot1(expected_packet, sizeof(expected_packet));
Dot11EndCFAck dot2(dot1);
test_equals(dot1, dot2);
}
TEST_F(Dot11EndCFAckTest, CopyAssignmentOperator) {
Dot11EndCFAck dot1(expected_packet, sizeof(expected_packet));
Dot11EndCFAck dot2;
dot2 = dot1;
test_equals(dot1, dot2);
}
TEST_F(Dot11EndCFAckTest, ClonePDU) {
Dot11EndCFAck dot1(expected_packet, sizeof(expected_packet));
std::auto_ptr<Dot11EndCFAck> dot2(dot1.clone_pdu());
test_equals(dot1, *dot2);
}
TEST_F(Dot11EndCFAckTest, FromBytes) {
std::auto_ptr<PDU> dot11(Dot11::from_bytes(expected_packet, sizeof(expected_packet)));
ASSERT_TRUE(dot11.get());
const Dot11EndCFAck *inner = dot11->find_inner_pdu<Dot11EndCFAck>();
ASSERT_TRUE(inner);
test_equals_expected(*inner);
}
TEST_F(Dot11EndCFAckTest, Serialize) {
Dot11EndCFAck pdu(expected_packet, sizeof(expected_packet));
PDU::serialization_type buffer = pdu.serialize();
ASSERT_EQ(sizeof(expected_packet), buffer.size());
EXPECT_TRUE(std::equal(buffer.begin(), buffer.end(), expected_packet));
}

View File

@@ -20,7 +20,7 @@ public:
const uint8_t Dot11DataTest::expected_packet[] = {
'\t', '\x00', 'O', '#', '\x00', '\x01', '\x02', '\x03', '\x04',
'\x05', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06', '\x02',
'\x03', '\x04', '\x05', '\x06', '\x07', '\x00', '\x00'
'\x03', '\x04', '\x05', '\x06', '\x07', '\xda', '\xf1'
};
TEST_F(Dot11DataTest, Constructor) {
@@ -61,3 +61,41 @@ TEST_F(Dot11DataTest, FromBytes) {
test_equals_expected(*inner);
}
TEST_F(Dot11DataTest, PCAPLoad1) {
const uint8_t buffer[] = {
'\x08', 'B', '\xd4', '\x00', '\x00', '$', '!', '\x92', '\xa7',
'S', '\x00', '\x1b', '\x11', '\xd2', '\x1b', '\xeb', '\x00',
'\x1b', '\x11', '\xd2', '\x1b', '\xeb', '\x90', 'y', '\xa3',
'_', '\x00', ' ', '\x00', '\x00', '\x00', '\x00', '\xf0', '\xef',
'\xb5', '\xf9', '4', '\xcb', '\x00', ',', 'D', '\xe4', '\xba',
'"', '\xa7', '/', '/', 'G', '\x04', '\xd5', 'o', 'N', '\xeb',
'6', '[', '\xc3', 'D', 't', 'y', '\xec', '\x84', '\xf2', '`',
' ', 'X', '\x1e', 'p', '\xa2', 'z', '\x02', '\x1a', '7', '\xd2',
'\xf2', '\n', '\x1c', '\xc7', 'z', 'D', '\xc4', '\xc4', '\xbc',
'G', '_', '\x9f', '\xcf', '\xbc', '\xa2', '\xb7', '\xaf', '\xed',
'\xe0', '\xcc', '\xb9', '\x9e', '\x94', ' ', '\xee', 'F', '\x89',
'1', '\xab', '\xe7', '\xb8', 'I', '\xaf', '\xc3', '\xf4', '\xc5',
'\x95', '\x1c', '\x8d', '\x1a', '\xf8', ':', '\xbd', '\x95',
'\xbf', 'y', '\xce', '\xda', 'x', 's', '@', '\xe0', '>', '\xa1',
'B', '\x94', '\xd9', '\xb1', '\xa6', '\x17', '\xee', '\xb4',
'\x95', 'E'
};
Dot11Data dot1(buffer, sizeof(buffer));
EXPECT_EQ(dot1.addr1(), "00:24:21:92:a7:53");
EXPECT_EQ(dot1.addr2(), "00:1b:11:d2:1b:eb");
EXPECT_EQ(dot1.addr3(), "00:1b:11:d2:1b:eb");
EXPECT_EQ(dot1.wep(), 1);
EXPECT_EQ(dot1.from_ds(), 1);
EXPECT_EQ(dot1.frag_num(), 0);
EXPECT_EQ(dot1.seq_num(), 1945);
std::auto_ptr<Dot11Data> dot2(dot1.clone_pdu());
test_equals(dot1, *dot2);
}
TEST_F(Dot11DataTest, Serialize) {
Dot11Data pdu(expected_packet, sizeof(expected_packet));
PDU::serialization_type buffer = pdu.serialize();
ASSERT_EQ(sizeof(expected_packet), buffer.size());
EXPECT_TRUE(std::equal(buffer.begin(), buffer.end(), expected_packet));
}

View File

@@ -63,6 +63,12 @@ TEST_F(Dot11DeauthenticationTest, CopyAssignmentOperator) {
test_equals(dot1, dot2);
}
TEST_F(Dot11DeauthenticationTest, ReasonCode) {
Dot11Deauthentication dot11;
dot11.reason_code(0x92f3);
EXPECT_EQ(dot11.reason_code(), 0x92f3);
}
TEST_F(Dot11DeauthenticationTest, ClonePDU) {
Dot11Deauthentication dot1(expected_packet, sizeof(expected_packet));
std::auto_ptr<Dot11Deauthentication> dot2(dot1.clone_pdu());
@@ -77,3 +83,10 @@ TEST_F(Dot11DeauthenticationTest, FromBytes) {
test_equals_expected(*inner);
}
TEST_F(Dot11DeauthenticationTest, Serialize) {
Dot11Deauthentication pdu(expected_packet, sizeof(expected_packet));
PDU::serialization_type buffer = pdu.serialize();
ASSERT_EQ(sizeof(expected_packet), buffer.size());
EXPECT_TRUE(std::equal(buffer.begin(), buffer.end(), expected_packet));
}

View File

@@ -63,6 +63,12 @@ TEST_F(Dot11DisassocTest, CopyAssignmentOperator) {
test_equals(dot1, dot2);
}
TEST_F(Dot11DisassocTest, ReasonCode) {
Dot11Disassoc dot11;
dot11.reason_code(0x92f3);
EXPECT_EQ(dot11.reason_code(), 0x92f3);
}
TEST_F(Dot11DisassocTest, ClonePDU) {
Dot11Disassoc dot1(expected_packet, sizeof(expected_packet));
std::auto_ptr<Dot11Disassoc> dot2(dot1.clone_pdu());
@@ -76,3 +82,10 @@ TEST_F(Dot11DisassocTest, FromBytes) {
ASSERT_TRUE(inner);
test_equals_expected(*inner);
}
TEST_F(Dot11DisassocTest, Serialize) {
Dot11Disassoc pdu(expected_packet, sizeof(expected_packet));
PDU::serialization_type buffer = pdu.serialize();
ASSERT_EQ(sizeof(expected_packet), buffer.size());
EXPECT_TRUE(std::equal(buffer.begin(), buffer.end(), expected_packet));
}

View File

@@ -159,5 +159,11 @@ TEST_F(Dot11Test, AddTaggedOption) {
EXPECT_TRUE(std::equal(hwaddr.begin(), hwaddr.end(), option->data_ptr()));
}
TEST_F(Dot11Test, Serialize) {
Dot11 pdu(expected_packet, sizeof(expected_packet));
PDU::serialization_type buffer = pdu.serialize();
ASSERT_EQ(sizeof(expected_packet), buffer.size());
EXPECT_TRUE(std::equal(buffer.begin(), buffer.end(), expected_packet));
}

View File

@@ -67,6 +67,18 @@ TEST_F(Dot11ProbeResponseTest, CopyAssignmentOperator) {
test_equals(dot1, dot2);
}
TEST_F(Dot11ProbeResponseTest, Interval) {
Dot11ProbeResponse dot11;
dot11.interval(0x92af);
EXPECT_EQ(dot11.interval(), 0x92af);
}
TEST_F(Dot11ProbeResponseTest, Timestamp) {
Dot11ProbeResponse dot11;
dot11.timestamp(0x92af8a72df928a7c);
EXPECT_EQ(dot11.timestamp(), 0x92af8a72df928a7c);
}
TEST_F(Dot11ProbeResponseTest, ClonePDU) {
Dot11ProbeResponse dot1(expected_packet, sizeof(expected_packet));
std::auto_ptr<Dot11ProbeResponse> dot2(dot1.clone_pdu());
@@ -81,3 +93,9 @@ TEST_F(Dot11ProbeResponseTest, FromBytes) {
test_equals_expected(*inner);
}
TEST_F(Dot11ProbeResponseTest, Serialize) {
Dot11ProbeResponse pdu(expected_packet, sizeof(expected_packet));
PDU::serialization_type buffer = pdu.serialize();
ASSERT_EQ(sizeof(expected_packet), buffer.size());
EXPECT_TRUE(std::equal(buffer.begin(), buffer.end(), expected_packet));
}

View File

@@ -0,0 +1,80 @@
#include <gtest/gtest.h>
#include <algorithm>
#include <memory>
#include <stdint.h>
#include "dot11.h"
#include "tests/dot11.h"
using namespace std;
using namespace Tins;
typedef Dot11::address_type address_type;
class Dot11PSPollTest : public testing::Test {
public:
static const address_type empty_addr, hwaddr;
static const uint8_t expected_packet[];
};
const uint8_t Dot11PSPollTest::expected_packet[] = {
'\xa5', '\x01', 'O', '#', '\x00', '\x01', '\x02', '\x03', '\x04',
'\x05', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06'
};
void test_equals(const Dot11PSPoll &dot1, const Dot11PSPoll &dot2) {
test_equals(
static_cast<const Dot11ControlTA&>(dot1),
static_cast<const Dot11ControlTA&>(dot2)
);
}
void test_equals_expected(const Dot11PSPoll &dot11) {
test_equals_expected(static_cast<const Dot11ControlTA&>(dot11));
EXPECT_EQ(dot11.subtype(), Dot11::PS);
}
TEST_F(Dot11PSPollTest, Constructor) {
Dot11PSPoll dot11;
test_equals_empty(static_cast<const Dot11ControlTA&>(dot11));
EXPECT_EQ(dot11.subtype(), Dot11::PS);
}
TEST_F(Dot11PSPollTest, ConstructorFromBuffer) {
Dot11PSPoll dot11(expected_packet, sizeof(expected_packet));
test_equals_expected(dot11);
}
TEST_F(Dot11PSPollTest, CopyConstructor) {
Dot11PSPoll dot1(expected_packet, sizeof(expected_packet));
Dot11PSPoll dot2(dot1);
test_equals(dot1, dot2);
}
TEST_F(Dot11PSPollTest, CopyAssignmentOperator) {
Dot11PSPoll dot1(expected_packet, sizeof(expected_packet));
Dot11PSPoll dot2;
dot2 = dot1;
test_equals(dot1, dot2);
}
TEST_F(Dot11PSPollTest, ClonePDU) {
Dot11PSPoll dot1(expected_packet, sizeof(expected_packet));
std::auto_ptr<Dot11PSPoll> dot2(dot1.clone_pdu());
test_equals(dot1, *dot2);
}
TEST_F(Dot11PSPollTest, FromBytes) {
std::auto_ptr<PDU> dot11(Dot11::from_bytes(expected_packet, sizeof(expected_packet)));
ASSERT_TRUE(dot11.get());
const Dot11PSPoll *inner = dot11->find_inner_pdu<Dot11PSPoll>();
ASSERT_TRUE(inner);
test_equals_expected(*inner);
}
TEST_F(Dot11PSPollTest, Serialize) {
Dot11PSPoll pdu(expected_packet, sizeof(expected_packet));
PDU::serialization_type buffer = pdu.serialize();
ASSERT_EQ(sizeof(expected_packet), buffer.size());
EXPECT_TRUE(std::equal(buffer.begin(), buffer.end(), expected_packet));
}

View File

@@ -66,6 +66,18 @@ TEST_F(Dot11ReAssocRequestTest, CopyAssignmentOperator) {
test_equals(dot1, dot2);
}
TEST_F(Dot11ReAssocRequestTest, ListenInterval) {
Dot11ReAssocRequest dot11;
dot11.listen_interval(0x92fd);
EXPECT_EQ(dot11.listen_interval(), 0x92fd);
}
TEST_F(Dot11ReAssocRequestTest, CurrentAP) {
Dot11ReAssocRequest dot11;
dot11.current_ap("00:01:02:03:04:05");
EXPECT_EQ(dot11.current_ap(), "00:01:02:03:04:05");
}
TEST_F(Dot11ReAssocRequestTest, ClonePDU) {
Dot11ReAssocRequest dot1(expected_packet, sizeof(expected_packet));
std::auto_ptr<Dot11ReAssocRequest> dot2(dot1.clone_pdu());
@@ -80,3 +92,9 @@ TEST_F(Dot11ReAssocRequestTest, FromBytes) {
test_equals_expected(*inner);
}
TEST_F(Dot11ReAssocRequestTest, Serialize) {
Dot11ReAssocRequest pdu(expected_packet, sizeof(expected_packet));
PDU::serialization_type buffer = pdu.serialize();
ASSERT_EQ(sizeof(expected_packet), buffer.size());
EXPECT_TRUE(std::equal(buffer.begin(), buffer.end(), expected_packet));
}

View File

@@ -81,3 +81,10 @@ TEST_F(Dot11ReAssocResponseTest, FromBytes) {
test_equals_expected(*inner);
}
TEST_F(Dot11ReAssocResponseTest, Serialize) {
Dot11ReAssocResponse pdu(expected_packet, sizeof(expected_packet));
PDU::serialization_type buffer = pdu.serialize();
ASSERT_EQ(sizeof(expected_packet), buffer.size());
EXPECT_TRUE(std::equal(buffer.begin(), buffer.end(), expected_packet));
}

80
tests/src/dot11/rts.cpp Normal file
View File

@@ -0,0 +1,80 @@
#include <gtest/gtest.h>
#include <algorithm>
#include <memory>
#include <stdint.h>
#include "dot11.h"
#include "tests/dot11.h"
using namespace std;
using namespace Tins;
typedef Dot11::address_type address_type;
class Dot11RTSTest : public testing::Test {
public:
static const address_type empty_addr, hwaddr;
static const uint8_t expected_packet[];
};
const uint8_t Dot11RTSTest::expected_packet[] = {
'\xb5', '\x01', 'O', '#', '\x00', '\x01', '\x02', '\x03', '\x04',
'\x05', '\x01', '\x02', '\x03', '\x04', '\x05', '\x06'
};
void test_equals(const Dot11RTS &dot1, const Dot11RTS &dot2) {
test_equals(
static_cast<const Dot11ControlTA&>(dot1),
static_cast<const Dot11ControlTA&>(dot2)
);
}
void test_equals_expected(const Dot11RTS &dot11) {
test_equals_expected(static_cast<const Dot11ControlTA&>(dot11));
EXPECT_EQ(dot11.subtype(), Dot11::RTS);
}
TEST_F(Dot11RTSTest, Constructor) {
Dot11RTS dot11;
test_equals_empty(static_cast<const Dot11ControlTA&>(dot11));
EXPECT_EQ(dot11.subtype(), Dot11::RTS);
}
TEST_F(Dot11RTSTest, ConstructorFromBuffer) {
Dot11RTS dot11(expected_packet, sizeof(expected_packet));
test_equals_expected(dot11);
}
TEST_F(Dot11RTSTest, CopyConstructor) {
Dot11RTS dot1(expected_packet, sizeof(expected_packet));
Dot11RTS dot2(dot1);
test_equals(dot1, dot2);
}
TEST_F(Dot11RTSTest, CopyAssignmentOperator) {
Dot11RTS dot1(expected_packet, sizeof(expected_packet));
Dot11RTS dot2;
dot2 = dot1;
test_equals(dot1, dot2);
}
TEST_F(Dot11RTSTest, ClonePDU) {
Dot11RTS dot1(expected_packet, sizeof(expected_packet));
std::auto_ptr<Dot11RTS> dot2(dot1.clone_pdu());
test_equals(dot1, *dot2);
}
TEST_F(Dot11RTSTest, FromBytes) {
std::auto_ptr<PDU> dot11(Dot11::from_bytes(expected_packet, sizeof(expected_packet)));
ASSERT_TRUE(dot11.get());
const Dot11RTS *inner = dot11->find_inner_pdu<Dot11RTS>();
ASSERT_TRUE(inner);
test_equals_expected(*inner);
}
TEST_F(Dot11RTSTest, Serialize) {
Dot11RTS pdu(expected_packet, sizeof(expected_packet));
PDU::serialization_type buffer = pdu.serialize();
ASSERT_EQ(sizeof(expected_packet), buffer.size());
EXPECT_TRUE(std::equal(buffer.begin(), buffer.end(), expected_packet));
}