1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608
|
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/chromeos/extensions/device_local_account_management_policy_provider.h"
#include <string>
#include <utility>
#include "base/files/file_path.h"
#include "base/memory/ptr_util.h"
#include "base/memory/ref_counted.h"
#include "base/strings/string16.h"
#include "base/values.h"
#include "extensions/common/extension.h"
#include "extensions/common/manifest.h"
#include "extensions/common/manifest_constants.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace chromeos {
namespace {
const char kWhitelistedId[] = "cbkkbcmdlboombapidmoeolnmdacpkch";
scoped_refptr<const extensions::Extension> CreateExtensionFromValues(
const std::string& id,
extensions::Manifest::Location location,
base::DictionaryValue* values,
int flags) {
values->SetString(extensions::manifest_keys::kName, "test");
values->SetString(extensions::manifest_keys::kVersion, "0.1");
std::string error;
return extensions::Extension::Create(base::FilePath(),
location,
*values,
flags,
id,
&error);
}
scoped_refptr<const extensions::Extension> CreateRegularExtension(
const std::string& id) {
base::DictionaryValue values;
return CreateExtensionFromValues(id,
extensions::Manifest::INTERNAL,
&values,
extensions::Extension::NO_FLAGS);
}
scoped_refptr<const extensions::Extension> CreateExternalComponentExtension() {
base::DictionaryValue values;
return CreateExtensionFromValues(std::string(),
extensions::Manifest::EXTERNAL_COMPONENT,
&values,
extensions::Extension::NO_FLAGS);
}
scoped_refptr<const extensions::Extension> CreateHostedApp() {
base::DictionaryValue values;
values.Set(extensions::manifest_keys::kApp, new base::DictionaryValue);
values.Set(extensions::manifest_keys::kWebURLs, new base::ListValue);
return CreateExtensionFromValues(std::string(),
extensions::Manifest::INTERNAL,
&values,
extensions::Extension::NO_FLAGS);
}
scoped_refptr<const extensions::Extension> CreatePlatformAppWithExtraValues(
const base::DictionaryValue* extra_values,
extensions::Manifest::Location location,
int flags) {
base::DictionaryValue values;
values.SetString("app.background.page", "background.html");
values.MergeDictionary(extra_values);
return CreateExtensionFromValues(std::string(), location, &values, flags);
}
scoped_refptr<const extensions::Extension> CreatePlatformApp() {
base::DictionaryValue values;
return CreatePlatformAppWithExtraValues(&values,
extensions::Manifest::INTERNAL,
extensions::Extension::NO_FLAGS);
}
} // namespace
TEST(DeviceLocalAccountManagementPolicyProviderTest, PublicSession) {
DeviceLocalAccountManagementPolicyProvider
provider(policy::DeviceLocalAccount::TYPE_PUBLIC_SESSION);
// Verify that if an extension's location has been whitelisted for use in
// public sessions, the extension can be installed.
scoped_refptr<const extensions::Extension> extension =
CreateExternalComponentExtension();
ASSERT_TRUE(extension.get());
base::string16 error;
EXPECT_TRUE(provider.UserMayLoad(extension.get(), &error));
EXPECT_EQ(base::string16(), error);
error.clear();
// Verify that if an extension's type has been whitelisted for use in
// device-local accounts, the extension can be installed.
extension = CreateHostedApp();
ASSERT_TRUE(extension.get());
EXPECT_TRUE(provider.UserMayLoad(extension.get(), &error));
EXPECT_EQ(base::string16(), error);
error.clear();
// Verify that if an extension's ID has been explicitly whitelisted for use in
// device-local accounts, the extension can be installed.
extension = CreateRegularExtension(kWhitelistedId);
ASSERT_TRUE(extension.get());
EXPECT_TRUE(provider.UserMayLoad(extension.get(), &error));
EXPECT_EQ(base::string16(), error);
error.clear();
// Verify that if neither the location, type nor the ID of an extension have
// been whitelisted for use in public sessions, the extension cannot be
// installed.
extension = CreateRegularExtension(std::string());
ASSERT_TRUE(extension.get());
EXPECT_FALSE(provider.UserMayLoad(extension.get(), &error));
EXPECT_NE(base::string16(), error);
error.clear();
// Verify that a minimal platform app can be installed from location
// EXTERNAL_POLICY.
{
base::DictionaryValue values;
extension = CreatePlatformAppWithExtraValues(
&values,
extensions::Manifest::EXTERNAL_POLICY,
extensions::Extension::NO_FLAGS);
ASSERT_TRUE(extension);
EXPECT_TRUE(provider.UserMayLoad(extension.get(), &error));
EXPECT_EQ(base::string16(), error);
error.clear();
}
// Verify that a minimal platform app can be installed from location
// EXTERNAL_POLICY_DOWNLOAD.
{
base::DictionaryValue values;
extension = CreatePlatformAppWithExtraValues(
&values,
extensions::Manifest::EXTERNAL_POLICY_DOWNLOAD,
extensions::Extension::NO_FLAGS);
ASSERT_TRUE(extension);
EXPECT_TRUE(provider.UserMayLoad(extension.get(), &error));
EXPECT_EQ(base::string16(), error);
error.clear();
}
// Verify that a minimal platform app cannot be installed from location
// UNPACKED.
{
base::DictionaryValue values;
extension = CreatePlatformAppWithExtraValues(
&values,
extensions::Manifest::UNPACKED,
extensions::Extension::NO_FLAGS);
ASSERT_TRUE(extension);
EXPECT_FALSE(provider.UserMayLoad(extension.get(), &error));
EXPECT_NE(base::string16(), error);
error.clear();
}
// Verify that a platform app with all safe manifest entries can be installed.
{
base::DictionaryValue values;
values.SetString(extensions::manifest_keys::kDescription, "something");
values.SetString(extensions::manifest_keys::kShortName, "something else");
base::ListValue* permissions = new base::ListValue();
permissions->AppendString("alarms");
permissions->AppendString("background");
values.Set(extensions::manifest_keys::kPermissions, permissions);
base::ListValue* optional_permissions = new base::ListValue();
optional_permissions->AppendString("alarms");
optional_permissions->AppendString("background");
values.Set(extensions::manifest_keys::kOptionalPermissions,
optional_permissions);
extension = CreatePlatformAppWithExtraValues(
&values,
extensions::Manifest::EXTERNAL_POLICY,
extensions::Extension::NO_FLAGS);
ASSERT_TRUE(extension);
EXPECT_TRUE(provider.UserMayLoad(extension.get(), &error));
EXPECT_EQ(base::string16(), error);
error.clear();
}
// Verify that a platform app with an unknown manifest entry cannot be
// installed.
{
base::DictionaryValue values;
values.SetString("not_whitelisted", "something");
extension = CreatePlatformAppWithExtraValues(
&values,
extensions::Manifest::EXTERNAL_POLICY,
extensions::Extension::NO_FLAGS);
ASSERT_TRUE(extension);
EXPECT_FALSE(provider.UserMayLoad(extension.get(), &error));
EXPECT_NE(base::string16(), error);
error.clear();
}
// Verify that a platform app with an unsafe manifest entry cannot be
// installed. Since the program logic is based entirely on whitelists, there
// is no significant advantage in testing all unsafe manifest entries
// individually.
{
base::DictionaryValue values;
values.Set("chrome_settings_overrides", new base::DictionaryValue());
extension = CreatePlatformAppWithExtraValues(
&values,
extensions::Manifest::EXTERNAL_POLICY,
extensions::Extension::NO_FLAGS);
ASSERT_TRUE(extension);
EXPECT_FALSE(provider.UserMayLoad(extension.get(), &error));
EXPECT_NE(base::string16(), error);
error.clear();
}
// Verify that a platform app with an unknown manifest entry under "app"
// cannot be installed.
{
base::DictionaryValue values;
values.SetString("app.not_whitelisted2", "something2");
extension = CreatePlatformAppWithExtraValues(
&values,
extensions::Manifest::EXTERNAL_POLICY,
extensions::Extension::NO_FLAGS);
ASSERT_TRUE(extension);
EXPECT_FALSE(provider.UserMayLoad(extension.get(), &error));
EXPECT_NE(base::string16(), error);
error.clear();
}
// Verify that a platform app with a safe manifest entry under "app" can be
// installed.
{
base::DictionaryValue values;
values.SetString("app.content_security_policy", "something2");
extension = CreatePlatformAppWithExtraValues(
&values,
extensions::Manifest::EXTERNAL_POLICY,
extensions::Extension::NO_FLAGS);
ASSERT_TRUE(extension);
EXPECT_TRUE(provider.UserMayLoad(extension.get(), &error));
EXPECT_EQ(base::string16(), error);
error.clear();
}
// Verify that a hosted app with a safe manifest entry under "app" can be
// installed.
{
base::DictionaryValue values;
values.Set(extensions::manifest_keys::kApp, new base::DictionaryValue);
values.Set(extensions::manifest_keys::kWebURLs, new base::ListValue);
values.SetString("app.content_security_policy", "something2");
extension = CreateExtensionFromValues(
std::string(),
extensions::Manifest::EXTERNAL_POLICY,
&values,
extensions::Extension::NO_FLAGS);
ASSERT_TRUE(extension);
EXPECT_TRUE(provider.UserMayLoad(extension.get(), &error));
EXPECT_EQ(base::string16(), error);
error.clear();
}
// Verify that a theme with a safe manifest entry under "app" cannot be
// installed.
{
base::DictionaryValue values;
values.Set("theme", new base::DictionaryValue());
values.SetString("app.content_security_policy", "something2");
extension = CreateExtensionFromValues(
std::string(),
extensions::Manifest::EXTERNAL_POLICY,
&values,
extensions::Extension::NO_FLAGS);
ASSERT_TRUE(extension);
EXPECT_FALSE(provider.UserMayLoad(extension.get(), &error));
EXPECT_NE(base::string16(), error);
error.clear();
}
// Verify that a platform app with an unknown permission entry cannot be
// installed.
{
base::ListValue* const permissions = new base::ListValue();
permissions->AppendString("not_whitelisted_permission");
base::DictionaryValue values;
values.Set(extensions::manifest_keys::kPermissions, permissions);
extension = CreatePlatformAppWithExtraValues(
&values,
extensions::Manifest::EXTERNAL_POLICY,
extensions::Extension::NO_FLAGS);
ASSERT_TRUE(extension);
EXPECT_FALSE(provider.UserMayLoad(extension.get(), &error));
EXPECT_NE(base::string16(), error);
error.clear();
}
// Verify that a platform app with an unsafe permission entry cannot be
// installed. Since the program logic is based entirely on whitelists, there
// is no significant advantage in testing all unsafe permissions individually.
{
base::ListValue* const permissions = new base::ListValue();
permissions->AppendString("experimental");
base::DictionaryValue values;
values.Set(extensions::manifest_keys::kPermissions, permissions);
extension = CreatePlatformAppWithExtraValues(
&values,
extensions::Manifest::EXTERNAL_POLICY,
extensions::Extension::NO_FLAGS);
ASSERT_TRUE(extension);
EXPECT_FALSE(provider.UserMayLoad(extension.get(), &error));
EXPECT_NE(base::string16(), error);
error.clear();
}
// Verify that a platform app with an unsafe optional permission entry cannot
// be installed.
{
base::ListValue* const permissions = new base::ListValue();
permissions->AppendString("experimental");
base::DictionaryValue values;
values.Set(extensions::manifest_keys::kOptionalPermissions, permissions);
extension = CreatePlatformAppWithExtraValues(
&values,
extensions::Manifest::EXTERNAL_POLICY,
extensions::Extension::NO_FLAGS);
ASSERT_TRUE(extension);
EXPECT_FALSE(provider.UserMayLoad(extension.get(), &error));
EXPECT_NE(base::string16(), error);
error.clear();
}
// Verify that a platform app with an url_handlers manifest entry and which is
// not installed through the web store cannot be installed.
{
base::ListValue* const matches = new base::ListValue();
matches->AppendString("https://example.com/*");
base::DictionaryValue values;
values.Set("url_handlers.example_com.matches", matches);
values.SetString("url_handlers.example_com.title", "example title");
extension = CreatePlatformAppWithExtraValues(
&values,
extensions::Manifest::EXTERNAL_POLICY,
extensions::Extension::NO_FLAGS);
ASSERT_TRUE(extension);
EXPECT_FALSE(provider.UserMayLoad(extension.get(), &error));
EXPECT_NE(base::string16(), error);
error.clear();
}
// Verify that a platform app with a url_handlers manifest entry and which is
// installed through the web store can be installed.
{
base::ListValue* const matches = new base::ListValue();
matches->AppendString("https://example.com/*");
base::DictionaryValue values;
values.Set("url_handlers.example_com.matches", matches);
values.SetString("url_handlers.example_com.title", "example title");
extension = CreatePlatformAppWithExtraValues(
&values,
extensions::Manifest::EXTERNAL_POLICY,
extensions::Extension::FROM_WEBSTORE);
ASSERT_TRUE(extension);
EXPECT_TRUE(provider.UserMayLoad(extension.get(), &error));
EXPECT_EQ(base::string16(), error);
error.clear();
}
// Verify that a platform app with remote URL permissions can be installed.
{
base::ListValue* const permissions = new base::ListValue();
permissions->AppendString("https://example.com/");
permissions->AppendString("http://example.com/");
permissions->AppendString("ftp://example.com/");
base::DictionaryValue values;
values.Set(extensions::manifest_keys::kPermissions, permissions);
extension = CreatePlatformAppWithExtraValues(
&values,
extensions::Manifest::EXTERNAL_POLICY,
extensions::Extension::NO_FLAGS);
ASSERT_TRUE(extension);
EXPECT_TRUE(provider.UserMayLoad(extension.get(), &error));
EXPECT_EQ(base::string16(), error);
error.clear();
}
// Verify that an extension with remote URL permissions cannot be installed.
{
base::ListValue* const permissions = new base::ListValue();
permissions->AppendString("https://example.com/");
permissions->AppendString("http://example.com/");
permissions->AppendString("ftp://example.com/");
base::DictionaryValue values;
values.Set(extensions::manifest_keys::kPermissions, permissions);
extension = CreateExtensionFromValues(
std::string(),
extensions::Manifest::EXTERNAL_POLICY,
&values,
extensions::Extension::NO_FLAGS);
ASSERT_TRUE(extension);
EXPECT_FALSE(provider.UserMayLoad(extension.get(), &error));
EXPECT_NE(base::string16(), error);
error.clear();
}
// Verify that a platform app with a local URL permission cannot be installed.
{
base::ListValue* const permissions = new base::ListValue();
permissions->AppendString("file:///some/where");
base::DictionaryValue values;
values.Set(extensions::manifest_keys::kPermissions, permissions);
extension = CreatePlatformAppWithExtraValues(
&values,
extensions::Manifest::EXTERNAL_POLICY,
extensions::Extension::NO_FLAGS);
ASSERT_TRUE(extension);
EXPECT_FALSE(provider.UserMayLoad(extension.get(), &error));
EXPECT_NE(base::string16(), error);
error.clear();
}
// Verify that a platform app with socket dictionary permission can be
// installed.
{
auto socket = base::MakeUnique<base::DictionaryValue>();
base::ListValue* const tcp_list = new base::ListValue();
tcp_list->AppendString("tcp-connect");
socket->Set("socket", tcp_list);
base::ListValue* const permissions = new base::ListValue();
permissions->Append(std::move(socket));
base::DictionaryValue values;
values.Set(extensions::manifest_keys::kPermissions, permissions);
extension = CreatePlatformAppWithExtraValues(
&values,
extensions::Manifest::EXTERNAL_POLICY,
extensions::Extension::NO_FLAGS);
ASSERT_TRUE(extension);
EXPECT_TRUE(provider.UserMayLoad(extension.get(), &error));
EXPECT_EQ(base::string16(), error);
error.clear();
}
// Verify that a platform app with unknown dictionary permission cannot be
// installed.
{
auto socket = base::MakeUnique<base::DictionaryValue>();
base::ListValue* const tcp_list = new base::ListValue();
tcp_list->AppendString("unknown_value");
socket->Set("unknown_key", tcp_list);
base::ListValue* const permissions = new base::ListValue();
permissions->Append(std::move(socket));
base::DictionaryValue values;
values.Set(extensions::manifest_keys::kPermissions, permissions);
extension = CreatePlatformAppWithExtraValues(
&values,
extensions::Manifest::EXTERNAL_POLICY,
extensions::Extension::NO_FLAGS);
ASSERT_TRUE(extension);
EXPECT_FALSE(provider.UserMayLoad(extension.get(), &error));
EXPECT_NE(base::string16(), error);
error.clear();
}
// Verify that an extension can be installed.
{
base::DictionaryValue values;
extension = CreateExtensionFromValues(
std::string(),
extensions::Manifest::EXTERNAL_POLICY,
&values,
extensions::Extension::NO_FLAGS);
ASSERT_TRUE(extension);
EXPECT_TRUE(provider.UserMayLoad(extension.get(), &error));
EXPECT_EQ(base::string16(), error);
error.clear();
}
// Verify that a shared_module can be installed.
{
base::DictionaryValue values;
values.Set("export.whitelist", new base::ListValue());
extension = CreateExtensionFromValues(
std::string(),
extensions::Manifest::EXTERNAL_POLICY,
&values,
extensions::Extension::NO_FLAGS);
ASSERT_TRUE(extension);
EXPECT_TRUE(provider.UserMayLoad(extension.get(), &error));
EXPECT_EQ(base::string16(), error);
error.clear();
}
// Verify that a theme can be installed.
{
base::DictionaryValue values;
values.Set("theme", new base::DictionaryValue());
extension = CreateExtensionFromValues(
std::string(),
extensions::Manifest::EXTERNAL_POLICY,
&values,
extensions::Extension::NO_FLAGS);
ASSERT_TRUE(extension);
EXPECT_TRUE(provider.UserMayLoad(extension.get(), &error));
EXPECT_EQ(base::string16(), error);
error.clear();
}
// Verify that a legacy_packaged_app cannot be installed and that it cannot
// have an "app" manifest entry.
{
base::DictionaryValue values;
values.SetString("app.launch.local_path", "something");
extension = CreateExtensionFromValues(
std::string(),
extensions::Manifest::EXTERNAL_POLICY,
&values,
extensions::Extension::NO_FLAGS);
ASSERT_TRUE(extension);
EXPECT_FALSE(provider.UserMayLoad(extension.get(), &error));
EXPECT_NE(base::string16(), error);
error.clear();
}
}
TEST(DeviceLocalAccountManagementPolicyProviderTest, KioskAppSession) {
DeviceLocalAccountManagementPolicyProvider
provider(policy::DeviceLocalAccount::TYPE_KIOSK_APP);
// Verify that a platform app can be installed.
scoped_refptr<const extensions::Extension> extension = CreatePlatformApp();
ASSERT_TRUE(extension.get());
base::string16 error;
EXPECT_TRUE(provider.UserMayLoad(extension.get(), &error));
EXPECT_EQ(base::string16(), error);
error.clear();
// Verify that an extension whose location has been whitelisted for use in
// other types of device-local accounts cannot be installed in a single-app
// kiosk session.
extension = CreateExternalComponentExtension();
ASSERT_TRUE(extension.get());
EXPECT_TRUE(provider.UserMayLoad(extension.get(), &error));
EXPECT_EQ(base::string16(), error);
error.clear();
// Verify that an extension whose type has been whitelisted for use in other
// types of device-local accounts cannot be installed in a single-app kiosk
// session.
extension = CreateHostedApp();
ASSERT_TRUE(extension.get());
EXPECT_FALSE(provider.UserMayLoad(extension.get(), &error));
EXPECT_NE(base::string16(), error);
error.clear();
// Verify that an extension whose ID has been whitelisted for use in other
// types of device-local accounts cannot be installed in a single-app kiosk
// session.
extension = CreateRegularExtension(kWhitelistedId);
ASSERT_TRUE(extension.get());
EXPECT_TRUE(provider.UserMayLoad(extension.get(), &error));
EXPECT_EQ(base::string16(), error);
error.clear();
}
} // namespace chromeos
|