diff --git a/include/radproto/attribute.h b/include/radproto/attribute.h index 0bd8777..b00410a 100644 --- a/include/radproto/attribute.h +++ b/include/radproto/attribute.h @@ -10,21 +10,21 @@ namespace RadProto class Attribute { public: - Attribute(uint8_t type); + Attribute(uint8_t code); virtual ~Attribute() = default; - uint8_t type() const { return m_type; } + uint8_t code() const { return m_code; } virtual std::string toString() const = 0; virtual std::vector toVector(const std::string& secret, const std::array& auth) const = 0; virtual Attribute* clone() const = 0; private: - uint8_t m_type; + uint8_t m_code; }; class String: public Attribute { public: - String(uint8_t type, const uint8_t* data, size_t size); - String(uint8_t type, const std::string& string); + String(uint8_t code, const uint8_t* data, size_t size); + String(uint8_t code, const std::string& string); std::string toString() const override { return m_value; } std::vector toVector(const std::string& secret, const std::array& auth) const override; String* clone() const override; @@ -35,8 +35,8 @@ namespace RadProto class Integer: public Attribute { public: - Integer(uint8_t type, const uint8_t* data, size_t size); - Integer(uint8_t type, uint32_t value); + Integer(uint8_t code, const uint8_t* data, size_t size); + Integer(uint8_t code, uint32_t value); std::string toString() const override; std::vector toVector(const std::string& secret, const std::array& auth) const override; Integer* clone() const override; @@ -47,8 +47,8 @@ namespace RadProto class IpAddress : public Attribute { public: - IpAddress(uint8_t type, const uint8_t* data, size_t size); - IpAddress(uint8_t type, const std::array& address); + IpAddress(uint8_t code, const uint8_t* data, size_t size); + IpAddress(uint8_t code, const std::array& address); std::string toString() const override; std::vector toVector(const std::string& secret, const std::array& auth) const override; IpAddress* clone() const override; @@ -59,8 +59,8 @@ namespace RadProto class Encrypted : public Attribute { public: - Encrypted (uint8_t type, const uint8_t* data, size_t size, const std::string& secret, const std::array& auth); - Encrypted(uint8_t type, const std::string& password); + Encrypted (uint8_t code, const uint8_t* data, size_t size, const std::string& secret, const std::array& auth); + Encrypted(uint8_t code, const std::string& password); std::string toString() const override { return m_value; } std::vector toVector(const std::string& secret, const std::array& auth) const override; Encrypted* clone() const override; @@ -71,8 +71,8 @@ namespace RadProto class Bytes: public Attribute { public: - Bytes(uint8_t type, const uint8_t* data, size_t size); - Bytes(uint8_t type, const std::vector& bytes); + Bytes(uint8_t code, const uint8_t* data, size_t size); + Bytes(uint8_t code, const std::vector& bytes); std::string toString() const override; std::vector toVector(const std::string& secret, const std::array& auth) const override; Bytes* clone() const override; @@ -83,8 +83,8 @@ namespace RadProto class ChapPassword: public Attribute { public: - ChapPassword(uint8_t type, const uint8_t* data, size_t size); - ChapPassword(uint8_t type, uint8_t chapId, const std::vector& chapValue); + ChapPassword(uint8_t code, const uint8_t* data, size_t size); + ChapPassword(uint8_t code, uint8_t chapId, const std::vector& chapValue); std::string toString() const override; uint8_t chapId() const { return m_chapId; } std::vector chapValue() const { return m_value; } diff --git a/include/radproto/attribute_types.h b/include/radproto/attribute_codes.h similarity index 98% rename from include/radproto/attribute_types.h rename to include/radproto/attribute_codes.h index bd6466c..b61f78d 100644 --- a/include/radproto/attribute_types.h +++ b/include/radproto/attribute_codes.h @@ -2,7 +2,7 @@ namespace RadProto { - enum Attribute_Types + enum Attribute_Codes { USER_NAME = 1, USER_PASSWORD = 2, diff --git a/include/radproto/dictionaries.h b/include/radproto/dictionaries.h index f2ef086..20cbc13 100644 --- a/include/radproto/dictionaries.h +++ b/include/radproto/dictionaries.h @@ -12,8 +12,25 @@ namespace RadProto BasicDictionary() = default; std::string name(uint32_t code) const; uint32_t code(const std::string& name) const; - void add(uint32_t code, const std::string& name); + std::string type(uint32_t code) const; + std::string type(const std::string& name) const; + + void add(uint32_t code, const std::string& name, const std::string& type); void append(const BasicDictionary& basicDict); + private: + std::map> m_rightDict; + std::map> m_reverseDict; + }; + + class VendorDictionary + { + public: + VendorDictionary() = default; + std::string name(uint32_t code) const; + uint32_t code(const std::string& name) const; + + void add(uint32_t code, const std::string& name); + void append(const VendorDictionary& vendorDict); private: std::map m_rightDict; std::map m_reverseDict; @@ -38,13 +55,15 @@ namespace RadProto Dictionaries(const std::string& filePath); void append(const Dictionaries& fillingDictionaries); const BasicDictionary& attributes() const { return m_attributes; } - const BasicDictionary& vendorNames() const { return m_vendorNames; } + const VendorDictionary& vendorNames() const { return m_vendorNames; } const DependentDictionary& attributeValues() const { return m_attributeValues; } const DependentDictionary& vendorAttributes() const { return m_vendorAttributes; } const DependentDictionary& vendorAttributeValues() const { return m_vendorAttributeValues; } std::string attributeName(uint32_t code) const; uint32_t attributeCode(const std::string& name) const; + std::string attributeType(uint32_t code) const; + std::string attributeType(const std::string name) const; std::string vendorName(uint32_t code) const; uint32_t vendorCode(const std::string& name) const; @@ -60,7 +79,7 @@ namespace RadProto private: BasicDictionary m_attributes; - BasicDictionary m_vendorNames; + VendorDictionary m_vendorNames; DependentDictionary m_attributeValues; DependentDictionary m_vendorAttributes; DependentDictionary m_vendorAttributeValues; diff --git a/include/radproto/error.h b/include/radproto/error.h index 92bfc42..b9c4ef2 100644 --- a/include/radproto/error.h +++ b/include/radproto/error.h @@ -19,11 +19,12 @@ namespace RadProto numberOfBytesIsLessThan20, requestLengthIsShort, eapMessageAttributeError, - invalidAttributeType, + invalidAttributeCode, invalidAttributeSize, invalidVendorSpecificAttributeId, suchAttributeNameAlreadyExists, - suchAttributeCodeAlreadyExists + suchAttributeCodeAlreadyExists, + suchAttributeNameWithAnotherTypeAlreadyExists }; class Exception: public std::runtime_error diff --git a/include/radproto/packet.h b/include/radproto/packet.h index 6d5b40b..33fa0e8 100644 --- a/include/radproto/packet.h +++ b/include/radproto/packet.h @@ -13,10 +13,10 @@ namespace RadProto { public: Packet(const uint8_t* buffer, size_t size, const std::string& secret); - Packet(uint8_t type, uint8_t id, const std::array& auth, const std::vector& attributes, const std::vector& vendorSpecific); + Packet(uint8_t code, uint8_t id, const std::array& auth, const std::vector& attributes, const std::vector& vendorSpecific); Packet(const Packet& other); ~Packet(); - uint8_t type() const { return m_type; } + uint8_t code() const { return m_code; } uint8_t id() const { return m_id; }; const std::array& auth() const { return m_auth; } const std::vector& attributes() const { return m_attributes; } @@ -24,7 +24,7 @@ namespace RadProto const std::vector makeSendBuffer(const std::string& secret) const; private: - uint8_t m_type; + uint8_t m_code; uint8_t m_id; bool m_recalcAuth; std::array m_auth; diff --git a/include/radproto/vendor_attribute.h b/include/radproto/vendor_attribute.h index 2c4867e..4e42514 100644 --- a/include/radproto/vendor_attribute.h +++ b/include/radproto/vendor_attribute.h @@ -10,14 +10,14 @@ namespace RadProto { public: VendorSpecific(const uint8_t* data); - VendorSpecific(uint32_t vendorId, uint8_t vendorType, const std::vector& vendorValue); + VendorSpecific(uint32_t vendorId, uint8_t vendorAttributeCode, const std::vector& vendorValue); std::string toString() const; - uint8_t vendorType() const { return m_vendorType; } + uint8_t vendorAttributeCode() const { return m_vendorAttributeCode; } uint32_t vendorId() const { return m_vendorId; } std::vector toVector() const; private: uint32_t m_vendorId; - uint8_t m_vendorType; + uint8_t m_vendorAttributeCode; std::vector m_value; }; } diff --git a/sample/server.cpp b/sample/server.cpp index 4eedd01..a0cb4bc 100644 --- a/sample/server.cpp +++ b/sample/server.cpp @@ -1,6 +1,6 @@ #include "server.h" #include "packet_codes.h" -#include "attribute_types.h" +#include "attribute_codes.h" #include #include @@ -37,11 +37,11 @@ RadProto::Packet Server::makeResponse(const RadProto::Packet& request) std::string userName; for (const auto& attribute : request.attributes()) { - if (attribute->type() == RadProto::USER_NAME) + if (attribute->code() == RadProto::USER_NAME) userName = attribute->toString(); } - if (request.type() == RadProto::ACCESS_REQUEST && userName == "test") + if (request.code() == RadProto::ACCESS_REQUEST && userName == "test") return RadProto::Packet(RadProto::ACCESS_ACCEPT, request.id(), request.auth(), attributes, vendorSpecific); return RadProto::Packet(RadProto::ACCESS_REJECT, request.id(), request.auth(), attributes, vendorSpecific); diff --git a/src/attribute.cpp b/src/attribute.cpp index 53f3fee..043f8af 100644 --- a/src/attribute.cpp +++ b/src/attribute.cpp @@ -7,20 +7,20 @@ #include using Attribute = RadProto::Attribute; -Attribute::Attribute(uint8_t type) - : m_type(type) +Attribute::Attribute(uint8_t code) + : m_code(code) { } using String = RadProto::String; -String::String(uint8_t type, const uint8_t* data, size_t size) - : Attribute(type), +String::String(uint8_t code, const uint8_t* data, size_t size) + : Attribute(code), m_value(reinterpret_cast(data), size) { } -String::String(uint8_t type, const std::string& string) - : Attribute(type), +String::String(uint8_t code, const std::string& string) + : Attribute(code), m_value(string) { } @@ -29,7 +29,7 @@ std::vector String::toVector(const std::string& /*secret*/, const std:: { std::vector attribute(m_value.length() + 2); std::copy(m_value.begin(), m_value.end(), std::next(attribute.begin(), 2)); - attribute[0] = type(); + attribute[0] = code(); attribute[1] = m_value.length() + 2; return attribute; } @@ -40,8 +40,8 @@ String* String::clone() const } using Integer = RadProto::Integer; -Integer::Integer(uint8_t type, const uint8_t* data, size_t size) - : Attribute(type), +Integer::Integer(uint8_t code, const uint8_t* data, size_t size) + : Attribute(code), m_value(0) { if (size != 4) @@ -53,8 +53,8 @@ Integer::Integer(uint8_t type, const uint8_t* data, size_t size) + data[3]; } -Integer::Integer(uint8_t type, uint32_t value) - : Attribute(type), +Integer::Integer(uint8_t code, uint32_t value) + : Attribute(code), m_value(value) { } @@ -67,7 +67,7 @@ std::string Integer::toString() const std::vector Integer::toVector(const std::string& /*secret*/, const std::array& /*auth*/) const { std::vector attribute(6); - attribute[0] = type(); + attribute[0] = code(); attribute[1] = 6; attribute[2] = m_value / (1 << 24); attribute[3] = (m_value / (1 << 16)) % 256; @@ -82,8 +82,8 @@ Integer* Integer::clone() const } using IpAddress = RadProto::IpAddress; -IpAddress::IpAddress(uint8_t type, const uint8_t* data, size_t size) - : Attribute(type) +IpAddress::IpAddress(uint8_t code, const uint8_t* data, size_t size) + : Attribute(code) { if (size != 4) throw RadProto::Exception(RadProto::Error::invalidAttributeSize); @@ -92,8 +92,8 @@ IpAddress::IpAddress(uint8_t type, const uint8_t* data, size_t size) m_value[i] = data[i]; } -IpAddress::IpAddress(uint8_t type, const std::array& address) - : Attribute(type), +IpAddress::IpAddress(uint8_t code, const std::array& address) + : Attribute(code), m_value(address) { } @@ -107,7 +107,7 @@ std::vector IpAddress::toVector(const std::string& /*secret*/, const st { std::vector attribute(6); - attribute[0] = type(); + attribute[0] = code(); attribute[1] = attribute.size(); for (size_t i = 0; i < m_value.size(); ++i) attribute[i + 2] = m_value[i]; @@ -121,8 +121,8 @@ IpAddress* IpAddress::clone() const } using Encrypted = RadProto::Encrypted; -Encrypted::Encrypted(uint8_t type, const uint8_t* data, size_t size, const std::string& secret, const std::array& auth) - : Attribute(type) +Encrypted::Encrypted(uint8_t code, const uint8_t* data, size_t size, const std::string& secret, const std::array& auth) + : Attribute(code) { if (size > 128) throw RadProto::Exception(RadProto::Error::invalidAttributeSize); @@ -154,8 +154,8 @@ Encrypted::Encrypted(uint8_t type, const uint8_t* data, size_t size, const std:: m_value.assign(plaintext.begin(), std::find(plaintext.begin(), plaintext.end(), 0)); } -Encrypted::Encrypted(uint8_t type, const std::string& password) - : Attribute(type), +Encrypted::Encrypted(uint8_t code, const std::string& password) + : Attribute(code), m_value(password) { } @@ -176,7 +176,7 @@ std::vector Encrypted::toVector(const std::string& secret, const std::a mdBuffer[i + secret.length()] = auth[i]; std::vector res(plaintext.length() + 2); - res[0] = type(); + res[0] = code(); res[1] = res.size(); auto it = std::next(res.begin(), 2); @@ -202,16 +202,16 @@ Encrypted* Encrypted::clone() const } using Bytes = RadProto::Bytes; -Bytes::Bytes(uint8_t type, const uint8_t* data, size_t size) - : Attribute(type), +Bytes::Bytes(uint8_t code, const uint8_t* data, size_t size) + : Attribute(code), m_value(size) { for (size_t i = 0; i < size; ++i) m_value[i] = data[i]; } -Bytes::Bytes(uint8_t type, const std::vector& bytes) - : Attribute(type), +Bytes::Bytes(uint8_t code, const std::vector& bytes) + : Attribute(code), m_value(bytes) { } @@ -230,7 +230,7 @@ std::vector Bytes::toVector(const std::string& /*secret*/, const std::a { std::vector attribute(m_value); attribute.insert(attribute.begin(), attribute.size() + 2); - attribute.insert(attribute.begin(), type()); + attribute.insert(attribute.begin(), code()); return attribute; } Bytes* Bytes::clone() const @@ -239,8 +239,8 @@ Bytes* Bytes::clone() const } using ChapPassword = RadProto::ChapPassword; -ChapPassword::ChapPassword(uint8_t type, const uint8_t* data, size_t size) - : Attribute(type), +ChapPassword::ChapPassword(uint8_t code, const uint8_t* data, size_t size) + : Attribute(code), m_value(size - 1) { if (size != 17) @@ -252,8 +252,8 @@ ChapPassword::ChapPassword(uint8_t type, const uint8_t* data, size_t size) m_value[i] = data[i + 1]; } -ChapPassword::ChapPassword(uint8_t type, uint8_t chapId, const std::vector& chapValue) - : Attribute(type), +ChapPassword::ChapPassword(uint8_t code, uint8_t chapId, const std::vector& chapValue) + : Attribute(code), m_chapId(chapId), m_value(chapValue) { @@ -274,7 +274,7 @@ std::vector ChapPassword::toVector(const std::string& /*secret*/, const std::vector attribute(m_value); attribute.insert(attribute.begin(), m_chapId); attribute.insert(attribute.begin(), m_value.size() + 3); - attribute.insert(attribute.begin(), type()); + attribute.insert(attribute.begin(), code()); return attribute; } diff --git a/src/dictionaries.cpp b/src/dictionaries.cpp index f6b4a5e..4b772a2 100644 --- a/src/dictionaries.cpp +++ b/src/dictionaries.cpp @@ -6,24 +6,35 @@ #include using BasicDictionary = RadProto::BasicDictionary; + std::string BasicDictionary::name(uint32_t code) const { - return m_rightDict.at(code); + return m_rightDict.at(code).first; +} + +std::string BasicDictionary::type(uint32_t code) const +{ + return m_rightDict.at(code).second; } uint32_t BasicDictionary::code(const std::string& name) const { - return m_reverseDict.at(name); + return m_reverseDict.at(name).first; } -void BasicDictionary::add(uint32_t code, const std::string& name) +std::string BasicDictionary::type(const std::string& name) const +{ + return m_reverseDict.at(name).second; +} + +void BasicDictionary::add(uint32_t code, const std::string& name, const std::string& type) { for (const auto& entry: m_rightDict) - if (entry.second == name && entry.first != code) + if (entry.second.first == name && entry.first != code) throw Exception(Error::suchAttributeNameAlreadyExists, "[BasicDictionary::add]. Attribute name " + name + " already exists with code " + std::to_string(entry.first)); - m_rightDict.insert_or_assign(code, name); - m_reverseDict.emplace(name, code); + m_rightDict.insert_or_assign(code, std::make_pair(name, type)); + m_reverseDict.insert_or_assign(name, std::make_pair(code, type)); } void BasicDictionary::append(const BasicDictionary& basicDict) @@ -31,17 +42,56 @@ void BasicDictionary::append(const BasicDictionary& basicDict) for (const auto& entry: basicDict.m_rightDict) { for (const auto& item: m_rightDict) - if (entry.second == item.second && entry.first != item.first) - throw Exception(Error::suchAttributeNameAlreadyExists, "[BasicDictionary::append]. Attribute name " + entry.second + " already exists with code " + std::to_string(item.first)); + if (entry.second.first == item.second.first && entry.first != item.first) + throw Exception(Error::suchAttributeNameAlreadyExists, "[BasicDictionary::append]. Attribute name " + entry.second.first + " already exists with code " + std::to_string(item.first)); m_rightDict.insert_or_assign(entry.first, entry.second); } for (const auto& entry: basicDict.m_reverseDict) + m_reverseDict.insert_or_assign(entry.first, entry.second); +} + +using VendorDictionary = RadProto::VendorDictionary; + +std::string VendorDictionary::name(uint32_t code) const +{ + return m_rightDict.at(code); +} + +uint32_t VendorDictionary::code(const std::string& name) const +{ + return m_reverseDict.at(name); +} + +void VendorDictionary::add(uint32_t code, const std::string& name) +{ + for (const auto& entry: m_rightDict) + { + if (entry.second == name && entry.first != code) + throw Exception(Error::suchAttributeNameAlreadyExists, "[VendorDictionary::add]. Vendor attribute name " + name + " already exists with code " + std::to_string(entry.first)); + } + m_rightDict.insert_or_assign(code, name); + m_reverseDict.emplace(name, code); +} + +void VendorDictionary::append(const VendorDictionary& vendorDict) +{ + for (const auto& entry: vendorDict.m_rightDict) + { + for (const auto& item: m_rightDict) + if (entry.second == item.second && entry.first != item.first) + throw Exception(Error::suchAttributeNameAlreadyExists, "[VendorDictionary::append]. Vendor attribute name " + entry.second + " already exists with code " + std::to_string(item.first)); + + m_rightDict.insert_or_assign(entry.first, entry.second); + } + + for (const auto& entry: vendorDict.m_reverseDict) m_reverseDict.emplace(entry.first, entry.second); } using DependentDictionary = RadProto::DependentDictionary; + std::string DependentDictionary::name(const std::string& dependencyName, uint32_t code) const { return m_rightDict.at(std::make_pair(dependencyName, code)); @@ -55,9 +105,10 @@ uint32_t DependentDictionary::code(const std::string& dependencyName, const std: void DependentDictionary::add(uint32_t code, const std::string& name, const std::string& dependencyName) { for (const auto& entry: m_rightDict) + { if (entry.second == name && entry.first.first == dependencyName && entry.first.second != code) throw Exception(Error::suchAttributeNameAlreadyExists, "[DependentDictionary::add]. Value name " + name + " of attribute " + dependencyName + " already exists with code " + std::to_string(entry.first.second)); - + } m_rightDict.insert_or_assign(std::make_pair(dependencyName, code), name); m_reverseDict.emplace(std::make_pair(dependencyName, name), code); } @@ -77,6 +128,7 @@ void DependentDictionary::append(const DependentDictionary& dependentDict) } using Dictionaries = RadProto::Dictionaries; + Dictionaries::Dictionaries(const std::string& filePath) { std::ifstream stream(filePath); @@ -99,24 +151,59 @@ Dictionaries::Dictionaries(const std::string& filePath) if (!tokens.empty()) { + std::vector excludeAttrs; + if (tokens[0] == "ATTRIBUTE") { - const auto& attrName = tokens[1]; - const auto code = std::stoul(tokens[2]); - if (!vendorName.empty()) - m_vendorAttributes.add(code, attrName, vendorName); + std::string::size_type n = tokens[2].find("."); + if (n == std::string::npos) + { + std::string attrName; + std::string attrType; + const auto code = std::stoul(tokens[2]); + attrName = tokens[1]; + + if (tokens.size() == 5) + { + if (tokens[4] == "encrypt=1") + attrType = "encrypted"; + else + attrType = "bytes"; + } + else + attrType = tokens[3]; + + if (!vendorName.empty()) + m_vendorAttributes.add(code, attrName, vendorName); + else + m_attributes.add(code, attrName, attrType); + } else - m_attributes.add(code, attrName); + excludeAttrs.push_back(tokens[1]); } else if (tokens[0] == "VALUE") { - const auto& attrNameVal = tokens[1]; - const auto& valueName = tokens[2]; - const auto valueCode = std::stoul(tokens[3]); - if (!vendorName.empty()) - m_vendorAttributeValues.add(valueCode, valueName, attrNameVal); - else - m_attributeValues.add(valueCode, valueName, attrNameVal); + bool flag = false; + if (!excludeAttrs.empty()) + { + for (const auto& name : excludeAttrs) + if (tokens[1] == name) + { + flag = true; + break; + } + } + + if (!flag) + { + const auto& attrNameVal = tokens[1]; + const auto& valueName = tokens[2]; + const auto valueCode = std::stoul(tokens[3]); + if (!vendorName.empty()) + m_vendorAttributeValues.add(valueCode, valueName, attrNameVal); + else + m_attributeValues.add(valueCode, valueName, attrNameVal); + } } else if (tokens[0] == "VENDOR") m_vendorNames.add(std::stoul(tokens[2]), tokens[1]); @@ -154,6 +241,16 @@ uint32_t Dictionaries::attributeCode(const std::string& name) const return attributes().code(name); } +std::string Dictionaries::attributeType(uint32_t code) const +{ + return attributes().type(code); +} + +std::string Dictionaries::attributeType(const std::string name) const +{ + return attributes().type(name); +} + std::string Dictionaries::vendorName(uint32_t code) const { return vendorNames().name(code); diff --git a/src/error.cpp b/src/error.cpp index edba414..b31d423 100644 --- a/src/error.cpp +++ b/src/error.cpp @@ -33,8 +33,8 @@ std::string ErrorCategory::message(int ev) const noexcept return "Request length is less than specified in the request"; case Error::eapMessageAttributeError: return "The EAP-Message attribute is present, but the Message-Authenticator attribute is missing"; - case Error::invalidAttributeType: - return "Invalid attribute type"; + case Error::invalidAttributeCode: + return "Invalid attribute code"; case Error::invalidAttributeSize: return "Invalid attribute size"; case Error::invalidVendorSpecificAttributeId: @@ -43,6 +43,8 @@ std::string ErrorCategory::message(int ev) const noexcept return "Such attribute name already exists"; case Error::suchAttributeCodeAlreadyExists: return "Such attribute code already exists"; + case Error::suchAttributeNameWithAnotherTypeAlreadyExists: + return "Such attribute name with another type already exists"; default: return "(Unrecognized error)"; } diff --git a/src/packet.cpp b/src/packet.cpp index 516d3df..a674863 100644 --- a/src/packet.cpp +++ b/src/packet.cpp @@ -1,6 +1,6 @@ #include "packet.h" #include "error.h" -#include "attribute_types.h" +#include "attribute_codes.h" #include #include @@ -8,22 +8,22 @@ using Packet = RadProto::Packet; namespace { - RadProto::Attribute* makeAttribute(uint8_t type, const uint8_t* data, size_t size, const std::string& secret, const std::array& auth) + RadProto::Attribute* makeAttribute(uint8_t code, const uint8_t* data, size_t size, const std::string& secret, const std::array& auth) { - if (type == 1 || type == 11 || type == 18 || type == 22 || type == 34 || type == 35 || type == 60 || type == 63) - return new RadProto::String(type, data, size); - else if (type == 2) - return new RadProto::Encrypted(type, data, size, secret, auth); - else if (type == 3) - return new RadProto::ChapPassword(type, data, size); - else if (type == 4 || type == 8 || type == 9 || type == 14) - return new RadProto::IpAddress(type, data, size); - else if (type == 5 || type == 6 || type == 7 || type == 10 || type == 12 || type == 13 || type == 15 || type == 16 || type == 27 || type == 28 || type == 29 || type == 37 || type == 38 || type == 61 || type == 62) - return new RadProto::Integer(type, data, size); - else if (type == 19 || type == 20 || type == 24 || type == 25 || type == 30 || type == 31 || type == 32 || type == 33 || type == 36 || type == 39 || type == 79 || type == 80) - return new RadProto::Bytes(type, data, size); - - throw RadProto::Exception(RadProto::Error::invalidAttributeType); + if (code == 1 || code == 11 || code == 18 || code == 22 || code == 34 || code == 35 || code == 60 || code == 63) + return new RadProto::String(code, data, size); + else if (code == 2) + return new RadProto::Encrypted(code, data, size, secret, auth); + else if (code == 3) + return new RadProto::ChapPassword(code, data, size); + else if (code == 4 || code == 8 || code == 9 || code == 14) + return new RadProto::IpAddress(code, data, size); + else if (code == 5 || code == 6 || code == 7 || code == 10 || code == 12 || code == 13 || code == 15 || code == 16 || code == 27 || code == 28 || code == 29 || code == 37 || code == 38 || code == 61 || code == 62) + return new RadProto::Integer(code, data, size); + else if (code == 19 || code == 20 || code == 24 || code == 25 || code == 30 || code == 31 || code == 32 || code == 33 || code == 36 || code == 39 || code == 79 || code == 80) + return new RadProto::Bytes(code, data, size); + + throw RadProto::Exception(RadProto::Error::invalidAttributeCode); } } @@ -38,7 +38,7 @@ Packet::Packet(const uint8_t* buffer, size_t size, const std::string& secret) if (size < length) throw Exception(Error::requestLengthIsShort); - m_type = buffer[0]; + m_code = buffer[0]; m_id = buffer[1]; @@ -63,20 +63,20 @@ Packet::Packet(const uint8_t* buffer, size_t size, const std::string& secret) bool messageAuthenticator = false; for (const auto& a : m_attributes) { - if (a->type() == EAP_MESSAGE) + if (a->code() == EAP_MESSAGE) eapMessage = true; - if (a->type() == MESSAGE_AUTHENTICATOR) + if (a->code() == MESSAGE_AUTHENTICATOR) messageAuthenticator = true; } if (eapMessage && !messageAuthenticator) throw Exception(Error::eapMessageAttributeError); } -Packet::Packet(uint8_t type, uint8_t id, const std::array& auth, const std::vector& attributes, const std::vector& vendorSpecific) - : m_type(type), +Packet::Packet(uint8_t code, uint8_t id, const std::array& auth, const std::vector& attributes, const std::vector& vendorSpecific) + : m_code(code), m_id(id), - m_recalcAuth(m_type == 2 || m_type == 3 || m_type == 11), + m_recalcAuth(m_code == 2 || m_code == 3 || m_code == 11), m_auth(auth), m_attributes(attributes), m_vendorSpecific(vendorSpecific) @@ -84,7 +84,7 @@ Packet::Packet(uint8_t type, uint8_t id, const std::array& auth, co } Packet::Packet(const Packet& other) - : m_type(other.m_type), + : m_code(other.m_code), m_id(other.m_id), m_recalcAuth(other.m_recalcAuth), m_auth(other.m_auth), @@ -106,7 +106,7 @@ const std::vector Packet::makeSendBuffer(const std::string& secret) con { std::vector sendBuffer(20); - sendBuffer[0] = m_type; + sendBuffer[0] = m_code; sendBuffer[1] = m_id; for (size_t i = 0; i < m_auth.size(); ++i) diff --git a/src/socket.cpp b/src/socket.cpp index a6c49bf..5ea27dd 100644 --- a/src/socket.cpp +++ b/src/socket.cpp @@ -7,9 +7,9 @@ using boost::system::error_code; namespace pls = std::placeholders; -std::string packetTypeToString(int type) +std::string packetCodeToString(int code) { - switch (type) + switch (code) { case RadProto::ACCESS_REQUEST: return "ACCESS_REQUEST"; case RadProto::ACCESS_ACCEPT: return "ACCESS_ACCEPT"; diff --git a/src/utils.cpp b/src/utils.cpp index 96a9f6c..b522a19 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -1,5 +1,5 @@ #include "utils.h" -#include "attribute_types.h" +#include "attribute_codes.h" #include //uint8_t, uint32_t std::string RadProto::byteToHex(uint8_t byte) diff --git a/src/vendor_attribute.cpp b/src/vendor_attribute.cpp index 9b02055..98abe81 100644 --- a/src/vendor_attribute.cpp +++ b/src/vendor_attribute.cpp @@ -2,7 +2,7 @@ #include "vendor_attribute.h" #include "utils.h" #include "error.h" -#include "attribute_types.h" +#include "attribute_codes.h" #include using VendorSpecific = RadProto::VendorSpecific; @@ -16,7 +16,7 @@ VendorSpecific::VendorSpecific(const uint8_t* data) + data[2] * (1 << 8) + data[3]; - m_vendorType = data[4]; + m_vendorAttributeCode = data[4]; size_t vendorLength = data[5]; m_value.resize(vendorLength - 2); @@ -25,9 +25,9 @@ VendorSpecific::VendorSpecific(const uint8_t* data) m_value[i] = data[i + 6]; } -VendorSpecific::VendorSpecific(uint32_t vendorId, uint8_t vendorType, const std::vector& vendorValue) +VendorSpecific::VendorSpecific(uint32_t vendorId, uint8_t vendorAttributeCode, const std::vector& vendorValue) : m_vendorId(vendorId), - m_vendorType(vendorType), + m_vendorAttributeCode(vendorAttributeCode), m_value(vendorValue) { } @@ -41,7 +41,7 @@ std::vector VendorSpecific::toVector() const attribute[3] = (m_vendorId / (1 << 16)) % 256; attribute[4] = (m_vendorId / (1 << 8)) % 256; attribute[5] = m_vendorId % 256; - attribute[6] = vendorType(); + attribute[6] = vendorAttributeCode(); attribute[7] = m_value.size() + 2; for (size_t i = 0; i < m_value.size(); ++i) attribute[i + 8] = m_value[i]; diff --git a/tests/attribute_tests.cpp b/tests/attribute_tests.cpp index c0f7168..b929788 100644 --- a/tests/attribute_tests.cpp +++ b/tests/attribute_tests.cpp @@ -33,7 +33,7 @@ BOOST_AUTO_TEST_CASE(StringDataConstructor) BOOST_TEST(values == expected, boost::test_tools::per_element()); - BOOST_CHECK_EQUAL(s.type(), 1); + BOOST_CHECK_EQUAL(s.code(), 1); } BOOST_AUTO_TEST_CASE(StringValueConstructor) @@ -47,7 +47,7 @@ BOOST_AUTO_TEST_CASE(StringValueConstructor) BOOST_TEST(values == expected, boost::test_tools::per_element()); - BOOST_CHECK_EQUAL(v.type(), 1); + BOOST_CHECK_EQUAL(v.code(), 1); } BOOST_AUTO_TEST_CASE(StringClone) @@ -62,7 +62,7 @@ BOOST_AUTO_TEST_CASE(StringClone) BOOST_TEST(values == expected, boost::test_tools::per_element()); - BOOST_CHECK_EQUAL(cs->type(), 1); + BOOST_CHECK_EQUAL(cs->code(), 1); } BOOST_AUTO_TEST_CASE(IntegerDataConstructor) @@ -79,7 +79,7 @@ BOOST_AUTO_TEST_CASE(IntegerDataConstructor) BOOST_TEST(values == expected, boost::test_tools::per_element()); - BOOST_CHECK_EQUAL(s.type(), 5); + BOOST_CHECK_EQUAL(s.code(), 5); } BOOST_AUTO_TEST_CASE(IntegerDataConstructorThrow) @@ -100,7 +100,7 @@ BOOST_AUTO_TEST_CASE(IntegerValueConstructor) BOOST_TEST(values == expected, boost::test_tools::per_element()); - BOOST_CHECK_EQUAL(v.type(), 5); + BOOST_CHECK_EQUAL(v.code(), 5); } BOOST_AUTO_TEST_CASE(IntegerClone) @@ -115,7 +115,7 @@ BOOST_AUTO_TEST_CASE(IntegerClone) BOOST_TEST(values == expected, boost::test_tools::per_element()); - BOOST_CHECK_EQUAL(cs->type(), 5); + BOOST_CHECK_EQUAL(cs->code(), 5); } BOOST_AUTO_TEST_CASE(IpAddressDataConstructor) @@ -132,7 +132,7 @@ BOOST_AUTO_TEST_CASE(IpAddressDataConstructor) BOOST_TEST(values == expected, boost::test_tools::per_element()); - BOOST_CHECK_EQUAL(s.type(), 4); + BOOST_CHECK_EQUAL(s.code(), 4); } BOOST_AUTO_TEST_CASE(IpAddressDataConstructorThrow) @@ -154,7 +154,7 @@ BOOST_AUTO_TEST_CASE(IpAddressValueConstructor) BOOST_TEST(values == expected, boost::test_tools::per_element()); - BOOST_CHECK_EQUAL(v.type(), 4); + BOOST_CHECK_EQUAL(v.code(), 4); } BOOST_AUTO_TEST_CASE(IpAddressClone) @@ -170,7 +170,7 @@ BOOST_AUTO_TEST_CASE(IpAddressClone) BOOST_TEST(values == expected, boost::test_tools::per_element()); - BOOST_CHECK_EQUAL(cs->type(), 4); + BOOST_CHECK_EQUAL(cs->code(), 4); } BOOST_AUTO_TEST_CASE(EncryptedDataConstructor_PasswordLength_6) @@ -188,7 +188,7 @@ BOOST_AUTO_TEST_CASE(EncryptedDataConstructor_PasswordLength_6) BOOST_TEST(values == expected, boost::test_tools::per_element()); - BOOST_CHECK_EQUAL(s.type(), 2); + BOOST_CHECK_EQUAL(s.code(), 2); } BOOST_AUTO_TEST_CASE(EncryptedDataConstructorThrow) @@ -220,7 +220,7 @@ BOOST_AUTO_TEST_CASE(EncryptedDataConstructor1_PasswordLength_15) BOOST_TEST(values == expected, boost::test_tools::per_element()); - BOOST_CHECK_EQUAL(s.type(), 2); + BOOST_CHECK_EQUAL(s.code(), 2); } BOOST_AUTO_TEST_CASE(EncryptedDataConstructor_PasswordLength_16) @@ -238,7 +238,7 @@ BOOST_AUTO_TEST_CASE(EncryptedDataConstructor_PasswordLength_16) BOOST_TEST(values == expected, boost::test_tools::per_element()); - BOOST_CHECK_EQUAL(s.type(), 2); + BOOST_CHECK_EQUAL(s.code(), 2); } BOOST_AUTO_TEST_CASE(EncryptedDataConstructor_PasswordLength_17) @@ -256,7 +256,7 @@ BOOST_AUTO_TEST_CASE(EncryptedDataConstructor_PasswordLength_17) BOOST_TEST(values == expected, boost::test_tools::per_element()); - BOOST_CHECK_EQUAL(s.type(), 2); + BOOST_CHECK_EQUAL(s.code(), 2); } BOOST_AUTO_TEST_CASE(EncryptedValueConstructor_PasswordLength_6) @@ -271,7 +271,7 @@ BOOST_AUTO_TEST_CASE(EncryptedValueConstructor_PasswordLength_6) BOOST_TEST(values == expected, boost::test_tools::per_element()); - BOOST_CHECK_EQUAL(v.type(), 2); + BOOST_CHECK_EQUAL(v.code(), 2); } BOOST_AUTO_TEST_CASE(EncryptedValueConstructor_PasswordLength_15) @@ -286,7 +286,7 @@ BOOST_AUTO_TEST_CASE(EncryptedValueConstructor_PasswordLength_15) BOOST_TEST(values == expected, boost::test_tools::per_element()); - BOOST_CHECK_EQUAL(v.type(), 2); + BOOST_CHECK_EQUAL(v.code(), 2); } BOOST_AUTO_TEST_CASE(EncryptedValueConstructor_PasswordLength_16) @@ -301,7 +301,7 @@ BOOST_AUTO_TEST_CASE(EncryptedValueConstructor_PasswordLength_16) BOOST_TEST(values == expected, boost::test_tools::per_element()); - BOOST_CHECK_EQUAL(v.type(), 2); + BOOST_CHECK_EQUAL(v.code(), 2); } BOOST_AUTO_TEST_CASE(EncryptedValueConstructor_PasswordLength_17) @@ -316,7 +316,7 @@ BOOST_AUTO_TEST_CASE(EncryptedValueConstructor_PasswordLength_17) BOOST_TEST(values == expected, boost::test_tools::per_element()); - BOOST_CHECK_EQUAL(v.type(), 2); + BOOST_CHECK_EQUAL(v.code(), 2); } BOOST_AUTO_TEST_CASE(EncryptedClone_PasswordLength_6) @@ -333,7 +333,7 @@ BOOST_AUTO_TEST_CASE(EncryptedClone_PasswordLength_6) BOOST_TEST(values == expected, boost::test_tools::per_element()); - BOOST_CHECK_EQUAL(cs->type(), 2); + BOOST_CHECK_EQUAL(cs->code(), 2); } BOOST_AUTO_TEST_CASE(EncryptedClone_PasswordLength_15) @@ -350,7 +350,7 @@ BOOST_AUTO_TEST_CASE(EncryptedClone_PasswordLength_15) BOOST_TEST(values == expected, boost::test_tools::per_element()); - BOOST_CHECK_EQUAL(cs->type(), 2); + BOOST_CHECK_EQUAL(cs->code(), 2); } BOOST_AUTO_TEST_CASE(EncryptedClone_PasswordLength_16) @@ -367,7 +367,7 @@ BOOST_AUTO_TEST_CASE(EncryptedClone_PasswordLength_16) BOOST_TEST(values == expected, boost::test_tools::per_element()); - BOOST_CHECK_EQUAL(cs->type(), 2); + BOOST_CHECK_EQUAL(cs->code(), 2); } BOOST_AUTO_TEST_CASE(EncryptedClone_PasswordLength_17) @@ -384,7 +384,7 @@ BOOST_AUTO_TEST_CASE(EncryptedClone_PasswordLength_17) BOOST_TEST(values == expected, boost::test_tools::per_element()); - BOOST_CHECK_EQUAL(cs->type(), 2); + BOOST_CHECK_EQUAL(cs->code(), 2); } BOOST_AUTO_TEST_CASE(BytesDataConstructor) @@ -399,7 +399,7 @@ BOOST_AUTO_TEST_CASE(BytesDataConstructor) BOOST_TEST(values == expected, boost::test_tools::per_element()); - BOOST_CHECK_EQUAL(s.type(), 19); + BOOST_CHECK_EQUAL(s.code(), 19); } BOOST_AUTO_TEST_CASE(BytesValueConstructor) @@ -413,7 +413,7 @@ BOOST_AUTO_TEST_CASE(BytesValueConstructor) BOOST_TEST(values == expected, boost::test_tools::per_element()); - BOOST_CHECK_EQUAL(v.type(), 19); + BOOST_CHECK_EQUAL(v.code(), 19); } BOOST_AUTO_TEST_CASE(BytesClone) @@ -428,7 +428,7 @@ BOOST_AUTO_TEST_CASE(BytesClone) BOOST_TEST(values == expected, boost::test_tools::per_element()); - BOOST_CHECK_EQUAL(cs->type(), 19); + BOOST_CHECK_EQUAL(cs->code(), 19); } BOOST_AUTO_TEST_CASE(ChapPasswordDataConstructor) @@ -445,7 +445,7 @@ BOOST_AUTO_TEST_CASE(ChapPasswordDataConstructor) BOOST_TEST(values == expected, boost::test_tools::per_element()); - BOOST_CHECK_EQUAL(s.type(), 3); + BOOST_CHECK_EQUAL(s.code(), 3); } BOOST_AUTO_TEST_CASE(ChapPasswordDataConstructorThrow) @@ -466,7 +466,7 @@ BOOST_AUTO_TEST_CASE(ChapPasswordValueConstructor) BOOST_TEST(values == expected, boost::test_tools::per_element()); - BOOST_CHECK_EQUAL(v.type(), 3); + BOOST_CHECK_EQUAL(v.code(), 3); } BOOST_AUTO_TEST_CASE(ChapPasswordClone) @@ -481,7 +481,7 @@ BOOST_AUTO_TEST_CASE(ChapPasswordClone) BOOST_TEST(values == expected, boost::test_tools::per_element()); - BOOST_CHECK_EQUAL(cs->type(), 3); + BOOST_CHECK_EQUAL(cs->code(), 3); } BOOST_AUTO_TEST_CASE(VendorSpecificDataConstructor) @@ -496,7 +496,7 @@ BOOST_AUTO_TEST_CASE(VendorSpecificDataConstructor) BOOST_TEST(values == expected, boost::test_tools::per_element()); - BOOST_CHECK_EQUAL(s.vendorType(), 1); + BOOST_CHECK_EQUAL(s.vendorAttributeCode(), 1); } BOOST_AUTO_TEST_CASE(VendorSpecificDataConstructorThrow) @@ -517,7 +517,7 @@ BOOST_AUTO_TEST_CASE(VendorSpecificValueConstructor) BOOST_TEST(values == expected, boost::test_tools::per_element()); - BOOST_CHECK_EQUAL(v.vendorType(), 1); + BOOST_CHECK_EQUAL(v.vendorAttributeCode(), 1); } BOOST_AUTO_TEST_SUITE_END() diff --git a/tests/dictionaries_tests.cpp b/tests/dictionaries_tests.cpp index a327aa8..9eba074 100644 --- a/tests/dictionaries_tests.cpp +++ b/tests/dictionaries_tests.cpp @@ -23,8 +23,471 @@ BOOST_AUTO_TEST_CASE(TestAdd) { RadProto::BasicDictionary b; - b.add(1, "User-Name"); - b.add(1, "User"); +// 1. codes !=, names == - exception + + b.add(1, "abc", "string"); + BOOST_CHECK_THROW(b.add(2, "abc", "string"), RadProto::Exception); + BOOST_CHECK_THROW(b.add(2, "abc", "integer"), RadProto::Exception); + + BOOST_CHECK_EQUAL(b.name(1), "abc"); + BOOST_CHECK_EQUAL(b.code("abc"), 1); + BOOST_CHECK_EQUAL(b.type("abc"), "string"); + BOOST_CHECK_EQUAL(b.type(1), "string"); + + BOOST_CHECK_THROW(b.name(2), std::out_of_range); + BOOST_CHECK_THROW(b.type(2), std::out_of_range); + + +// 2. codes ==, names !=, types == + + b.add(3, "def", "string"); + b.add(3, "ghi", "string"); + + BOOST_CHECK_EQUAL(b.name(3), "ghi"); + BOOST_CHECK_EQUAL(b.type(3), "string"); + + BOOST_CHECK_EQUAL(b.code("def"), 3); + BOOST_CHECK_EQUAL(b.code("ghi"), 3); + + BOOST_CHECK_EQUAL(b.type("def"), "string"); + BOOST_CHECK_EQUAL(b.type("ghi"), "string"); + +// 2.1. codes ==, names !=, types != + + b.add(4, "jkl", "string"); + b.add(4, "mno", "integer"); + + BOOST_CHECK_EQUAL(b.name(4), "mno"); + BOOST_CHECK_EQUAL(b.type(4), "integer"); + + BOOST_CHECK_EQUAL(b.code("jkl"), 4); + BOOST_CHECK_EQUAL(b.code("mno"), 4); + + BOOST_CHECK_EQUAL(b.type("jkl"), "string"); + BOOST_CHECK_EQUAL(b.type("mno"), "integer"); + + +// 3. codes ==, names ==, types == + + b.add(5, "cde", "integer"); + b.add(5, "cde", "integer"); + + BOOST_CHECK_EQUAL(b.name(5), "cde"); + BOOST_CHECK_EQUAL(b.type(5), "integer"); + + BOOST_CHECK_EQUAL(b.code("cde"), 5); + + BOOST_CHECK_EQUAL(b.type("cde"), "integer"); + +// 3.1. codes ==, names ==, types != + + b.add(6, "efg", "integer"); + b.add(6, "efg", "string"); + + BOOST_CHECK_EQUAL(b.name(6), "efg"); + BOOST_CHECK_EQUAL(b.type(6), "string"); + + BOOST_CHECK_EQUAL(b.code("efg"), 6); + + BOOST_CHECK_EQUAL(b.type("efg"), "string"); +} + +BOOST_AUTO_TEST_CASE(TestAppend) +{ + +// 1. codes !=, names == - exception + + RadProto::BasicDictionary a; + + a.add(1, "abc", "string"); + + BOOST_CHECK_EQUAL(a.name(1), "abc"); + BOOST_CHECK_EQUAL(a.code("abc"), 1); + BOOST_CHECK_EQUAL(a.type("abc"), "string"); + BOOST_CHECK_EQUAL(a.type(1), "string"); + + RadProto::BasicDictionary b; + + b.add(2, "abc", "string"); + + BOOST_CHECK_EQUAL(b.name(2), "abc"); + BOOST_CHECK_EQUAL(b.code("abc"), 2); + BOOST_CHECK_EQUAL(b.type("abc"), "string"); + BOOST_CHECK_EQUAL(b.type(2), "string"); + + BOOST_CHECK_THROW(a.append(b), RadProto::Exception); + + RadProto::BasicDictionary c; + + c.add(2, "abc", "integer"); + + BOOST_CHECK_EQUAL(c.name(2), "abc"); + BOOST_CHECK_EQUAL(c.code("abc"), 2); + BOOST_CHECK_EQUAL(c.type("abc"), "integer"); + BOOST_CHECK_EQUAL(c.type(2), "integer"); + + BOOST_CHECK_THROW(a.append(c), RadProto::Exception); + + BOOST_CHECK_THROW(a.name(2), std::out_of_range); + BOOST_CHECK_THROW(a.type(2), std::out_of_range); + + +// 2. codes ==, names !=, types == + + RadProto::BasicDictionary d; + + d.add(1, "abc", "string"); + + BOOST_CHECK_EQUAL(d.name(1), "abc"); + BOOST_CHECK_EQUAL(d.type(1), "string"); + BOOST_CHECK_EQUAL(d.code("abc"), 1); + BOOST_CHECK_EQUAL(d.type("abc"), "string"); + + RadProto::BasicDictionary e; + + e.add(1, "bcd", "string"); + + BOOST_CHECK_EQUAL(e.name(1), "bcd"); + BOOST_CHECK_EQUAL(e.type(1), "string"); + BOOST_CHECK_EQUAL(e.code("bcd"), 1); + BOOST_CHECK_EQUAL(e.type("bcd"), "string"); + + d.append(e); + + BOOST_CHECK_EQUAL(d.name(1), "bcd"); + BOOST_CHECK_EQUAL(d.type(1), "string"); + BOOST_CHECK_EQUAL(d.code("abc"), 1); + BOOST_CHECK_EQUAL(d.code("bcd"), 1); + BOOST_CHECK_EQUAL(d.type("abc"), "string"); + BOOST_CHECK_EQUAL(d.type("bcd"), "string"); + +// 2.1. codes ==, names !=, types != + + RadProto::BasicDictionary f; + + f.add(1, "abc", "string"); + + BOOST_CHECK_EQUAL(f.name(1), "abc"); + BOOST_CHECK_EQUAL(f.type(1), "string"); + BOOST_CHECK_EQUAL(f.code("abc"), 1); + BOOST_CHECK_EQUAL(f.type("abc"), "string"); + + RadProto::BasicDictionary g; + + g.add(1, "bcd", "integer"); + + BOOST_CHECK_EQUAL(g.name(1), "bcd"); + BOOST_CHECK_EQUAL(g.type(1), "integer"); + BOOST_CHECK_EQUAL(g.code("bcd"), 1); + BOOST_CHECK_EQUAL(g.type("bcd"), "integer"); + + f.append(g); + + BOOST_CHECK_EQUAL(f.name(1), "bcd"); + BOOST_CHECK_EQUAL(f.type(1), "integer"); + BOOST_CHECK_EQUAL(f.code("abc"), 1); + BOOST_CHECK_EQUAL(f.code("bcd"), 1); + BOOST_CHECK_EQUAL(f.type("abc"), "string"); + BOOST_CHECK_EQUAL(f.type("bcd"), "integer"); + + +// 3. codes ==, names ==, types == + + RadProto::BasicDictionary h; + + h.add(1, "abc", "string"); + + BOOST_CHECK_EQUAL(h.name(1), "abc"); + BOOST_CHECK_EQUAL(h.type(1), "string"); + BOOST_CHECK_EQUAL(h.code("abc"), 1); + BOOST_CHECK_EQUAL(h.type("abc"), "string"); + + RadProto::BasicDictionary i; + + i.add(1, "abc", "string"); + + BOOST_CHECK_EQUAL(i.name(1), "abc"); + BOOST_CHECK_EQUAL(i.type(1), "string"); + BOOST_CHECK_EQUAL(i.code("abc"), 1); + BOOST_CHECK_EQUAL(i.type("abc"), "string"); + + h.append(i); + + BOOST_CHECK_EQUAL(h.name(1), "abc"); + BOOST_CHECK_EQUAL(h.type(1), "string"); + BOOST_CHECK_EQUAL(h.code("abc"), 1); + BOOST_CHECK_EQUAL(h.type("abc"), "string"); + +// 3.1 codes ==, names ==, types != + + RadProto::BasicDictionary j; + + j.add(1, "abc", "string"); + + BOOST_CHECK_EQUAL(j.name(1), "abc"); + BOOST_CHECK_EQUAL(j.type(1), "string"); + BOOST_CHECK_EQUAL(j.code("abc"), 1); + BOOST_CHECK_EQUAL(j.type("abc"), "string"); + + RadProto::BasicDictionary k; + + k.add(1, "abc", "integer"); + + BOOST_CHECK_EQUAL(k.name(1), "abc"); + BOOST_CHECK_EQUAL(k.type(1), "integer"); + BOOST_CHECK_EQUAL(k.code("abc"), 1); + BOOST_CHECK_EQUAL(k.type("abc"), "integer"); + + j.append(k); + + BOOST_CHECK_EQUAL(j.name(1), "abc"); + BOOST_CHECK_EQUAL(j.type(1), "integer"); + BOOST_CHECK_EQUAL(j.code("abc"), 1); + BOOST_CHECK_EQUAL(j.type("abc"), "integer"); +} + +BOOST_AUTO_TEST_CASE(TestConstructor) +{ + RadProto::BasicDictionary b; + + BOOST_CHECK_THROW(b.name(0), std::out_of_range); + + BOOST_CHECK_THROW(b.code(""), std::out_of_range); + +// Function add + +// 1. codes !=, names == - exception + + b.add(1, "abc", "string"); + BOOST_CHECK_THROW(b.add(2, "abc", "string"), RadProto::Exception); + BOOST_CHECK_THROW(b.add(2, "abc", "integer"), RadProto::Exception); + + BOOST_CHECK_EQUAL(b.name(1), "abc"); + BOOST_CHECK_EQUAL(b.code("abc"), 1); + BOOST_CHECK_EQUAL(b.type("abc"), "string"); + BOOST_CHECK_EQUAL(b.type(1), "string"); + + BOOST_CHECK_THROW(b.name(2), std::out_of_range); + BOOST_CHECK_THROW(b.type(2), std::out_of_range); + + +// 2. codes ==, names !=, types == + + b.add(3, "def", "string"); + b.add(3, "ghi", "string"); + + BOOST_CHECK_EQUAL(b.name(3), "ghi"); + BOOST_CHECK_EQUAL(b.type(3), "string"); + + BOOST_CHECK_EQUAL(b.code("def"), 3); + BOOST_CHECK_EQUAL(b.code("ghi"), 3); + + BOOST_CHECK_EQUAL(b.type("def"), "string"); + BOOST_CHECK_EQUAL(b.type("ghi"), "string"); + +// 2.1. codes ==, names !=, types != + + b.add(4, "jkl", "string"); + b.add(4, "mno", "integer"); + + BOOST_CHECK_EQUAL(b.name(4), "mno"); + BOOST_CHECK_EQUAL(b.type(4), "integer"); + + BOOST_CHECK_EQUAL(b.code("jkl"), 4); + BOOST_CHECK_EQUAL(b.code("mno"), 4); + + BOOST_CHECK_EQUAL(b.type("jkl"), "string"); + BOOST_CHECK_EQUAL(b.type("mno"), "integer"); + + +// 3. codes ==, names ==, types == + + b.add(5, "cde", "integer"); + b.add(5, "cde", "integer"); + + BOOST_CHECK_EQUAL(b.name(5), "cde"); + BOOST_CHECK_EQUAL(b.type(5), "integer"); + + BOOST_CHECK_EQUAL(b.code("cde"), 5); + + BOOST_CHECK_EQUAL(b.type("cde"), "integer"); + +// 3.1. codes ==, names ==, types != + + b.add(6, "efg", "integer"); + b.add(6, "efg", "string"); + + BOOST_CHECK_EQUAL(b.name(6), "efg"); + BOOST_CHECK_EQUAL(b.type(6), "string"); + + BOOST_CHECK_EQUAL(b.code("efg"), 6); + + BOOST_CHECK_EQUAL(b.type("efg"), "string"); + + +// Function append + +// 1. codes !=, names == - exception + + RadProto::BasicDictionary a; + + a.add(1, "abc", "string"); + + BOOST_CHECK_EQUAL(a.name(1), "abc"); + BOOST_CHECK_EQUAL(a.code("abc"), 1); + BOOST_CHECK_EQUAL(a.type("abc"), "string"); + BOOST_CHECK_EQUAL(a.type(1), "string"); + + RadProto::BasicDictionary p; + + p.add(2, "abc", "string"); + + BOOST_CHECK_EQUAL(p.name(2), "abc"); + BOOST_CHECK_EQUAL(p.code("abc"), 2); + BOOST_CHECK_EQUAL(p.type("abc"), "string"); + BOOST_CHECK_EQUAL(p.type(2), "string"); + + BOOST_CHECK_THROW(a.append(p), RadProto::Exception); + + RadProto::BasicDictionary c; + + c.add(2, "abc", "integer"); + + BOOST_CHECK_EQUAL(c.name(2), "abc"); + BOOST_CHECK_EQUAL(c.code("abc"), 2); + BOOST_CHECK_EQUAL(c.type("abc"), "integer"); + BOOST_CHECK_EQUAL(c.type(2), "integer"); + + BOOST_CHECK_THROW(a.append(c), RadProto::Exception); + + BOOST_CHECK_THROW(a.name(2), std::out_of_range); + BOOST_CHECK_THROW(a.type(2), std::out_of_range); + + +// 2. codes ==, names !=, types == + + RadProto::BasicDictionary d; + + d.add(1, "abc", "string"); + + BOOST_CHECK_EQUAL(d.name(1), "abc"); + BOOST_CHECK_EQUAL(d.type(1), "string"); + BOOST_CHECK_EQUAL(d.code("abc"), 1); + BOOST_CHECK_EQUAL(d.type("abc"), "string"); + + RadProto::BasicDictionary e; + + e.add(1, "bcd", "string"); + + BOOST_CHECK_EQUAL(e.name(1), "bcd"); + BOOST_CHECK_EQUAL(e.type(1), "string"); + BOOST_CHECK_EQUAL(e.code("bcd"), 1); + BOOST_CHECK_EQUAL(e.type("bcd"), "string"); + + d.append(e); + + BOOST_CHECK_EQUAL(d.name(1), "bcd"); + BOOST_CHECK_EQUAL(d.type(1), "string"); + BOOST_CHECK_EQUAL(d.code("abc"), 1); + BOOST_CHECK_EQUAL(d.code("bcd"), 1); + BOOST_CHECK_EQUAL(d.type("abc"), "string"); + BOOST_CHECK_EQUAL(d.type("bcd"), "string"); + +// 2.1. codes ==, names !=, types != + + RadProto::BasicDictionary f; + + f.add(1, "abc", "string"); + + BOOST_CHECK_EQUAL(f.name(1), "abc"); + BOOST_CHECK_EQUAL(f.type(1), "string"); + BOOST_CHECK_EQUAL(f.code("abc"), 1); + BOOST_CHECK_EQUAL(f.type("abc"), "string"); + + RadProto::BasicDictionary g; + + g.add(1, "bcd", "integer"); + + BOOST_CHECK_EQUAL(g.name(1), "bcd"); + BOOST_CHECK_EQUAL(g.type(1), "integer"); + BOOST_CHECK_EQUAL(g.code("bcd"), 1); + BOOST_CHECK_EQUAL(g.type("bcd"), "integer"); + + f.append(g); + + BOOST_CHECK_EQUAL(f.name(1), "bcd"); + BOOST_CHECK_EQUAL(f.type(1), "integer"); + BOOST_CHECK_EQUAL(f.code("abc"), 1); + BOOST_CHECK_EQUAL(f.code("bcd"), 1); + BOOST_CHECK_EQUAL(f.type("abc"), "string"); + BOOST_CHECK_EQUAL(f.type("bcd"), "integer"); + + +// 3. codes ==, names ==, types == + + RadProto::BasicDictionary h; + + h.add(1, "abc", "string"); + + BOOST_CHECK_EQUAL(h.name(1), "abc"); + BOOST_CHECK_EQUAL(h.type(1), "string"); + BOOST_CHECK_EQUAL(h.code("abc"), 1); + BOOST_CHECK_EQUAL(h.type("abc"), "string"); + + RadProto::BasicDictionary i; + + i.add(1, "abc", "string"); + + BOOST_CHECK_EQUAL(i.name(1), "abc"); + BOOST_CHECK_EQUAL(i.type(1), "string"); + BOOST_CHECK_EQUAL(i.code("abc"), 1); + BOOST_CHECK_EQUAL(i.type("abc"), "string"); + + h.append(i); + + BOOST_CHECK_EQUAL(h.name(1), "abc"); + BOOST_CHECK_EQUAL(h.type(1), "string"); + BOOST_CHECK_EQUAL(h.code("abc"), 1); + BOOST_CHECK_EQUAL(h.type("abc"), "string"); + +// 3.1 codes ==, names ==, types != + + RadProto::BasicDictionary j; + + j.add(1, "abc", "string"); + + BOOST_CHECK_EQUAL(j.name(1), "abc"); + BOOST_CHECK_EQUAL(j.type(1), "string"); + BOOST_CHECK_EQUAL(j.code("abc"), 1); + BOOST_CHECK_EQUAL(j.type("abc"), "string"); + + RadProto::BasicDictionary k; + + k.add(1, "abc", "integer"); + + BOOST_CHECK_EQUAL(k.name(1), "abc"); + BOOST_CHECK_EQUAL(k.type(1), "integer"); + BOOST_CHECK_EQUAL(k.code("abc"), 1); + BOOST_CHECK_EQUAL(k.type("abc"), "integer"); + + j.append(k); + + BOOST_CHECK_EQUAL(j.name(1), "abc"); + BOOST_CHECK_EQUAL(j.type(1), "integer"); + BOOST_CHECK_EQUAL(j.code("abc"), 1); + BOOST_CHECK_EQUAL(j.type("abc"), "integer"); +} +BOOST_AUTO_TEST_SUITE_END() + + +BOOST_AUTO_TEST_SUITE(VendorDictionaryTests) + +BOOST_AUTO_TEST_CASE(TestAdd) +{ + RadProto::VendorDictionary b; + + b.add(1, "Vendor-Name"); + b.add(1, "Vendor"); b.add(1, "abc"); BOOST_CHECK_THROW(b.add(2, "abc"), RadProto::Exception); b.add(3, "def"); @@ -32,58 +495,57 @@ BOOST_AUTO_TEST_CASE(TestAdd) BOOST_CHECK_EQUAL(b.name(1), "abc"); BOOST_CHECK_EQUAL(b.name(3), "def"); - BOOST_CHECK_EQUAL(b.code("User-Name"), 1); - BOOST_CHECK_EQUAL(b.code("User"), 1); + BOOST_CHECK_EQUAL(b.code("Vendor-Name"), 1); + BOOST_CHECK_EQUAL(b.code("Vendor"), 1); BOOST_CHECK_EQUAL(b.code("abc"), 1); BOOST_CHECK_EQUAL(b.code("def"), 3); BOOST_CHECK_THROW(b.name(2), std::out_of_range); } - BOOST_AUTO_TEST_CASE(TestAppend) { - RadProto::BasicDictionary a; + RadProto::VendorDictionary a; a.add(2, "def"); a.add(3, "ghi"); - a.add(4, "User-Name"); + a.add(4, "Vendor-Name"); BOOST_CHECK_EQUAL(a.name(2), "def"); BOOST_CHECK_EQUAL(a.name(3), "ghi"); - BOOST_CHECK_EQUAL(a.name(4), "User-Name"); + BOOST_CHECK_EQUAL(a.name(4), "Vendor-Name"); BOOST_CHECK_EQUAL(a.code("def"), 2); BOOST_CHECK_EQUAL(a.code("ghi"), 3); - BOOST_CHECK_EQUAL(a.code("User-Name"), 4); + BOOST_CHECK_EQUAL(a.code("Vendor-Name"), 4); - RadProto::BasicDictionary b; + RadProto::VendorDictionary b; - b.add(1, "User-Name"); + b.add(1, "Vendor-Name"); - BOOST_CHECK_EQUAL(b.name(1), "User-Name"); - BOOST_CHECK_EQUAL(b.code("User-Name"), 1); + BOOST_CHECK_EQUAL(b.name(1), "Vendor-Name"); + BOOST_CHECK_EQUAL(b.code("Vendor-Name"), 1); BOOST_CHECK_THROW(a.append(b), RadProto::Exception); BOOST_CHECK_THROW(a.name(1), std::out_of_range); - RadProto::BasicDictionary c; + RadProto::VendorDictionary c; - c.add(4, "User"); + c.add(4, "Vendor"); - BOOST_CHECK_EQUAL(c.name(4), "User"); - BOOST_CHECK_EQUAL(c.code("User"), 4); + BOOST_CHECK_EQUAL(c.name(4), "Vendor"); + BOOST_CHECK_EQUAL(c.code("Vendor"), 4); a.append(c); BOOST_CHECK_EQUAL(a.name(2), "def"); BOOST_CHECK_EQUAL(a.name(3), "ghi"); - BOOST_CHECK_EQUAL(a.name(4), "User"); + BOOST_CHECK_EQUAL(a.name(4), "Vendor"); BOOST_CHECK_EQUAL(a.code("def"), 2); BOOST_CHECK_EQUAL(a.code("ghi"), 3); - BOOST_CHECK_EQUAL(a.code("User"), 4); - BOOST_CHECK_EQUAL(a.code("User-Name"), 4); + BOOST_CHECK_EQUAL(a.code("Vendor"), 4); + BOOST_CHECK_EQUAL(a.code("Vendor-Name"), 4); - RadProto::BasicDictionary d; + RadProto::VendorDictionary d; d.add(4, "jkl"); @@ -97,11 +559,11 @@ BOOST_AUTO_TEST_CASE(TestAppend) BOOST_CHECK_EQUAL(a.name(4), "jkl"); BOOST_CHECK_EQUAL(a.code("def"), 2); BOOST_CHECK_EQUAL(a.code("ghi"), 3); - BOOST_CHECK_EQUAL(a.code("User"), 4); - BOOST_CHECK_EQUAL(a.code("User-Name"), 4); + BOOST_CHECK_EQUAL(a.code("Vendor"), 4); + BOOST_CHECK_EQUAL(a.code("Vendor-Name"), 4); BOOST_CHECK_EQUAL(a.code("jkl"), 4); - RadProto::BasicDictionary e; + RadProto::VendorDictionary e; e.add(2, "def"); @@ -115,53 +577,53 @@ BOOST_AUTO_TEST_CASE(TestAppend) BOOST_CHECK_EQUAL(a.name(4), "jkl"); BOOST_CHECK_EQUAL(a.code("def"), 2); BOOST_CHECK_EQUAL(a.code("ghi"), 3); - BOOST_CHECK_EQUAL(a.code("User"), 4); - BOOST_CHECK_EQUAL(a.code("User-Name"), 4); + BOOST_CHECK_EQUAL(a.code("Vendor"), 4); + BOOST_CHECK_EQUAL(a.code("Vendor-Name"), 4); BOOST_CHECK_EQUAL(a.code("jkl"), 4); - RadProto::BasicDictionary f; + RadProto::VendorDictionary f; - f.add(4, "User-Name"); + f.add(4, "Vendor-Name"); - BOOST_CHECK_EQUAL(f.name(4), "User-Name"); - BOOST_CHECK_EQUAL(f.code("User-Name"), 4); + BOOST_CHECK_EQUAL(f.name(4), "Vendor-Name"); + BOOST_CHECK_EQUAL(f.code("Vendor-Name"), 4); a.append(f); BOOST_CHECK_EQUAL(a.name(2), "def"); BOOST_CHECK_EQUAL(a.name(3), "ghi"); - BOOST_CHECK_EQUAL(a.name(4), "User-Name"); + BOOST_CHECK_EQUAL(a.name(4), "Vendor-Name"); BOOST_CHECK_EQUAL(a.code("def"), 2); BOOST_CHECK_EQUAL(a.code("ghi"), 3); - BOOST_CHECK_EQUAL(a.code("User-Name"), 4); - BOOST_CHECK_EQUAL(a.code("User"), 4); + BOOST_CHECK_EQUAL(a.code("Vendor-Name"), 4); + BOOST_CHECK_EQUAL(a.code("Vendor"), 4); BOOST_CHECK_EQUAL(a.code("jkl"), 4); } BOOST_AUTO_TEST_CASE(TestConstructor) { - RadProto::BasicDictionary b; + RadProto::VendorDictionary b; BOOST_CHECK_THROW(b.name(0), std::out_of_range); BOOST_CHECK_THROW(b.code(""), std::out_of_range); - b.add(1, "User-Name"); - b.add(1, "User"); + b.add(1, "Vendor-Name"); + b.add(1, "Vendor"); b.add(5, "ijk"); b.add(3, "def"); - BOOST_CHECK_THROW(b.add(2, "User"), RadProto::Exception); + BOOST_CHECK_THROW(b.add(2, "Vendor"), RadProto::Exception); - BOOST_CHECK_EQUAL(b.name(1), "User"); + BOOST_CHECK_EQUAL(b.name(1), "Vendor"); BOOST_CHECK_EQUAL(b.name(5), "ijk"); BOOST_CHECK_EQUAL(b.name(3), "def"); - BOOST_CHECK_EQUAL(b.code("User-Name"), 1); - BOOST_CHECK_EQUAL(b.code("User"), 1); + BOOST_CHECK_EQUAL(b.code("Vendor-Name"), 1); + BOOST_CHECK_EQUAL(b.code("Vendor"), 1); BOOST_CHECK_EQUAL(b.code("ijk"), 5); BOOST_CHECK_EQUAL(b.code("def"), 3); BOOST_CHECK_THROW(b.name(2), std::out_of_range); - RadProto::BasicDictionary c; + RadProto::VendorDictionary c; c.add(2, "def"); c.add(5, "ghi"); @@ -173,7 +635,7 @@ BOOST_AUTO_TEST_CASE(TestConstructor) BOOST_CHECK_THROW(c.append(b), RadProto::Exception); - RadProto::BasicDictionary a; + RadProto::VendorDictionary a; a.add(2, "def"); @@ -382,6 +844,24 @@ BOOST_AUTO_TEST_CASE(TestAttributeCode) BOOST_CHECK_EQUAL(a.attributeCode("User-Password"), 2); } +BOOST_AUTO_TEST_CASE(TestAttributeType) +{ + RadProto::Dictionaries a("dictionary"); + + BOOST_CHECK_EQUAL(a.attributeType(1), "string"); + BOOST_CHECK_EQUAL(a.attributeType("User-Name"), "string"); + +// flag = "encypt=1" + + BOOST_CHECK_EQUAL(a.attributeType(2), "encrypted"); + BOOST_CHECK_EQUAL(a.attributeType("User-Password"), "encrypted"); + +// flag = "def=2" + + BOOST_CHECK_EQUAL(a.attributeType(7), "bytes"); + BOOST_CHECK_EQUAL(a.attributeType("abc"), "bytes"); +} + BOOST_AUTO_TEST_CASE(TestAttributeValueName) { RadProto::Dictionaries a("dictionary"); diff --git a/tests/dictionary.1 b/tests/dictionary.1 index 20220b7..2f768a5 100644 --- a/tests/dictionary.1 +++ b/tests/dictionary.1 @@ -1,6 +1,7 @@ ATTRIBUTE User-Name 1 string -ATTRIBUTE User-Password 2 encrypted +ATTRIBUTE User-Password 2 string encrypt=1 ATTRIBUTE Service-Type 6 integer +ATTRIBUTE abc 7 string def=2 VALUE Service-Type Login-User 1 VALUE Service-Type Framed-User 2 diff --git a/tests/packet_tests.cpp b/tests/packet_tests.cpp index afca13c..d800727 100644 --- a/tests/packet_tests.cpp +++ b/tests/packet_tests.cpp @@ -3,7 +3,7 @@ #include "radproto/packet.h" #include "radproto/attribute.h" #include "radproto/vendor_attribute.h" -#include "attribute_types.h" +#include "attribute_codes.h" #include "radproto/error.h" #include "utils.h" #include @@ -29,7 +29,7 @@ BOOST_AUTO_TEST_CASE(PacketBufferConstructorRequest) RadProto::Packet p(d.data(), d.size(), "secret"); - BOOST_CHECK_EQUAL(p.type(), 1); + BOOST_CHECK_EQUAL(p.code(), 1); BOOST_CHECK_EQUAL(p.id(), 0xd0); @@ -41,55 +41,55 @@ BOOST_AUTO_TEST_CASE(PacketBufferConstructorRequest) auto* attr0 = findAttribute(attrs, RadProto::USER_NAME); BOOST_REQUIRE(attr0 != nullptr); - BOOST_CHECK_EQUAL(attr0->type(), RadProto::USER_NAME); + BOOST_CHECK_EQUAL(attr0->code(), RadProto::USER_NAME); BOOST_CHECK_EQUAL(attr0->toString(), "test"); auto* attr1 = findAttribute(attrs, RadProto::USER_PASSWORD); BOOST_REQUIRE(attr1 != nullptr); - BOOST_CHECK_EQUAL(attr1->type(), RadProto::USER_PASSWORD); + BOOST_CHECK_EQUAL(attr1->code(), RadProto::USER_PASSWORD); BOOST_CHECK_EQUAL(attr1->toString(), "123456"); auto* attr2 = findAttribute(attrs, RadProto::NAS_IP_ADDRESS); BOOST_REQUIRE(attr2 != nullptr); - BOOST_CHECK_EQUAL(attr2->type(), RadProto::NAS_IP_ADDRESS); + BOOST_CHECK_EQUAL(attr2->code(), RadProto::NAS_IP_ADDRESS); BOOST_CHECK_EQUAL(attr2->toString(), "127.0.0.1"); auto* attr3 = findAttribute(attrs, RadProto::NAS_PORT); BOOST_REQUIRE(attr3 != nullptr); - BOOST_CHECK_EQUAL(attr3->type(), RadProto::NAS_PORT); + BOOST_CHECK_EQUAL(attr3->code(), RadProto::NAS_PORT); BOOST_CHECK_EQUAL(attr3->toString(), "1"); auto* attr4 = findAttribute(attrs, RadProto::MESSAGE_AUTHENTICATOR); BOOST_REQUIRE(attr4 != nullptr); - BOOST_CHECK_EQUAL(attr4->type(), RadProto::MESSAGE_AUTHENTICATOR); + BOOST_CHECK_EQUAL(attr4->code(), RadProto::MESSAGE_AUTHENTICATOR); BOOST_CHECK_EQUAL(attr4->toString(), "F3E000E77DEB51EB815D52373D06B71B"); auto* attr5 = findAttribute(attrs, RadProto::FRAMED_PROTOCOL); BOOST_REQUIRE(attr5 != nullptr); - BOOST_CHECK_EQUAL(attr5->type(), RadProto::FRAMED_PROTOCOL); + BOOST_CHECK_EQUAL(attr5->code(), RadProto::FRAMED_PROTOCOL); BOOST_CHECK_EQUAL(attr5->toString(), "1"); std::vector vendor = p.vendorSpecific(); BOOST_REQUIRE_EQUAL(vendor.size(), 1); BOOST_CHECK_EQUAL(vendor[0].vendorId(), 171); - BOOST_CHECK_EQUAL(vendor[0].vendorType(), 1); + BOOST_CHECK_EQUAL(vendor[0].vendorAttributeCode(), 1); BOOST_CHECK_EQUAL(vendor[0].toString(), "00000003"); - std::set types {RadProto::USER_NAME, RadProto::USER_PASSWORD, RadProto::NAS_IP_ADDRESS, RadProto::NAS_PORT, RadProto::MESSAGE_AUTHENTICATOR, RadProto::FRAMED_PROTOCOL}; + std::set codes {RadProto::USER_NAME, RadProto::USER_PASSWORD, RadProto::NAS_IP_ADDRESS, RadProto::NAS_PORT, RadProto::MESSAGE_AUTHENTICATOR, RadProto::FRAMED_PROTOCOL}; BOOST_REQUIRE_EQUAL(attrs.size(), 6); - BOOST_CHECK(types.count(attrs[0]->type()) == 1); - BOOST_CHECK(types.count(attrs[1]->type()) == 1); - BOOST_CHECK(types.count(attrs[2]->type()) == 1); - BOOST_CHECK(types.count(attrs[3]->type()) == 1); - BOOST_CHECK(types.count(attrs[4]->type()) == 1); - BOOST_CHECK(types.count(attrs[5]->type()) == 1); + BOOST_CHECK(codes.count(attrs[0]->code()) == 1); + BOOST_CHECK(codes.count(attrs[1]->code()) == 1); + BOOST_CHECK(codes.count(attrs[2]->code()) == 1); + BOOST_CHECK(codes.count(attrs[3]->code()) == 1); + BOOST_CHECK(codes.count(attrs[4]->code()) == 1); + BOOST_CHECK(codes.count(attrs[5]->code()) == 1); std::vector values = p.makeSendBuffer("secret"); @@ -106,7 +106,7 @@ BOOST_AUTO_TEST_CASE(PacketBufferConstructorResponse) RadProto::Packet p(d.data(), d.size(), "secret"); - BOOST_CHECK_EQUAL(p.type(), 2); + BOOST_CHECK_EQUAL(p.code(), 2); BOOST_CHECK_EQUAL(p.id(), 0xd0); @@ -119,48 +119,48 @@ BOOST_AUTO_TEST_CASE(PacketBufferConstructorResponse) auto* attr0 = findAttribute(attrs, RadProto::USER_NAME); BOOST_REQUIRE(attr0 != nullptr); - BOOST_CHECK_EQUAL(attr0->type(), RadProto::USER_NAME); + BOOST_CHECK_EQUAL(attr0->code(), RadProto::USER_NAME); BOOST_CHECK_EQUAL(attr0->toString(), "test"); auto* attr1 = findAttribute(attrs, RadProto::NAS_PORT); BOOST_REQUIRE(attr1 != nullptr); - BOOST_CHECK_EQUAL(attr1->type(), RadProto::NAS_PORT); + BOOST_CHECK_EQUAL(attr1->code(), RadProto::NAS_PORT); BOOST_CHECK_EQUAL(attr1->toString(), "20"); auto* attr2 = findAttribute(attrs, RadProto::NAS_IP_ADDRESS); BOOST_REQUIRE(attr2 != nullptr); - BOOST_CHECK_EQUAL(attr2->type(), RadProto::NAS_IP_ADDRESS); + BOOST_CHECK_EQUAL(attr2->code(), RadProto::NAS_IP_ADDRESS); BOOST_CHECK_EQUAL(attr2->toString(), "127.104.22.17"); auto* attr3 = findAttribute(attrs, RadProto::CALLBACK_NUMBER); BOOST_REQUIRE(attr3 != nullptr); - BOOST_CHECK_EQUAL(attr3->type(), RadProto::CALLBACK_NUMBER); + BOOST_CHECK_EQUAL(attr3->code(), RadProto::CALLBACK_NUMBER); BOOST_CHECK_EQUAL(attr3->toString(), "313233616263"); auto* attr4 = findAttribute(attrs, RadProto::CHAP_PASSWORD); BOOST_REQUIRE(attr4 != nullptr); - BOOST_CHECK_EQUAL(attr4->type(), RadProto::CHAP_PASSWORD); + BOOST_CHECK_EQUAL(attr4->code(), RadProto::CHAP_PASSWORD); BOOST_CHECK_EQUAL(attr4->toString(), "1 31323334353637383961626364656667"); std::vector vendor = p.vendorSpecific(); BOOST_REQUIRE_EQUAL(vendor.size(), 1); BOOST_CHECK_EQUAL(vendor[0].vendorId(), 171); - BOOST_CHECK_EQUAL(vendor[0].vendorType(), 1); + BOOST_CHECK_EQUAL(vendor[0].vendorAttributeCode(), 1); BOOST_CHECK_EQUAL(vendor[0].toString(), "00000003"); - std::set types {RadProto::USER_NAME, RadProto::NAS_PORT, RadProto::NAS_IP_ADDRESS, RadProto::CALLBACK_NUMBER, RadProto::CHAP_PASSWORD}; + std::set codes {RadProto::USER_NAME, RadProto::NAS_PORT, RadProto::NAS_IP_ADDRESS, RadProto::CALLBACK_NUMBER, RadProto::CHAP_PASSWORD}; BOOST_REQUIRE_EQUAL(attrs.size(), 5); - BOOST_CHECK(types.count(attrs[0]->type()) == 1); - BOOST_CHECK(types.count(attrs[1]->type()) == 1); - BOOST_CHECK(types.count(attrs[2]->type()) == 1); - BOOST_CHECK(types.count(attrs[3]->type()) == 1); - BOOST_CHECK(types.count(attrs[4]->type()) == 1); + BOOST_CHECK(codes.count(attrs[0]->code()) == 1); + BOOST_CHECK(codes.count(attrs[1]->code()) == 1); + BOOST_CHECK(codes.count(attrs[2]->code()) == 1); + BOOST_CHECK(codes.count(attrs[3]->code()) == 1); + BOOST_CHECK(codes.count(attrs[4]->code()) == 1); std::vector values = p.makeSendBuffer("secret"); @@ -185,7 +185,7 @@ BOOST_AUTO_TEST_CASE(PacketDataConstructorThrowSizeLessLength) BOOST_CHECK_THROW(RadProto::Packet p(d.data(), d.size(), "secret"), RadProto::Exception); } -BOOST_AUTO_TEST_CASE(PacketDataConstructorThrowMakeAttributeInvalidType) +BOOST_AUTO_TEST_CASE(PacketDataConstructorThrowMakeAttributeInvalidCode) { std::vector d {0x02, 0xd0, 0x00, 0x4d, 0x93, 0xa9, 0x61, 0x8b, 0x2f, 0x4c, 0x5a, 0x51, 0x65, 0x67, 0x3d, 0xb4, 0x07, 0x30, 0xa2, 0x39, 0x17, 0x06, 0x74, 0x65, 0x73, 0x74, 0x05, 0x06, 0x00, 0x00, 0x00, 0x14, 0x04, 0x06, 0x7f, 0x68, 0x16, 0x11, 0x13, 0x08, 0x31, 0x32, 0x33, 0x61, 0x62, 0x63, 0x03, 0x13, 0x01, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x1a, 0x0c, 0x00, 0x00, 0x00, 0xab, 0x01, 0x06, 0x00, 0x00, 0x00, 0x03}; @@ -205,7 +205,7 @@ BOOST_AUTO_TEST_CASE(PacketValueConstructorResponse) RadProto::Packet p(2, 208, auth, attributes, vendorSpecific); - BOOST_CHECK_EQUAL(p.type(), 2); + BOOST_CHECK_EQUAL(p.code(), 2); BOOST_CHECK_EQUAL(p.id(), 208); @@ -216,48 +216,48 @@ BOOST_AUTO_TEST_CASE(PacketValueConstructorResponse) auto* attr0 = findAttribute(attrs, RadProto::USER_NAME); BOOST_REQUIRE(attr0 != nullptr); - BOOST_CHECK_EQUAL(attr0->type(), RadProto::USER_NAME); + BOOST_CHECK_EQUAL(attr0->code(), RadProto::USER_NAME); BOOST_CHECK_EQUAL(attr0->toString(), "test"); auto* attr1 = findAttribute(attrs, RadProto::NAS_PORT); BOOST_REQUIRE(attr1 != nullptr); - BOOST_CHECK_EQUAL(attr1->type(), RadProto::NAS_PORT); + BOOST_CHECK_EQUAL(attr1->code(), RadProto::NAS_PORT); BOOST_CHECK_EQUAL(attr1->toString(), "20"); auto* attr2 = findAttribute(attrs, RadProto::NAS_IP_ADDRESS); BOOST_REQUIRE(attr2 != nullptr); - BOOST_CHECK_EQUAL(attr2->type(), RadProto::NAS_IP_ADDRESS); + BOOST_CHECK_EQUAL(attr2->code(), RadProto::NAS_IP_ADDRESS); BOOST_CHECK_EQUAL(attr2->toString(), "127.104.22.17"); auto* attr3 = findAttribute(attrs, RadProto::CALLBACK_NUMBER); BOOST_REQUIRE(attr3 != nullptr); - BOOST_CHECK_EQUAL(attr3->type(), RadProto::CALLBACK_NUMBER); + BOOST_CHECK_EQUAL(attr3->code(), RadProto::CALLBACK_NUMBER); BOOST_CHECK_EQUAL(attr3->toString(), "313233616263"); auto* attr4 = findAttribute(attrs, RadProto::CHAP_PASSWORD); BOOST_REQUIRE(attr4 != nullptr); - BOOST_CHECK_EQUAL(attr4->type(), RadProto::CHAP_PASSWORD); + BOOST_CHECK_EQUAL(attr4->code(), RadProto::CHAP_PASSWORD); BOOST_CHECK_EQUAL(attr4->toString(), "1 31323334353637383961626364656667"); std::vector vendor = p.vendorSpecific(); BOOST_REQUIRE_EQUAL(vendor.size(), 1); BOOST_CHECK_EQUAL(vendor[0].vendorId(), 171); - BOOST_CHECK_EQUAL(vendor[0].vendorType(), 1); + BOOST_CHECK_EQUAL(vendor[0].vendorAttributeCode(), 1); BOOST_CHECK_EQUAL(vendor[0].toString(), "00000003"); - std::set types {RadProto::USER_NAME, RadProto::NAS_PORT, RadProto::NAS_IP_ADDRESS, RadProto::CALLBACK_NUMBER, RadProto::CHAP_PASSWORD}; + std::set codes {RadProto::USER_NAME, RadProto::NAS_PORT, RadProto::NAS_IP_ADDRESS, RadProto::CALLBACK_NUMBER, RadProto::CHAP_PASSWORD}; BOOST_REQUIRE_EQUAL(attrs.size(), 5); - BOOST_CHECK(types.count(attrs[0]->type()) == 1); - BOOST_CHECK(types.count(attrs[1]->type()) == 1); - BOOST_CHECK(types.count(attrs[2]->type()) == 1); - BOOST_CHECK(types.count(attrs[3]->type()) == 1); - BOOST_CHECK(types.count(attrs[4]->type()) == 1); + BOOST_CHECK(codes.count(attrs[0]->code()) == 1); + BOOST_CHECK(codes.count(attrs[1]->code()) == 1); + BOOST_CHECK(codes.count(attrs[2]->code()) == 1); + BOOST_CHECK(codes.count(attrs[3]->code()) == 1); + BOOST_CHECK(codes.count(attrs[4]->code()) == 1); std::vector values = p.makeSendBuffer("secret"); @@ -279,7 +279,7 @@ BOOST_AUTO_TEST_CASE(PacketValueConstructorRequest) RadProto::Packet p(1, 208, auth, attributes, vendorSpecific); - BOOST_CHECK_EQUAL(p.type(), 1); + BOOST_CHECK_EQUAL(p.code(), 1); BOOST_CHECK_EQUAL(p.id(), 208); @@ -290,55 +290,55 @@ BOOST_AUTO_TEST_CASE(PacketValueConstructorRequest) auto* attr0 = findAttribute(attrs, RadProto::USER_NAME); BOOST_REQUIRE(attr0 != nullptr); - BOOST_CHECK_EQUAL(attr0->type(), RadProto::USER_NAME); + BOOST_CHECK_EQUAL(attr0->code(), RadProto::USER_NAME); BOOST_CHECK_EQUAL(attr0->toString(), "test"); auto* attr1 = findAttribute(attrs, RadProto::USER_PASSWORD); BOOST_REQUIRE(attr1 != nullptr); - BOOST_CHECK_EQUAL(attr1->type(), RadProto::USER_PASSWORD); + BOOST_CHECK_EQUAL(attr1->code(), RadProto::USER_PASSWORD); BOOST_CHECK_EQUAL(attr1->toString(), "123456"); auto* attr2 = findAttribute(attrs, RadProto::NAS_IP_ADDRESS); BOOST_REQUIRE(attr2 != nullptr); - BOOST_CHECK_EQUAL(attr2->type(), RadProto::NAS_IP_ADDRESS); + BOOST_CHECK_EQUAL(attr2->code(), RadProto::NAS_IP_ADDRESS); BOOST_CHECK_EQUAL(attr2->toString(), "127.0.0.1"); auto* attr3 = findAttribute(attrs, RadProto::NAS_PORT); BOOST_REQUIRE(attr3 != nullptr); - BOOST_CHECK_EQUAL(attr3->type(), RadProto::NAS_PORT); + BOOST_CHECK_EQUAL(attr3->code(), RadProto::NAS_PORT); BOOST_CHECK_EQUAL(attr3->toString(), "1"); auto* attr4 = findAttribute(attrs, RadProto::MESSAGE_AUTHENTICATOR); BOOST_REQUIRE(attr4 != nullptr); - BOOST_CHECK_EQUAL(attr4->type(), RadProto::MESSAGE_AUTHENTICATOR); + BOOST_CHECK_EQUAL(attr4->code(), RadProto::MESSAGE_AUTHENTICATOR); BOOST_CHECK_EQUAL(attr4->toString(), "F3E000E77DEB51EB815D52373D06B71B"); auto* attr5 = findAttribute(attrs, RadProto::FRAMED_PROTOCOL); BOOST_REQUIRE(attr5 != nullptr); - BOOST_CHECK_EQUAL(attr5->type(), RadProto::FRAMED_PROTOCOL); + BOOST_CHECK_EQUAL(attr5->code(), RadProto::FRAMED_PROTOCOL); BOOST_CHECK_EQUAL(attr5->toString(), "1"); std::vector vendor = p.vendorSpecific(); BOOST_REQUIRE_EQUAL(vendor.size(), 1); BOOST_CHECK_EQUAL(vendor[0].vendorId(), 171); - BOOST_CHECK_EQUAL(vendor[0].vendorType(), 1); + BOOST_CHECK_EQUAL(vendor[0].vendorAttributeCode(), 1); BOOST_CHECK_EQUAL(vendor[0].toString(), "00000003"); - std::set types {RadProto::USER_NAME, RadProto::USER_PASSWORD, RadProto::NAS_IP_ADDRESS, RadProto::NAS_PORT, RadProto::MESSAGE_AUTHENTICATOR, RadProto::FRAMED_PROTOCOL}; + std::set codes {RadProto::USER_NAME, RadProto::USER_PASSWORD, RadProto::NAS_IP_ADDRESS, RadProto::NAS_PORT, RadProto::MESSAGE_AUTHENTICATOR, RadProto::FRAMED_PROTOCOL}; BOOST_REQUIRE_EQUAL(attrs.size(), 6); - BOOST_CHECK(types.count(attrs[0]->type()) == 1); - BOOST_CHECK(types.count(attrs[1]->type()) == 1); - BOOST_CHECK(types.count(attrs[2]->type()) == 1); - BOOST_CHECK(types.count(attrs[3]->type()) == 1); - BOOST_CHECK(types.count(attrs[4]->type()) == 1); - BOOST_CHECK(types.count(attrs[5]->type()) == 1); + BOOST_CHECK(codes.count(attrs[0]->code()) == 1); + BOOST_CHECK(codes.count(attrs[1]->code()) == 1); + BOOST_CHECK(codes.count(attrs[2]->code()) == 1); + BOOST_CHECK(codes.count(attrs[3]->code()) == 1); + BOOST_CHECK(codes.count(attrs[4]->code()) == 1); + BOOST_CHECK(codes.count(attrs[5]->code()) == 1); std::vector values = p.makeSendBuffer("secret"); @@ -354,7 +354,7 @@ BOOST_AUTO_TEST_CASE(PacketCopyConstructorRequest) RadProto::Packet other(d.data(), d.size(), "secret"); RadProto::Packet p(other); - BOOST_CHECK_EQUAL(p.type(), other.type()); + BOOST_CHECK_EQUAL(p.code(), other.code()); BOOST_CHECK_EQUAL(p.id(), other.id()); @@ -364,55 +364,55 @@ BOOST_AUTO_TEST_CASE(PacketCopyConstructorRequest) auto* attr0 = findAttribute(attrs, RadProto::USER_NAME); BOOST_REQUIRE(attr0 != nullptr); - BOOST_CHECK_EQUAL(attr0->type(), RadProto::USER_NAME); + BOOST_CHECK_EQUAL(attr0->code(), RadProto::USER_NAME); BOOST_CHECK_EQUAL(attr0->toString(), "test"); auto* attr1 = findAttribute(attrs, RadProto::USER_PASSWORD); BOOST_REQUIRE(attr1 != nullptr); - BOOST_CHECK_EQUAL(attr1->type(), RadProto::USER_PASSWORD); + BOOST_CHECK_EQUAL(attr1->code(), RadProto::USER_PASSWORD); BOOST_CHECK_EQUAL(attr1->toString(), "123456"); auto* attr2 = findAttribute(attrs, RadProto::NAS_IP_ADDRESS); BOOST_REQUIRE(attr2 != nullptr); - BOOST_CHECK_EQUAL(attr2->type(), RadProto::NAS_IP_ADDRESS); + BOOST_CHECK_EQUAL(attr2->code(), RadProto::NAS_IP_ADDRESS); BOOST_CHECK_EQUAL(attr2->toString(), "127.0.0.1"); auto* attr3 = findAttribute(attrs, RadProto::NAS_PORT); BOOST_REQUIRE(attr3 != nullptr); - BOOST_CHECK_EQUAL(attr3->type(), RadProto::NAS_PORT); + BOOST_CHECK_EQUAL(attr3->code(), RadProto::NAS_PORT); BOOST_CHECK_EQUAL(attr3->toString(), "1"); auto* attr4 = findAttribute(attrs, RadProto::MESSAGE_AUTHENTICATOR); BOOST_REQUIRE(attr4 != nullptr); - BOOST_CHECK_EQUAL(attr4->type(), RadProto::MESSAGE_AUTHENTICATOR); + BOOST_CHECK_EQUAL(attr4->code(), RadProto::MESSAGE_AUTHENTICATOR); BOOST_CHECK_EQUAL(attr4->toString(), "F3E000E77DEB51EB815D52373D06B71B"); auto* attr5 = findAttribute(attrs, RadProto::FRAMED_PROTOCOL); BOOST_REQUIRE(attr5 != nullptr); - BOOST_CHECK_EQUAL(attr5->type(), RadProto::FRAMED_PROTOCOL); + BOOST_CHECK_EQUAL(attr5->code(), RadProto::FRAMED_PROTOCOL); BOOST_CHECK_EQUAL(attr5->toString(), "1"); std::vector vendor = p.vendorSpecific(); BOOST_REQUIRE_EQUAL(vendor.size(), 1); BOOST_CHECK_EQUAL(vendor[0].vendorId(), 171); - BOOST_CHECK_EQUAL(vendor[0].vendorType(), 1); + BOOST_CHECK_EQUAL(vendor[0].vendorAttributeCode(), 1); BOOST_CHECK_EQUAL(vendor[0].toString(), "00000003"); - std::set types {RadProto::USER_NAME, RadProto::USER_PASSWORD, RadProto::NAS_IP_ADDRESS, RadProto::NAS_PORT, RadProto::MESSAGE_AUTHENTICATOR, RadProto::FRAMED_PROTOCOL}; + std::set codes {RadProto::USER_NAME, RadProto::USER_PASSWORD, RadProto::NAS_IP_ADDRESS, RadProto::NAS_PORT, RadProto::MESSAGE_AUTHENTICATOR, RadProto::FRAMED_PROTOCOL}; BOOST_REQUIRE_EQUAL(attrs.size(), 6); - BOOST_CHECK(types.count(attrs[0]->type()) == 1); - BOOST_CHECK(types.count(attrs[1]->type()) == 1); - BOOST_CHECK(types.count(attrs[2]->type()) == 1); - BOOST_CHECK(types.count(attrs[3]->type()) == 1); - BOOST_CHECK(types.count(attrs[4]->type()) == 1); - BOOST_CHECK(types.count(attrs[5]->type()) == 1); + BOOST_CHECK(codes.count(attrs[0]->code()) == 1); + BOOST_CHECK(codes.count(attrs[1]->code()) == 1); + BOOST_CHECK(codes.count(attrs[2]->code()) == 1); + BOOST_CHECK(codes.count(attrs[3]->code()) == 1); + BOOST_CHECK(codes.count(attrs[4]->code()) == 1); + BOOST_CHECK(codes.count(attrs[5]->code()) == 1); std::vector values = p.makeSendBuffer("secret"); @@ -430,7 +430,7 @@ BOOST_AUTO_TEST_CASE(PacketCopyConstructorResponse) RadProto::Packet other(d.data(), d.size(), "secret"); RadProto::Packet p(other); - BOOST_CHECK_EQUAL(p.type(), other.type()); + BOOST_CHECK_EQUAL(p.code(), other.code()); BOOST_CHECK_EQUAL(p.id(), other.id()); @@ -441,48 +441,48 @@ BOOST_AUTO_TEST_CASE(PacketCopyConstructorResponse) auto* attr0 = findAttribute(attrs, RadProto::USER_NAME); BOOST_REQUIRE(attr0 != nullptr); - BOOST_CHECK_EQUAL(attr0->type(), RadProto::USER_NAME); + BOOST_CHECK_EQUAL(attr0->code(), RadProto::USER_NAME); BOOST_CHECK_EQUAL(attr0->toString(), "test"); auto* attr1 = findAttribute(attrs, RadProto::NAS_PORT); BOOST_REQUIRE(attr1 != nullptr); - BOOST_CHECK_EQUAL(attr1->type(), RadProto::NAS_PORT); + BOOST_CHECK_EQUAL(attr1->code(), RadProto::NAS_PORT); BOOST_CHECK_EQUAL(attr1->toString(), "20"); auto* attr2 = findAttribute(attrs, RadProto::NAS_IP_ADDRESS); BOOST_REQUIRE(attr2 != nullptr); - BOOST_CHECK_EQUAL(attr2->type(), RadProto::NAS_IP_ADDRESS); + BOOST_CHECK_EQUAL(attr2->code(), RadProto::NAS_IP_ADDRESS); BOOST_CHECK_EQUAL(attr2->toString(), "127.104.22.17"); auto* attr3 = findAttribute(attrs, RadProto::CALLBACK_NUMBER); BOOST_REQUIRE(attr3 != nullptr); - BOOST_CHECK_EQUAL(attr3->type(), RadProto::CALLBACK_NUMBER); + BOOST_CHECK_EQUAL(attr3->code(), RadProto::CALLBACK_NUMBER); BOOST_CHECK_EQUAL(attr3->toString(), "313233616263"); auto* attr4 = findAttribute(attrs, RadProto::CHAP_PASSWORD); BOOST_REQUIRE(attr4 != nullptr); - BOOST_CHECK_EQUAL(attr4->type(), RadProto::CHAP_PASSWORD); + BOOST_CHECK_EQUAL(attr4->code(), RadProto::CHAP_PASSWORD); BOOST_CHECK_EQUAL(attr4->toString(), "1 31323334353637383961626364656667"); std::vector vendor = p.vendorSpecific(); BOOST_REQUIRE_EQUAL(vendor.size(), 1); BOOST_CHECK_EQUAL(vendor[0].vendorId(), 171); - BOOST_CHECK_EQUAL(vendor[0].vendorType(), 1); + BOOST_CHECK_EQUAL(vendor[0].vendorAttributeCode(), 1); BOOST_CHECK_EQUAL(vendor[0].toString(), "00000003"); - std::set types {RadProto::USER_NAME, RadProto::NAS_PORT, RadProto::NAS_IP_ADDRESS, RadProto::CALLBACK_NUMBER, RadProto::CHAP_PASSWORD}; + std::set codes {RadProto::USER_NAME, RadProto::NAS_PORT, RadProto::NAS_IP_ADDRESS, RadProto::CALLBACK_NUMBER, RadProto::CHAP_PASSWORD}; BOOST_REQUIRE_EQUAL(attrs.size(), 5); - BOOST_CHECK(types.count(attrs[0]->type()) == 1); - BOOST_CHECK(types.count(attrs[1]->type()) == 1); - BOOST_CHECK(types.count(attrs[2]->type()) == 1); - BOOST_CHECK(types.count(attrs[3]->type()) == 1); - BOOST_CHECK(types.count(attrs[4]->type()) == 1); + BOOST_CHECK(codes.count(attrs[0]->code()) == 1); + BOOST_CHECK(codes.count(attrs[1]->code()) == 1); + BOOST_CHECK(codes.count(attrs[2]->code()) == 1); + BOOST_CHECK(codes.count(attrs[3]->code()) == 1); + BOOST_CHECK(codes.count(attrs[4]->code()) == 1); std::vector values = p.makeSendBuffer("secret"); diff --git a/tests/socket_tests.cpp b/tests/socket_tests.cpp index ba1b2cd..5ca86ca 100644 --- a/tests/socket_tests.cpp +++ b/tests/socket_tests.cpp @@ -4,7 +4,7 @@ #include "radproto/error.h" #include "radproto/attribute.h" #include "radproto/vendor_attribute.h" -#include "attribute_types.h" +#include "attribute_codes.h" #include "utils.h" #include #include @@ -43,7 +43,7 @@ namespace BOOST_REQUIRE(p != std::nullopt); RadProto::Packet d = p.value(); - BOOST_CHECK_EQUAL(d.type(), 1); + BOOST_CHECK_EQUAL(d.code(), 1); BOOST_CHECK_EQUAL(d.id(), 208); @@ -56,55 +56,55 @@ namespace auto* attr0 = findAttribute(attrs, RadProto::USER_NAME); BOOST_REQUIRE(attr0 != nullptr); - BOOST_CHECK_EQUAL(attr0->type(), RadProto::USER_NAME); + BOOST_CHECK_EQUAL(attr0->code(), RadProto::USER_NAME); BOOST_CHECK_EQUAL(attr0->toString(), "test"); auto* attr1 = findAttribute(attrs, RadProto::USER_PASSWORD); BOOST_REQUIRE(attr1 != nullptr); - BOOST_CHECK_EQUAL(attr1->type(), RadProto::USER_PASSWORD); + BOOST_CHECK_EQUAL(attr1->code(), RadProto::USER_PASSWORD); BOOST_CHECK_EQUAL(attr1->toString(), "123456"); auto* attr2 = findAttribute(attrs, RadProto::NAS_IP_ADDRESS); BOOST_REQUIRE(attr2 != nullptr); - BOOST_CHECK_EQUAL(attr2->type(), RadProto::NAS_IP_ADDRESS); + BOOST_CHECK_EQUAL(attr2->code(), RadProto::NAS_IP_ADDRESS); BOOST_CHECK_EQUAL(attr2->toString(), "127.0.0.1"); auto* attr3 = findAttribute(attrs, RadProto::NAS_PORT); BOOST_REQUIRE(attr3 != nullptr); - BOOST_CHECK_EQUAL(attr3->type(), RadProto::NAS_PORT); + BOOST_CHECK_EQUAL(attr3->code(), RadProto::NAS_PORT); BOOST_CHECK_EQUAL(attr3->toString(), "1"); auto* attr4 = findAttribute(attrs, RadProto::MESSAGE_AUTHENTICATOR); BOOST_REQUIRE(attr4 != nullptr); - BOOST_CHECK_EQUAL(attr4->type(), RadProto::MESSAGE_AUTHENTICATOR); + BOOST_CHECK_EQUAL(attr4->code(), RadProto::MESSAGE_AUTHENTICATOR); BOOST_CHECK_EQUAL(attr4->toString(), "F3E000E77DEB51EB815D52373D06B71B"); auto* attr5 = findAttribute(attrs, RadProto::FRAMED_PROTOCOL); BOOST_REQUIRE(attr5 != nullptr); - BOOST_CHECK_EQUAL(attr5->type(), RadProto::FRAMED_PROTOCOL); + BOOST_CHECK_EQUAL(attr5->code(), RadProto::FRAMED_PROTOCOL); BOOST_CHECK_EQUAL(attr5->toString(), "1"); std::vector vendor = d.vendorSpecific(); BOOST_REQUIRE_EQUAL(vendor.size(), 1); BOOST_CHECK_EQUAL(vendor[0].vendorId(), 171); - BOOST_CHECK_EQUAL(vendor[0].vendorType(), 1); + BOOST_CHECK_EQUAL(vendor[0].vendorAttributeCode(), 1); BOOST_CHECK_EQUAL(vendor[0].toString(), "00000003"); - std::set types {RadProto::USER_NAME, RadProto::USER_PASSWORD, RadProto::NAS_IP_ADDRESS, RadProto::NAS_PORT, RadProto::MESSAGE_AUTHENTICATOR, RadProto::FRAMED_PROTOCOL}; + std::set codes {RadProto::USER_NAME, RadProto::USER_PASSWORD, RadProto::NAS_IP_ADDRESS, RadProto::NAS_PORT, RadProto::MESSAGE_AUTHENTICATOR, RadProto::FRAMED_PROTOCOL}; BOOST_REQUIRE_EQUAL(attrs.size(), 6); - BOOST_CHECK(types.count(attrs[0]->type()) == 1); - BOOST_CHECK(types.count(attrs[1]->type()) == 1); - BOOST_CHECK(types.count(attrs[2]->type()) == 1); - BOOST_CHECK(types.count(attrs[3]->type()) == 1); - BOOST_CHECK(types.count(attrs[4]->type()) == 1); - BOOST_CHECK(types.count(attrs[5]->type()) == 1); + BOOST_CHECK(codes.count(attrs[0]->code()) == 1); + BOOST_CHECK(codes.count(attrs[1]->code()) == 1); + BOOST_CHECK(codes.count(attrs[2]->code()) == 1); + BOOST_CHECK(codes.count(attrs[3]->code()) == 1); + BOOST_CHECK(codes.count(attrs[4]->code()) == 1); + BOOST_CHECK(codes.count(attrs[5]->code()) == 1); } } diff --git a/tests/utils.cpp b/tests/utils.cpp index 004951a..52ec5cd 100644 --- a/tests/utils.cpp +++ b/tests/utils.cpp @@ -1,10 +1,10 @@ #include "utils.h" -RadProto::Attribute* findAttribute(const std::vector& attributes, RadProto::Attribute_Types type) +RadProto::Attribute* findAttribute(const std::vector& attributes, RadProto::Attribute_Codes code) { for (const auto& b : attributes) { - if (b->type() == type) + if (b->code() == code) return b; } return nullptr; diff --git a/tests/utils.h b/tests/utils.h index 1c7615a..b582641 100644 --- a/tests/utils.h +++ b/tests/utils.h @@ -1,8 +1,8 @@ #pragma once -#include "attribute_types.h" +#include "attribute_codes.h" #include "attribute.h" #include "vendor_attribute.h" -RadProto::Attribute* findAttribute(const std::vector& attributes, RadProto::Attribute_Types type); +RadProto::Attribute* findAttribute(const std::vector& attributes, RadProto::Attribute_Codes code);