Skip to content

Commit 7caaeb7

Browse files
sandarshmeta-codesync[bot]
authored andcommitted
Populate the allowlist with message types
Summary: Populate the allowlist with message types and add tests Reviewed By: sharmafb Differential Revision: D91296473 fbshipit-source-id: 56db7cfe32e626fec772441de2cd7b15a800073e
1 parent f5a9d76 commit 7caaeb7

2 files changed

Lines changed: 114 additions & 8 deletions

File tree

moxygen/MoQFramer.cpp

Lines changed: 61 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,19 +146,72 @@ folly::Expected<uint64_t, moxygen::ErrorCode> decodeDelta(
146146

147147
namespace moxygen {
148148

149+
// Frame type sets for parameter allowlist
150+
const folly::F14FastSet<FrameType> kAllowedFramesForAuthToken = {
151+
FrameType::PUBLISH,
152+
FrameType::SUBSCRIBE,
153+
FrameType::SUBSCRIBE_UPDATE,
154+
FrameType::SUBSCRIBE_ANNOUNCES,
155+
FrameType::ANNOUNCE,
156+
FrameType::TRACK_STATUS,
157+
FrameType::FETCH};
158+
159+
const folly::F14FastSet<FrameType> kAllowedFramesForDeliveryTimeout = {
160+
FrameType::PUBLISH_OK,
161+
FrameType::SUBSCRIBE,
162+
FrameType::SUBSCRIBE_UPDATE};
163+
164+
const folly::F14FastSet<FrameType> kAllowedFramesForSubscriberPriority = {
165+
FrameType::SUBSCRIBE,
166+
FrameType::FETCH,
167+
FrameType::SUBSCRIBE_UPDATE,
168+
FrameType::PUBLISH_OK};
169+
170+
const folly::F14FastSet<FrameType> kAllowedFramesForSubscriptionFilter = {
171+
FrameType::SUBSCRIBE,
172+
FrameType::PUBLISH_OK,
173+
FrameType::SUBSCRIBE_UPDATE};
174+
175+
const folly::F14FastSet<FrameType> kAllowedFramesForExpires = {
176+
FrameType::SUBSCRIBE_OK,
177+
FrameType::PUBLISH,
178+
FrameType::PUBLISH_OK,
179+
FrameType::REQUEST_OK};
180+
181+
const folly::F14FastSet<FrameType> kAllowedFramesForGroupOrder = {
182+
FrameType::SUBSCRIBE,
183+
FrameType::PUBLISH_OK,
184+
FrameType::FETCH};
185+
186+
const folly::F14FastSet<FrameType> kAllowedFramesForLargestObject = {
187+
FrameType::SUBSCRIBE_OK,
188+
FrameType::PUBLISH,
189+
FrameType::REQUEST_OK};
190+
191+
const folly::F14FastSet<FrameType> kAllowedFramesForForward = {
192+
FrameType::SUBSCRIBE,
193+
FrameType::SUBSCRIBE_UPDATE,
194+
FrameType::PUBLISH,
195+
FrameType::PUBLISH_OK,
196+
FrameType::SUBSCRIBE_ANNOUNCES};
197+
149198
// Allowlist mapping: TrackRequestParamKey -> set of allowed FrameTypes
199+
// Empty set means allowed for all frame types
150200
const folly::F14FastMap<TrackRequestParamKey, folly::F14FastSet<FrameType>>
151201
kParamAllowlist = {
152-
{TrackRequestParamKey::DELIVERY_TIMEOUT, {}},
153-
{TrackRequestParamKey::AUTHORIZATION_TOKEN, {}},
202+
{TrackRequestParamKey::AUTHORIZATION_TOKEN, kAllowedFramesForAuthToken},
203+
{TrackRequestParamKey::DELIVERY_TIMEOUT,
204+
kAllowedFramesForDeliveryTimeout},
154205
{TrackRequestParamKey::MAX_CACHE_DURATION, {}},
155206
{TrackRequestParamKey::PUBLISHER_PRIORITY, {}},
156-
{TrackRequestParamKey::SUBSCRIBER_PRIORITY, {}},
157-
{TrackRequestParamKey::SUBSCRIPTION_FILTER, {}},
158-
{TrackRequestParamKey::EXPIRES, {}},
159-
{TrackRequestParamKey::GROUP_ORDER, {}},
160-
{TrackRequestParamKey::LARGEST_OBJECT, {}},
161-
{TrackRequestParamKey::FORWARD, {}},
207+
{TrackRequestParamKey::SUBSCRIBER_PRIORITY,
208+
kAllowedFramesForSubscriberPriority},
209+
{TrackRequestParamKey::SUBSCRIPTION_FILTER,
210+
kAllowedFramesForSubscriptionFilter},
211+
{TrackRequestParamKey::EXPIRES, kAllowedFramesForExpires},
212+
{TrackRequestParamKey::GROUP_ORDER, kAllowedFramesForGroupOrder},
213+
{TrackRequestParamKey::LARGEST_OBJECT, kAllowedFramesForLargestObject},
214+
{TrackRequestParamKey::FORWARD, kAllowedFramesForForward},
162215
};
163216

164217
bool Parameters::isParamAllowed(TrackRequestParamKey key) const {

moxygen/test/MoQFramerTest.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3477,3 +3477,56 @@ TEST(MoQFramerV16DeathTest, AnnounceCancelWithoutRequestIDDies) {
34773477
writer.writeAnnounceCancel(writeBuf, announceCancel),
34783478
"RequestID required for v16\\+ AnnounceCancel");
34793479
}
3480+
3481+
// Tests for Parameters::isParamAllowed()
3482+
class ParametersIsParamAllowedTest : public ::testing::Test {};
3483+
3484+
TEST_F(ParametersIsParamAllowedTest, ParamAllowedForFrameType) {
3485+
Parameters params(FrameType::SUBSCRIBE);
3486+
EXPECT_TRUE(params.isParamAllowed(TrackRequestParamKey::DELIVERY_TIMEOUT));
3487+
EXPECT_TRUE(params.isParamAllowed(TrackRequestParamKey::AUTHORIZATION_TOKEN));
3488+
EXPECT_TRUE(params.isParamAllowed(TrackRequestParamKey::SUBSCRIBER_PRIORITY));
3489+
}
3490+
3491+
TEST_F(ParametersIsParamAllowedTest, ParamNotAllowedForFrameType) {
3492+
Parameters params(FrameType::FETCH);
3493+
EXPECT_FALSE(params.isParamAllowed(TrackRequestParamKey::DELIVERY_TIMEOUT));
3494+
EXPECT_FALSE(params.isParamAllowed(TrackRequestParamKey::EXPIRES));
3495+
}
3496+
3497+
TEST_F(ParametersIsParamAllowedTest, ParamAllowedForAllFrameTypes) {
3498+
// MAX_CACHE_DURATION and PUBLISHER_PRIORITY have empty sets = allowed for all
3499+
Parameters paramsAnnounce(FrameType::ANNOUNCE);
3500+
EXPECT_TRUE(
3501+
paramsAnnounce.isParamAllowed(TrackRequestParamKey::MAX_CACHE_DURATION));
3502+
EXPECT_TRUE(
3503+
paramsAnnounce.isParamAllowed(TrackRequestParamKey::PUBLISHER_PRIORITY));
3504+
3505+
Parameters paramsFetch(FrameType::FETCH);
3506+
EXPECT_TRUE(
3507+
paramsFetch.isParamAllowed(TrackRequestParamKey::MAX_CACHE_DURATION));
3508+
EXPECT_TRUE(
3509+
paramsFetch.isParamAllowed(TrackRequestParamKey::PUBLISHER_PRIORITY));
3510+
}
3511+
3512+
TEST_F(ParametersIsParamAllowedTest, UnknownParamKeyReturnsFalse) {
3513+
Parameters params(FrameType::SUBSCRIBE);
3514+
// Cast an unknown value to TrackRequestParamKey
3515+
auto unknownKey = static_cast<TrackRequestParamKey>(9999);
3516+
EXPECT_FALSE(params.isParamAllowed(unknownKey));
3517+
}
3518+
3519+
TEST_F(ParametersIsParamAllowedTest, MultipleParamsMixedResults) {
3520+
Parameters params(FrameType::PUBLISH_OK);
3521+
// Allowed for PUBLISH_OK
3522+
EXPECT_TRUE(params.isParamAllowed(TrackRequestParamKey::DELIVERY_TIMEOUT));
3523+
EXPECT_TRUE(params.isParamAllowed(TrackRequestParamKey::SUBSCRIBER_PRIORITY));
3524+
EXPECT_TRUE(params.isParamAllowed(TrackRequestParamKey::SUBSCRIPTION_FILTER));
3525+
EXPECT_TRUE(params.isParamAllowed(TrackRequestParamKey::EXPIRES));
3526+
EXPECT_TRUE(params.isParamAllowed(TrackRequestParamKey::GROUP_ORDER));
3527+
EXPECT_TRUE(params.isParamAllowed(TrackRequestParamKey::FORWARD));
3528+
// NOT allowed for PUBLISH_OK
3529+
EXPECT_FALSE(
3530+
params.isParamAllowed(TrackRequestParamKey::AUTHORIZATION_TOKEN));
3531+
EXPECT_FALSE(params.isParamAllowed(TrackRequestParamKey::LARGEST_OBJECT));
3532+
}

0 commit comments

Comments
 (0)