Commit 88af5cdf authored by Omar Morsi's avatar Omar Morsi Committed by Commit Bot

Automate platform keys test extension packing

This CL automate the packing of the enterprise platform keys test
extension such that running
google-chrome-stable --pack-extension=<test_extension_path>
--pack-extension-key=<test_extension_private_key_path>
to update the crx file after changing tests is not needed as the
crx file will automatically be created before the tests run in
the SetUp() function.

reflected while running the tests without manually regenerating the crx
file.

Bug: chromium:716027
Test: Manual. Made some changes in the tests and made sure they are
Change-Id: I3309b54d717d112ab41ee8cac6db78aa4a11cf78
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2035898
Commit-Queue: Omar Morsi <omorsi@google.com>
Reviewed-by: default avatarMaksim Ivanov <emaxx@chromium.org>
Cr-Commit-Position: refs/heads/master@{#739368}
parent 0dcef84f
...@@ -6,8 +6,12 @@ ...@@ -6,8 +6,12 @@
#include <stddef.h> #include <stddef.h>
#include <memory> #include <memory>
#include <string>
#include "base/bind.h" #include "base/bind.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/path_service.h" #include "base/path_service.h"
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/stl_util.h" #include "base/stl_util.h"
...@@ -23,6 +27,7 @@ ...@@ -23,6 +27,7 @@
#include "crypto/scoped_test_system_nss_key_slot.h" #include "crypto/scoped_test_system_nss_key_slot.h"
#include "extensions/browser/extension_registry.h" #include "extensions/browser/extension_registry.h"
#include "net/cert/nss_cert_database.h" #include "net/cert/nss_cert_database.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
...@@ -102,9 +107,6 @@ const unsigned char privateKeyPkcs8System[] = { ...@@ -102,9 +107,6 @@ const unsigned char privateKeyPkcs8System[] = {
0xb5, 0x6f, 0xe9, 0x1b, 0x32, 0x91, 0x34, 0x38 0xb5, 0x6f, 0xe9, 0x1b, 0x32, 0x91, 0x34, 0x38
}; };
const char kUpdateManifestPath[] =
"/extensions/api_test/enterprise_platform_keys/update_manifest.xml";
void ImportPrivateKeyPKCS8ToSlot(const unsigned char* pkcs8_der, void ImportPrivateKeyPKCS8ToSlot(const unsigned char* pkcs8_der,
size_t pkcs8_der_size, size_t pkcs8_der_size,
PK11SlotInfo* slot) { PK11SlotInfo* slot) {
...@@ -131,6 +133,13 @@ void ImportPrivateKeyPKCS8ToSlot(const unsigned char* pkcs8_der, ...@@ -131,6 +133,13 @@ void ImportPrivateKeyPKCS8ToSlot(const unsigned char* pkcs8_der,
// its extension ID is well-known and the policy system can push policies for // its extension ID is well-known and the policy system can push policies for
// the extension. // the extension.
const char kTestExtensionID[] = "aecpbnckhoppanpmefllkdkohionpmig"; const char kTestExtensionID[] = "aecpbnckhoppanpmefllkdkohionpmig";
const char kTestExtensionUpdateManifest[] =
R"(<?xml version='1.0' encoding='UTF-8'?>
<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>
<app appid='$1'>
<updatecheck codebase='$2' version='0.1' />
</app>
</gupdate>)";
struct Params { struct Params {
Params(PlatformKeysTestBase::SystemTokenStatus system_token_status, Params(PlatformKeysTestBase::SystemTokenStatus system_token_status,
...@@ -163,7 +172,23 @@ class EnterprisePlatformKeysTest ...@@ -163,7 +172,23 @@ class EnterprisePlatformKeysTest
} }
void SetUpOnMainThread() override { void SetUpOnMainThread() override {
policy_test_utils::SetUpEmbeddedTestServer(embedded_test_server()); ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
embedded_test_server()->ServeFilesFromDirectory(temp_dir_.GetPath());
crx_path_ = temp_dir_.GetPath().Append(kCrxFileName);
update_manifest_path_ = temp_dir_.GetPath().Append(kUpdateManifestFileName);
extension_path_ = test_data_dir_.Append(kExtensionDirName);
pem_path_ = test_data_dir_.Append(kPemFileName);
base::FilePath created_crx_path =
PackExtensionWithOptions(extension_path_, crx_path_, pem_path_,
/*pem_out_path=*/base::FilePath());
ASSERT_EQ(created_crx_path, crx_path_);
GenerateUpdateManifestFile();
PlatformKeysTestBase::SetUpOnMainThread(); PlatformKeysTestBase::SetUpOnMainThread();
} }
...@@ -177,6 +202,10 @@ class EnterprisePlatformKeysTest ...@@ -177,6 +202,10 @@ class EnterprisePlatformKeysTest
done_callback.Run(); done_callback.Run();
} }
protected:
const std::string kUpdateManifestFileName =
"enterprise_platform_keys_update_manifest.xml";
private: private:
void PrepareTestSystemSlotOnIO( void PrepareTestSystemSlotOnIO(
crypto::ScopedTestSystemNSSKeySlot* system_slot) override { crypto::ScopedTestSystemNSSKeySlot* system_slot) override {
...@@ -187,6 +216,29 @@ class EnterprisePlatformKeysTest ...@@ -187,6 +216,29 @@ class EnterprisePlatformKeysTest
system_slot->slot()); system_slot->slot());
} }
void GenerateUpdateManifestFile() {
const std::string kContent = base::ReplaceStringPlaceholders(
kTestExtensionUpdateManifest,
{kTestExtensionID,
embedded_test_server()->GetURL("/" + kCrxFileName).spec().c_str()},
/*offsets=*/nullptr);
int written_bytes = base::WriteFile(update_manifest_path_, kContent.data(),
kContent.size());
ASSERT_EQ(written_bytes, static_cast<int>(kContent.length()));
}
const std::string kCrxFileName = "enterprise_platform_keys.crx";
const std::string kExtensionDirName = "enterprise_platform_keys";
const std::string kPemFileName = "enterprise_platform_keys.pem";
base::FilePath crx_path_;
base::FilePath extension_path_;
base::FilePath pem_path_;
base::FilePath update_manifest_path_;
base::ScopedTempDir temp_dir_;
DISALLOW_COPY_AND_ASSIGN(EnterprisePlatformKeysTest); DISALLOW_COPY_AND_ASSIGN(EnterprisePlatformKeysTest);
}; };
...@@ -207,8 +259,9 @@ IN_PROC_BROWSER_TEST_P(EnterprisePlatformKeysTest, Basic) { ...@@ -207,8 +259,9 @@ IN_PROC_BROWSER_TEST_P(EnterprisePlatformKeysTest, Basic) {
loop.Run(); loop.Run();
} }
policy_test_utils::SetExtensionInstallForcelistPolicy( policy_test_utils::SetExtensionInstallForcelistPolicy(
kTestExtensionID, embedded_test_server()->GetURL(kUpdateManifestPath), kTestExtensionID,
profile(), mock_policy_provider()); embedded_test_server()->GetURL("/" + kUpdateManifestFileName), profile(),
mock_policy_provider());
// By default, the system token is disabled. // By default, the system token is disabled.
std::string system_token_availability = ""; std::string system_token_availability = "";
......
...@@ -2,9 +2,6 @@ ...@@ -2,9 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// Must be packed to ../enterprise_platform_keys.crx using the private key
// ../enterprise_platform_keys.pem .
'use strict'; 'use strict';
var systemTokenEnabled = (location.href.indexOf("systemTokenEnabled") != -1); var systemTokenEnabled = (location.href.indexOf("systemTokenEnabled") != -1);
......
<?xml version='1.0' encoding='UTF-8'?>
<!--
This update manifest points to the enterprise_platform_keys.crx file.
"mock.http" is a placeholder that gets substituted with the test server
address in runtime.
-->
<gupdate xmlns='http://www.google.com/update2/response' protocol='2.0'>
<app appid='aecpbnckhoppanpmefllkdkohionpmig'>
<updatecheck
codebase='http://mock.http/extensions/api_test/enterprise_platform_keys.crx'
version='1.0.0.0' />
</app>
</gupdate>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment