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 6, 2024
1 parent 86ca328 commit 7409eeb
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 16 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
17 changes: 16 additions & 1 deletion cobalt/tools/automated_testing/cobalt_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,23 @@ def __init__(self,
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)
for target_param in self.launcher_params.target_params:
if target_param not in self.target_params:
self.target_params.append(target_param)

if hasattr(self, 'url') and self.url.startswith('http://'):
url_base = 'http://' + self.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 7409eeb

Please sign in to comment.