Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for ABP filter redirects as mock responses #3419

Merged
merged 4 commits into from Nov 19, 2019
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Add unittest for mock redirect based responses

  • Loading branch information
bbondy committed Nov 11, 2019
commit 48ea2700d418374f3e575ad71deb998af883b8b2
@@ -0,0 +1,30 @@
/* Copyright (c) 2019 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "brave/components/brave_shields/browser/adblock_stub_response.h"
#include "services/network/public/cpp/resource_request.h"
#include "services/network/public/cpp/resource_response.h"
#include "testing/gtest/include/gtest/gtest.h"

TEST(AdBlockStubResponse, ScriptRedirectDataURL) {
std::string redirect =
"data:application/script,<script>alert('hi');</script>";
This conversation was marked as resolved by bbondy

This comment has been minimized.

Copy link
@iefremov

iefremov Nov 14, 2019

Contributor

clang-format

std::string data;
network::ResourceRequest request;
network::ResourceResponseHead resource_response;
brave_shields::MakeStubResponse(redirect, request, &resource_response, &data);
This conversation was marked as resolved by bbondy

This comment has been minimized.

Copy link
@iefremov

iefremov Nov 14, 2019

Contributor

nit: I think you can just write {} instead of preallocated request

ASSERT_STREQ(data.c_str(), "<script>alert('hi');</script>");
This conversation was marked as resolved by bbondy

This comment has been minimized.

Copy link
@iefremov

iefremov Nov 14, 2019

Contributor

EXPECT_EQ(data, "<script>alert('hi');</script>");

ASSERT_STREQ(resource_response.mime_type.c_str(), "application/script");
}

TEST(AdBlockStubResponse, HTMLRedirectDataURL) {
std::string redirect = "data:text/html,<strong>π</strong>";
std::string data;
network::ResourceRequest request;
network::ResourceResponseHead resource_response;
brave_shields::MakeStubResponse(redirect, request, &resource_response, &data);
ASSERT_STREQ(data.c_str(), "<strong>π</strong>");
This conversation was marked as resolved by bbondy

This comment has been minimized.

Copy link
@iefremov

iefremov Nov 14, 2019

Contributor

same as above

ASSERT_STREQ(resource_response.mime_type.c_str(), "text/html");
}
This conversation was marked as resolved by bbondy

This comment has been minimized.

Copy link
@iefremov

iefremov Nov 14, 2019

Contributor

Maybe add a test checking that info from redirect is prioritized over stuff in request?

This comment has been minimized.

Copy link
@bbondy

bbondy Nov 18, 2019

Author Member

yep, I'll also add a test showing that content type gets obtained from the Accept header if not present in the data URL.

@@ -92,6 +92,7 @@ test("brave_unit_tests") {
"//brave/common/shield_exceptions_unittest.cc",
"//brave/components/assist_ranker/ranker_model_loader_impl_unittest.cc",
"//brave/components/brave_shields/browser/ad_block_regional_service_unittest.cc",
"//brave/components/brave_shields/browser/adblock_stub_response_unittest.cc",
"//brave/components/brave_shields/browser/https_everywhere_recently_used_cache_unittest.cpp",
"//brave/components/rappor/log_uploader_unittest.cc",
"//brave/components/translate/core/browser/translate_language_list_unittest.cc",
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.