Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(148)

Side by Side Diff: mojo/public/cpp/bindings/tests/validation_unittest.cc

Issue 2312813002: Limit Mojo messages recursion depth (Closed)
Patch Set: Address review comments Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 #include <stdio.h> 7 #include <stdio.h>
8 #include <algorithm> 8 #include <algorithm>
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 // This test is similar to the BoundsCheck test but for responses. 417 // This test is similar to the BoundsCheck test but for responses.
418 TEST_F(ValidationTest, ResponseBoundsCheck) { 418 TEST_F(ValidationTest, ResponseBoundsCheck) {
419 DummyMessageReceiver dummy_receiver; 419 DummyMessageReceiver dummy_receiver;
420 mojo::FilterChain validators(&dummy_receiver); 420 mojo::FilterChain validators(&dummy_receiver);
421 validators.Append<mojo::MessageHeaderValidator>(); 421 validators.Append<mojo::MessageHeaderValidator>();
422 validators.Append<BoundsCheckTestInterface::ResponseValidator_>(); 422 validators.Append<BoundsCheckTestInterface::ResponseValidator_>();
423 423
424 RunValidationTests("resp_boundscheck_", &validators); 424 RunValidationTests("resp_boundscheck_", &validators);
425 } 425 }
426 426
427 // Test that the client cannot send a message (e.g. a recursively defined
428 // struct) so deep that the validation code blows the stack. The validation code
429 // should check for this case and return a validation error.
430 TEST_F(ValidationTest, RequestMaxRecursionDepth) {
431 DummyMessageReceiver dummy_receiver;
432 mojo::FilterChain validators(&dummy_receiver);
433 validators.Append<mojo::MessageHeaderValidator>();
434 validators.Append<ConformanceTestInterface::RequestValidator_>();
435
436 RunValidationTests("req_max_recursion_depth", &validators);
yzshen1 2016/09/07 16:51:20 Does it make sense to use the same prefix as other
tibell 2016/09/08 00:03:38 Done.
437 }
438
427 // Test that InterfacePtr<X> applies the correct validators and they don't 439 // Test that InterfacePtr<X> applies the correct validators and they don't
428 // conflict with each other: 440 // conflict with each other:
429 // - MessageHeaderValidator 441 // - MessageHeaderValidator
430 // - X::ResponseValidator_ 442 // - X::ResponseValidator_
431 TEST_F(ValidationIntegrationTest, InterfacePtr) { 443 TEST_F(ValidationIntegrationTest, InterfacePtr) {
432 IntegrationTestInterfacePtr interface_ptr = MakeProxy( 444 IntegrationTestInterfacePtr interface_ptr = MakeProxy(
433 InterfacePtrInfo<IntegrationTestInterface>(testee_endpoint(), 0u)); 445 InterfacePtrInfo<IntegrationTestInterface>(testee_endpoint(), 0u));
434 interface_ptr.internal_state()->EnableTestingMode(); 446 interface_ptr.internal_state()->EnableTestingMode();
435 447
436 RunValidationTests("integration_intf_resp", test_message_receiver()); 448 RunValidationTests("integration_intf_resp", test_message_receiver());
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 EXPECT_TRUE(IsKnownEnumValue(static_cast<StructWithEnum::EnumWithin>(0))); 502 EXPECT_TRUE(IsKnownEnumValue(static_cast<StructWithEnum::EnumWithin>(0)));
491 EXPECT_TRUE(IsKnownEnumValue(static_cast<StructWithEnum::EnumWithin>(1))); 503 EXPECT_TRUE(IsKnownEnumValue(static_cast<StructWithEnum::EnumWithin>(1)));
492 EXPECT_TRUE(IsKnownEnumValue(static_cast<StructWithEnum::EnumWithin>(2))); 504 EXPECT_TRUE(IsKnownEnumValue(static_cast<StructWithEnum::EnumWithin>(2)));
493 EXPECT_TRUE(IsKnownEnumValue(static_cast<StructWithEnum::EnumWithin>(3))); 505 EXPECT_TRUE(IsKnownEnumValue(static_cast<StructWithEnum::EnumWithin>(3)));
494 EXPECT_FALSE(IsKnownEnumValue(static_cast<StructWithEnum::EnumWithin>(4))); 506 EXPECT_FALSE(IsKnownEnumValue(static_cast<StructWithEnum::EnumWithin>(4)));
495 } 507 }
496 508
497 } // namespace 509 } // namespace
498 } // namespace test 510 } // namespace test
499 } // namespace mojo 511 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698