-
Notifications
You must be signed in to change notification settings - Fork 898
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
Issue 5690: Add key for brave services #3198
Conversation
@@ -8,13 +8,35 @@ | |||
#include <memory> | |||
#include <vector> | |||
|
|||
#include "base/strings/stringprintf.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?
static URLPattern proxy_pattern(URLPattern::SCHEME_HTTP | | ||
URLPattern::SCHEME_HTTPS, kBraveProxyPattern); | ||
|
||
if (proxy_pattern.MatchesURL(ctx->request_url)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this is a viable method to use anymore for headers with network service - cc @iefremov
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm also not sure this was ever really the right place to add headers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not? I tested OnBeforeStartTransaction_SiteHacksWork
and it worked for UA overriding. It should be safe for non-restricted headers (Cookies, Referer, etc)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's definitely not the right place for UA overriding because there are methods specifically for that. The other method I was thinking of was NavigationHandle::SetRequestHeaders but that only works for main/subframe navigations
4548cb6
to
70a808f
Compare
namespace brave { | ||
|
||
void AddBraveServicesKeyHeader(network::ResourceRequest* url_request) { | ||
static URLPattern proxy_pattern(URLPattern::SCHEME_HTTP | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need HTTP here? I'm pretty sure all of our proxies are HTTPS only.
common/network_constants.cc
Outdated
@@ -5,6 +5,7 @@ | |||
|
|||
#include "brave/common/network_constants.h" | |||
|
|||
const char kBraveProxyPattern[] = "*://*.brave.com/*"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be https://*.brave.com/*
I think.
49cc058
to
14bbc69
Compare
0d48e43
to
9771069
Compare
f07fe4d
to
e9a934c
Compare
|
||
defines = [] | ||
if (brave_services_key != "") { | ||
defines += [ "BRAVE_SERVICES_KEY=\"$brave_services_key\"" ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mind adding a comment describing this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
#include "services/network/public/cpp/resource_request.h" | ||
#include "url/gurl.h" | ||
|
||
#if !defined(BRAVE_SERVICES_KEY) | ||
#define BRAVE_SERVICES_KEY "dummytoken" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to see some comments here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
kBraveProxyPattern); | ||
if (proxy_pattern.MatchesURL(url_request->url)) { | ||
url_request->headers.SetHeaderIfMissing(kBraveServicesKeyHeader, | ||
BRAVE_SERVICES_KEY); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-format
@@ -0,0 +1,62 @@ | |||
/* Copyright (c) 2019 The Brave Authors. All rights reserved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a browser test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done!
net::TestURLRequestContext* context() { return context_.get(); } | ||
|
||
private: | ||
content::TestBrowserThreadBundle thread_bundle_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems to me that we don't need all this stuff for simple tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are some minors
2327e50
to
117d8a4
Compare
|
||
void SetUpOnMainThread() override { | ||
host_resolver()->AddRule("*", "127.0.0.1"); | ||
EXPECT_TRUE(https_server_.Start()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd use ASSERT_TRUE
return loader_factory_; | ||
} | ||
|
||
void SetUp() override { InProcessBrowserTest::SetUp(); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unneeded?
->GetSharedURLLoaderFactory(); | ||
} | ||
|
||
bool LoadURL(std::string host) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const std::string&
or base::StringPiece
} | ||
|
||
bool LoadURL(std::string host) { | ||
std::unique_ptr<network::ResourceRequest> request = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
auto here and below
scoped_refptr<network::SharedURLLoaderFactory> loader_factory_ = nullptr; | ||
}; | ||
|
||
IN_PROC_BROWSER_TEST_F(SystemNetworkContextManagerBrowsertest, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Many thanks for making the test!
|
||
namespace brave { | ||
|
||
class BraveSystemRequestHandlerTest : public testing::Test { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you don't need to have an empty class, just use TEST(BraveSystemRequestHandlerTest, AddBraveServiceKeyHeader)
for tests
}; | ||
|
||
TEST_F(BraveSystemRequestHandlerTest, AddBraveServiceKeyHeader) { | ||
GURL url("https://demo.brave.com"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
clang-format
}; | ||
|
||
TEST_F(BraveSystemRequestHandlerTest, AddBraveServiceKeyHeader) { | ||
GURL url("https://demo.brave.com"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const GURL
|
||
#include "brave/browser/net/url_context.h" | ||
#include "brave/common/network_constants.h" | ||
#include "chrome/test/base/chrome_render_view_host_test_harness.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
most of includes are not needed - these three below and url_context.h
Fix brave/brave-browser#5690
Submitter Checklist:
npm run lint
)git rebase master
(if needed).git rebase -i
to squash commits (if needed).Test Plan:
Keychain Access
Services:
Remaining proxies are currently blocked on: brave/brave-browser#6331
Reviewer Checklist:
After-merge Checklist:
changes has landed on.