Skip to content

Commit

Permalink
Enable more black box tests for android.
Browse files Browse the repository at this point in the history
Consider all service worker URL's to be trustworthy for black box
tests.

b/299309300
  • Loading branch information
aee-google committed May 15, 2024
1 parent 1002259 commit c3993f4
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 20 deletions.
7 changes: 5 additions & 2 deletions cobalt/black_box_tests/black_box_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,11 @@ def __init__(self, args):
self.proxy_port = args.proxy_port or str(
self.GetUnusedPort([_server_binding_address]))
proxy_address = args.proxy_address or _server_binding_address
_launcher_params.target_params.append(
f'--proxy={proxy_address}:{self.proxy_port}')
proxy_url = f'{proxy_address}:{self.proxy_port}'
_launcher_params.target_params.append(f'--proxy={proxy_url}')

_launcher_params.target_params.append(
'--unsafely-treat-insecure-origin-as-secure=*web-platform.test')

self.device_ips = args.device_ips

Expand Down
25 changes: 20 additions & 5 deletions cobalt/tools/automated_testing/cobalt_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,24 +135,39 @@ def __init__(self,
self.launcher_params = launcher_params
self.log_handler = log_handler
self.poll_until_wait_seconds = poll_until_wait_seconds
self.target_params = target_params
self.success_message = success_message

if log_file:
self.log_file = open(log_file, encoding='utf-8') # pylint: disable=consider-using-with
logging.basicConfig(stream=self.log_file, level=logging.INFO)
else:
self.log_file = sys.stdout

if self.launcher_params.target_params:
for target_param in self.launcher_params.target_params:
if target_param not in self.target_params:
self.target_params.append(target_param)

if url:
self.url = url
self.target_params = target_params
self.success_message = success_message
if hasattr(self, 'url'):
url_string = '--url=' + self.url
if not self.target_params:
self.target_params = [url_string]
else:
self.target_params.append(url_string)
if self.launcher_params.target_params:
self.target_params.extend(self.launcher_params.target_params)

if url.startswith('http://'):
url_base = 'http://' + url.split('/')[2]
found = False
for (i, p) in enumerate(self.target_params):
if p.startswith('--unsafely-treat-insecure-origin-as-secure='):
found = True
self.target_params[i] += ';' + url_base
break
if not found:
self.target_params.append(
f'--unsafely-treat-insecure-origin-as-secure={url_base}')

def SendResume(self):
"""Sends a resume signal to start Cobalt from preload."""
Expand Down
35 changes: 31 additions & 4 deletions cobalt/worker/service_worker_jobs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@

#include "cobalt/worker/service_worker_jobs.h"

#include <vector>

#include "base/bind.h"
#include "base/command_line.h"
#include "base/strings/stringprintf.h"
#include "base/task/current_thread.h"
#include "base/time/time.h"
Expand All @@ -25,12 +28,20 @@
#include "cobalt/worker/extendable_event.h"
#include "net/base/mime_util.h"
#include "net/base/url_util.h"
#if !defined(COBALT_BUILD_TYPE_GOLD)
#include "base/strings/pattern.h"
#endif

namespace cobalt {
namespace worker {

namespace {

#if !defined(COBALT_BUILD_TYPE_GOLD)
const char kUnsafelyTreatInsecureOriginAsSecure[] =
"unsafely-treat-insecure-origin-as-secure";
#endif

bool PathContainsEscapedSlash(const GURL& url) {
const std::string path = url.path();
return (path.find("%2f") != std::string::npos ||
Expand Down Expand Up @@ -73,11 +84,27 @@ bool IsOriginPotentiallyTrustworthy(const GURL& url) {
// authenticated, return "Potentially Trustworthy".
if (url.SchemeIs("h5vcc-embedded")) return true;

// 8. If origin has been configured as a trustworthy origin, return
// "Potentially Trustworthy".
if (origin.host() == "web-platform.test") {
return true;
// 8. If origin has been configured as a trustworthy origin, return
// "Potentially Trustworthy".
#if !defined(COBALT_BUILD_TYPE_GOLD)
const base::CommandLine& command_line =
*base::CommandLine::ForCurrentProcess();
if (command_line.HasSwitch(kUnsafelyTreatInsecureOriginAsSecure)) {
std::string origins_str =
command_line.GetSwitchValueASCII(kUnsafelyTreatInsecureOriginAsSecure);
std::vector<std::string> allowlist = base::SplitString(
origins_str, ";", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
if (base::Contains(allowlist, origin.Serialize())) {
return true;
}

for (const std::string& origin_or_pattern : allowlist) {
if (base::MatchPattern(origin.host(), origin_or_pattern)) {
return true;
}
}
}
#endif

// 9. Return "Not Trustworthy".
return false;
Expand Down
9 changes: 0 additions & 9 deletions starboard/android/arm/cobalt/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,6 @@
'suspend_visibility',
'timer_hit_after_preload',
'timer_hit_in_preload',
'service_worker_add_to_cache_test',
'service_worker_cache_keys_test',
'service_worker_controller_activation_test',
'service_worker_get_registrations_test',
'service_worker_fetch_main_resource_test',
'service_worker_fetch_test',
'service_worker_message_test',
'service_worker_post_message_test',
'service_worker_test',
'service_worker_persist_test',
'deep_links',
'web_platform_tests',
Expand Down

0 comments on commit c3993f4

Please sign in to comment.