/* * Copyright 2004 The WebRTC Project Authors. All rights reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source * tree. An additional intellectual property rights grant can be found * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree.
*/
// Forwards results to the test class. class StunRequestThunker : public StunRequest { public:
StunRequestThunker(StunRequestManager& manager, StunRequestTest* test)
: StunRequest(manager, CreateStunMessage(STUN_BINDING_REQUEST)),
test_(test) {
SetAuthenticationRequired(false);
}
// Test handling of a normal binding response.
TEST_F(StunRequestTest, TestSuccess) { auto* request = new StunRequestThunker(manager_, this);
std::unique_ptr<StunMessage> res =
request->CreateResponseMessage(STUN_BINDING_RESPONSE);
manager_.Send(request);
EXPECT_TRUE(manager_.CheckResponse(res.get()));
// Test handling of an error binding response.
TEST_F(StunRequestTest, TestError) { auto* request = new StunRequestThunker(manager_, this);
std::unique_ptr<StunMessage> res =
request->CreateResponseMessage(STUN_BINDING_ERROR_RESPONSE);
manager_.Send(request);
EXPECT_TRUE(manager_.CheckResponse(res.get()));
// Test handling of a binding response with the wrong transaction id.
TEST_F(StunRequestTest, TestUnexpected) { auto* request = new StunRequestThunker(manager_, this);
std::unique_ptr<StunMessage> res = CreateStunMessage(STUN_BINDING_RESPONSE);
// Test that requests are sent at the right times.
TEST_F(StunRequestTest, TestBackoff) {
rtc::ScopedFakeClock fake_clock; auto* request = new StunRequestThunker(manager_, this);
std::unique_ptr<StunMessage> res =
request->CreateResponseMessage(STUN_BINDING_RESPONSE);
int64_t start = rtc::TimeMillis();
manager_.Send(request); for (int i = 0; i < 9; ++i) {
EXPECT_TRUE_SIMULATED_WAIT(request_count_ != i, STUN_TOTAL_TIMEOUT,
fake_clock);
int64_t elapsed = rtc::TimeMillis() - start;
RTC_DLOG(LS_INFO) << "STUN request #" << (i + 1) << " sent at " << elapsed
<< " ms";
EXPECT_EQ(TotalDelay(i), elapsed);
}
EXPECT_TRUE(manager_.CheckResponse(res.get()));
// Test that we timeout properly if no response is received.
TEST_F(StunRequestTest, TestTimeout) {
rtc::ScopedFakeClock fake_clock; auto* request = new StunRequestThunker(manager_, this);
std::unique_ptr<StunMessage> res =
request->CreateResponseMessage(STUN_BINDING_RESPONSE);
// Regression test for specific crash where we receive a response with the // same id as a request that doesn't have an underlying StunMessage yet.
TEST_F(StunRequestTest, TestNoEmptyRequest) {
StunRequestThunker* request = new StunRequestThunker(manager_, this);
manager_.SendDelayed(request, 100);
StunMessage dummy_req(0, request->id());
std::unique_ptr<StunMessage> res =
CreateStunMessage(STUN_BINDING_RESPONSE, &dummy_req);
// If the response contains an attribute in the "comprehension required" range // which is not recognized, the transaction should be considered a failure and // the response should be ignored.
TEST_F(StunRequestTest, TestUnrecognizedComprehensionRequiredAttribute) { auto* request = new StunRequestThunker(manager_, this);
std::unique_ptr<StunMessage> res =
request->CreateResponseMessage(STUN_BINDING_ERROR_RESPONSE);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.