Skip to content

Commit f97433c

Browse files
committed
add reserved property name
Signed-off-by: Emelia Lei <[email protected]>
1 parent d658a30 commit f97433c

File tree

4 files changed

+60
-0
lines changed

4 files changed

+60
-0
lines changed

src/groups/bmq/bmqa/bmqa_messageproperties.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
///
4343
/// - First character of the property name must be alpha-numeric.
4444
///
45+
/// - Property names starting with the prefix "bmq." are reserved for
46+
/// internal use and cannot be set by users.
47+
///
4548
/// Restrictions on Property Values {#bmqa_messageproperties_valuerestrictions}
4649
/// ===============================
4750
///

src/groups/bmq/bmqp/bmqp_messageproperties.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,9 @@ bool MessageProperties::streamInPropertyValue(const Property& p) const
363363
return rc == 0;
364364
}
365365

366+
// PUBLIC CONSTANTS
367+
const char MessageProperties::k_RESERVED_PROPERTY_PREFIX[] = "bmq.";
368+
366369
// CREATORS
367370
MessageProperties::MessageProperties(bslma::Allocator* basicAllocator)
368371
: d_allocator_p(bslma::Default::allocator(basicAllocator))

src/groups/bmq/bmqp/bmqp_messageproperties.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,10 @@ class MessageProperties {
349349
// there is only one property and property's name has maximum allowable
350350
// length, and also takes into consideration the protocol overhead.
351351

352+
/// Reserved property name prefix. Property names starting with this
353+
/// prefix are reserved for internal use and cannot be set by users.
354+
static const char k_RESERVED_PROPERTY_PREFIX[];
355+
352356
public:
353357
// TRAITS
354358
BSLMF_NESTED_TRAIT_DECLARATION(MessageProperties,
@@ -624,6 +628,13 @@ inline bool MessageProperties::isValidPropertyName(const bsl::string& name)
624628
return false; // RETURN
625629
}
626630

631+
// Check if the name starts with the reserved prefix
632+
const size_t reservedPrefixLen = bsl::strlen(k_RESERVED_PROPERTY_PREFIX);
633+
if (name.length() >= reservedPrefixLen &&
634+
name.compare(0, reservedPrefixLen, k_RESERVED_PROPERTY_PREFIX) == 0) {
635+
return false; // RETURN
636+
}
637+
627638
// TBD: use C++ flavor of 'isalnum' instead, which takes the locale as
628639
// well?
629640
return bsl::isalnum(name[0]);

src/groups/bmq/bmqp/bmqp_messageproperties.t.cpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,6 +1243,48 @@ static void test10_empty()
12431243
BMQTST_ASSERT(!p.hasProperty("z"));
12441244
}
12451245

1246+
static void test11_reservedPropertyNames()
1247+
// ------------------------------------------------------------------------
1248+
// RESERVED PROPERTY NAMES
1249+
//
1250+
// Concerns:
1251+
// Verify that property names starting with the reserved prefix
1252+
// "bmq." cannot be set by users.
1253+
//
1254+
// Testing:
1255+
// - Setting properties with reserved prefix should fail
1256+
// - Setting properties without reserved prefix should succeed
1257+
// - Specifically test "bmq.traceparent" as it's reserved for
1258+
// distributed tracing
1259+
// ------------------------------------------------------------------------
1260+
{
1261+
bmqtst::TestHelper::printTestName("RESERVED PROPERTY NAMES");
1262+
1263+
bmqp::MessageProperties obj(bmqtst::TestHelperUtil::allocator());
1264+
1265+
// Test setting property with reserved prefix should fail
1266+
BMQTST_ASSERT_NE(0, obj.setPropertyAsString("bmq.traceparent", "test"));
1267+
BMQTST_ASSERT_NE(0, obj.setPropertyAsString("bmq.test", "value"));
1268+
BMQTST_ASSERT_NE(0, obj.setPropertyAsInt32("bmq.count", 42));
1269+
1270+
// Verify that no properties were added
1271+
BMQTST_ASSERT_EQ(0, obj.numProperties());
1272+
BMQTST_ASSERT(!obj.hasProperty("bmq.traceparent"));
1273+
BMQTST_ASSERT(!obj.hasProperty("bmq.test"));
1274+
BMQTST_ASSERT(!obj.hasProperty("bmq.count"));
1275+
1276+
// Test that properties without reserved prefix work normally
1277+
BMQTST_ASSERT_EQ(0, obj.setPropertyAsString("traceparent", "test"));
1278+
BMQTST_ASSERT_EQ(0, obj.setPropertyAsString("myProperty", "value"));
1279+
BMQTST_ASSERT_EQ(0, obj.setPropertyAsInt32("count", 42));
1280+
1281+
// Verify properties were added successfully
1282+
BMQTST_ASSERT_EQ(3, obj.numProperties());
1283+
BMQTST_ASSERT(obj.hasProperty("traceparent"));
1284+
BMQTST_ASSERT(obj.hasProperty("myProperty"));
1285+
BMQTST_ASSERT(obj.hasProperty("count"));
1286+
}
1287+
12461288
// ============================================================================
12471289
// MAIN PROGRAM
12481290
// ----------------------------------------------------------------------------
@@ -1255,6 +1297,7 @@ int main(int argc, char* argv[])
12551297

12561298
switch (_testCase) {
12571299
case 0:
1300+
case 11: test11_reservedPropertyNames(); break;
12581301
case 10: test10_empty(); break;
12591302
case 9: test9_copyAssignTest(); break;
12601303
case 8: test8_printTest(); break;

0 commit comments

Comments
 (0)