From 6a6164ab4f1c311a8f9662bd6e8a8bc082dad276 Mon Sep 17 00:00:00 2001 From: Filipe Silva Date: Thu, 19 Oct 2017 19:15:44 +0100 Subject: [PATCH 1/7] revert: ci: use chrome stable (#18307) This reverts commit 8bcb268140c1ec64093761de57200501ee65df61. --- .travis.yml | 2 - aio/scripts/test-pwa-score.js | 5 ++ .../examples/shared/protractor.config.js | 6 +- scripts/ci/env.sh | 2 + scripts/ci/install-chromium.sh | 84 +++++++++++++++++++ scripts/ci/install.sh | 20 +++-- 6 files changed, 111 insertions(+), 8 deletions(-) create mode 100755 scripts/ci/install-chromium.sh diff --git a/.travis.yml b/.travis.yml index 9d7d2526d7440..b71170795be8e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,12 +1,10 @@ language: node_js sudo: false -# force trusty as Google Chrome addon is not supported on Precise dist: trusty node_js: - '6.9.5' addons: - chrome: stable # firefox: "38.0" apt: sources: diff --git a/aio/scripts/test-pwa-score.js b/aio/scripts/test-pwa-score.js index a53e1b28b26d0..388d76651d233 100644 --- a/aio/scripts/test-pwa-score.js +++ b/aio/scripts/test-pwa-score.js @@ -19,6 +19,11 @@ const config = require('lighthouse/lighthouse-core/config/default.js'); // Constants const VIEWER_URL = 'https://googlechrome.github.io/lighthouse/viewer/'; +// Specify the path to Chrome on Travis +if (process.env.TRAVIS) { + process.env.LIGHTHOUSE_CHROMIUM_PATH = process.env.CHROME_BIN; +} + // Run _main(process.argv.slice(2)); diff --git a/aio/tools/examples/shared/protractor.config.js b/aio/tools/examples/shared/protractor.config.js index 21b54feb8bc4b..b5c090e2dfa78 100644 --- a/aio/tools/examples/shared/protractor.config.js +++ b/aio/tools/examples/shared/protractor.config.js @@ -20,7 +20,11 @@ exports.config = { // Capabilities to be passed to the webdriver instance. capabilities: { - 'browserName': 'chrome' + 'browserName': 'chrome', + // For Travis + chromeOptions: { + binary: process.env.CHROME_BIN + } }, // Framework to use. Jasmine is recommended. diff --git a/scripts/ci/env.sh b/scripts/ci/env.sh index a226c289f9b4e..adcfc73633910 100755 --- a/scripts/ci/env.sh +++ b/scripts/ci/env.sh @@ -36,6 +36,7 @@ fi setEnvVar NODE_VERSION 6.9.5 setEnvVar YARN_VERSION 1.0.2 +setEnvVar CHROMIUM_VERSION 499098 # Chrome 62 linux stable, see https://www.chromium.org/developers/calendar setEnvVar SAUCE_CONNECT_VERSION 4.4.9 setEnvVar PROJECT_ROOT $(cd ${thisDir}/../..; pwd) @@ -101,6 +102,7 @@ if [[ ${TRAVIS:-} ]]; then setEnvVar BROWSER_STACK_USERNAME angularteam1 # not using use setEnvVar so that we don't print the key export BROWSER_STACK_ACCESS_KEY=BWCd4SynLzdDcv8xtzsB + setEnvVar CHROME_BIN ${HOME}/.chrome/chromium/chrome-linux/chrome setEnvVar BROWSER_PROVIDER_READY_FILE /tmp/angular-build/browser-provider-tunnel-init.lock fi diff --git a/scripts/ci/install-chromium.sh b/scripts/ci/install-chromium.sh new file mode 100755 index 0000000000000..c18f3c9f7f51a --- /dev/null +++ b/scripts/ci/install-chromium.sh @@ -0,0 +1,84 @@ +#!/usr/bin/env bash + +set -u -e -o pipefail + +# Setup environment +readonly thisDir=$(cd $(dirname $0); pwd) +source ${thisDir}/_travis-fold.sh + + +# This script basically follows the instructions to download an old version of Chromium: https://www.chromium.org/getting-involved/download-chromium +# 1) It retrieves the current stable version number from https://www.chromium.org/developers/calendar (via the https://omahaproxy.appspot.com/all file), e.g. 359700 for Chromium 48. +# 2) It checks the Travis cache for this specific version +# 3) If not available, it downloads and caches it, using the "decrement commit number" trick. + +#Build version read from the OmahaProxy CSV Viewer at https://www.chromium.org/developers/calendar +#Let's use the following version of Chromium, and inform about availability of newer build from https://omahaproxy.appspot.com/all +# +# CHROMIUM_VERSION <<< this variable is now set via env.sh + +PLATFORM="$(uname -s)" +case "$PLATFORM" in + (Darwin) + ARCHITECTURE=Mac + DIST_FILE=chrome-mac.zip + ;; + (Linux) + ARCHITECTURE=Linux_x64 + DIST_FILE=chrome-linux.zip + ;; + (*) + echo Unsupported platform $PLATFORM. Exiting ... >&2 + exit 3 + ;; +esac + +TMP=$(curl -s "https://omahaproxy.appspot.com/all") || true +oldIFS="$IFS" +IFS=' +' +IFS=${IFS:0:1} +lines=( $TMP ) +IFS=',' +for line in "${lines[@]}" + do + lineArray=($line); + if [ "${lineArray[0]}" = "linux" ] && [ "${lineArray[1]}" = "stable" ] ; then + LATEST_CHROMIUM_VERSION="${lineArray[7]}" + fi +done +IFS="$oldIFS" + +CHROMIUM_DIR=$HOME/.chrome/chromium +CHROMIUM_BIN=$CHROMIUM_DIR/chrome-linux/chrome +CHROMIUM_VERSION_FILE=$CHROMIUM_DIR/VERSION + +EXISTING_VERSION="" +if [[ -f $CHROMIUM_VERSION_FILE && -x $CHROMIUM_BIN ]]; then + EXISTING_VERSION=`cat $CHROMIUM_VERSION_FILE` + echo Found cached Chromium version: ${EXISTING_VERSION} +fi + +if [[ "$EXISTING_VERSION" != "$CHROMIUM_VERSION" ]]; then + echo Downloading Chromium version: ${CHROMIUM_VERSION} + rm -fR $CHROMIUM_DIR + mkdir -p $CHROMIUM_DIR + + NEXT=$CHROMIUM_VERSION + FILE="chrome-linux.zip" + STATUS=404 + while [[ $STATUS == 404 && $NEXT -ge 0 ]] + do + echo Fetch Chromium version: ${NEXT} + STATUS=$(curl "https://storage.googleapis.com/chromium-browser-snapshots/${ARCHITECTURE}/${NEXT}/${DIST_FILE}" -s -w %{http_code} --create-dirs -o $FILE) || true + NEXT=$[$NEXT-1] + done + + unzip $FILE -d $CHROMIUM_DIR + rm $FILE + echo $CHROMIUM_VERSION > $CHROMIUM_VERSION_FILE +fi + +if [[ "$CHROMIUM_VERSION" != "$LATEST_CHROMIUM_VERSION" ]]; then + echo "New version of Chromium available. Update install-chromium.sh with build number: ${LATEST_CHROMIUM_VERSION}" +fi diff --git a/scripts/ci/install.sh b/scripts/ci/install.sh index 095ddd9643625..74ba83fe50beb 100755 --- a/scripts/ci/install.sh +++ b/scripts/ci/install.sh @@ -64,11 +64,21 @@ if [[ ${TRAVIS} && ${CI_MODE} == "bazel" ]]; then travisFoldEnd "bazel-install" fi -# Start xvfb for local Chrome testing -if [[ ${TRAVIS} && (${CI_MODE} == "js" || ${CI_MODE} == "e2e" || ${CI_MODE} == "e2e_2" || ${CI_MODE} == "aio" || ${CI_MODE} == "aio_e2e") ]]; then - travisFoldStart "xvfb-start" - sh -e /etc/init.d/xvfb start - travisFoldEnd "xvfb-start" + +# Install Chromium +if [[ ${TRAVIS} && ${CI_MODE} == "js" || ${CI_MODE} == "e2e" || ${CI_MODE} == "e2e_2" || ${CI_MODE} == "aio" || ${CI_MODE} == "aio_e2e" ]]; then + travisFoldStart "install-chromium" + ( + ${thisDir}/install-chromium.sh + + # Start xvfb for local Chrome used for testing + if [[ ${TRAVIS} ]]; then + travisFoldStart "install-chromium.xvfb-start" + sh -e /etc/init.d/xvfb start + travisFoldEnd "install-chromium.xvfb-start" + fi + ) + travisFoldEnd "install-chromium" fi From 1d9024ee9a98039daee177c881c37bf0b5a79222 Mon Sep 17 00:00:00 2001 From: George Kalpakas Date: Mon, 11 Dec 2017 16:27:29 +0200 Subject: [PATCH 2/7] build: pin ChromeDriver version (#20940) Since our version of Chromium is also pinned, a new ChromeDriver (that drops support for our Chromium version) can cause random (and unrelated to the corresponding changes) errors on CI. This commit pins the version of ChromeDriver and it should now be manually upgraded to a vrsion that is compatible with th currently used Chromium version. PR Close #20940 --- aio/package.json | 2 +- aio/tools/examples/shared/package.json | 2 +- integration/hello_world__closure/package.json | 2 +- integration/hello_world__systemjs_umd/package.json | 2 +- package.json | 3 ++- packages/platform-server/integrationtest/package.json | 3 ++- scripts/ci/env.sh | 3 ++- scripts/ci/install.sh | 8 +------- 8 files changed, 11 insertions(+), 14 deletions(-) diff --git a/aio/package.json b/aio/package.json index 0431e3d63402d..c575a860d5488 100644 --- a/aio/package.json +++ b/aio/package.json @@ -57,7 +57,7 @@ "~~check-env": "node scripts/check-environment", "~~build": "ng build --target=production --environment=stable -sm --build-optimizer", "post~~build": "yarn sw-manifest && yarn sw-copy", - "~~update-webdriver": "webdriver-manager update --standalone false --gecko false" + "~~update-webdriver": "webdriver-manager update --standalone false --gecko false $CHROMEDRIVER_VERSION_ARG" }, "engines": { "node": ">=6.9.5 <7.0.0", diff --git a/aio/tools/examples/shared/package.json b/aio/tools/examples/shared/package.json index 85ba989112e2f..9c665fc06dc81 100644 --- a/aio/tools/examples/shared/package.json +++ b/aio/tools/examples/shared/package.json @@ -6,7 +6,7 @@ "scripts": { "http-server": "http-server", "protractor": "protractor", - "webdriver:update": "webdriver-manager update --standalone false --gecko false", + "webdriver:update": "webdriver-manager update --standalone false --gecko false $CHROMEDRIVER_VERSION_ARG", "postinstall": "yarn webdriver:update" }, "keywords": [], diff --git a/integration/hello_world__closure/package.json b/integration/hello_world__closure/package.json index 51ec7029bace5..78519201cc869 100644 --- a/integration/hello_world__closure/package.json +++ b/integration/hello_world__closure/package.json @@ -23,7 +23,7 @@ "protractor": "file:../../node_modules/protractor" }, "scripts": { - "postinstall": "webdriver-manager update --gecko false", + "postinstall": "webdriver-manager update --gecko false --standalone false $CHROMEDRIVER_VERSION_ARG", "closure": "java -jar node_modules/google-closure-compiler/compiler.jar --flagfile closure.conf", "test": "ngc && yarn run closure && concurrently \"yarn run serve\" \"yarn run protractor\" --kill-others --success first", "serve": "lite-server -c e2e/browser.config.json", diff --git a/integration/hello_world__systemjs_umd/package.json b/integration/hello_world__systemjs_umd/package.json index c3b3fb42b2a1d..bc65edc9bc7ff 100644 --- a/integration/hello_world__systemjs_umd/package.json +++ b/integration/hello_world__systemjs_umd/package.json @@ -4,7 +4,7 @@ "version": "0.0.0", "license": "MIT", "scripts": { - "postinstall": "webdriver-manager update --gecko false", + "postinstall": "webdriver-manager update --gecko false --standalone false $CHROMEDRIVER_VERSION_ARG", "test": "concurrently \"npm run serve\" \"npm run protractor\" --kill-others --success first", "serve": "lite-server -c bs-config.e2e.json", "preprotractor": "tsc -p e2e", diff --git a/package.json b/package.json index e99953aacbe74..df5f92f5d256a 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,8 @@ }, "scripts": { "preinstall": "node -e \"if(process.env.npm_execpath.indexOf('yarn') === -1) throw new Error('Please use Yarn instead of NPM to install dependencies. See: https://yarnpkg.com/lang/en/docs/install/')\"", - "postinstall": "webdriver-manager update --gecko false", + "postinstall": "yarn update-webdriver", + "update-webdriver": "webdriver-manager update --gecko false $CHROMEDRIVER_VERSION_ARG", "check-env": "gulp check-env" }, "dependencies": { diff --git a/packages/platform-server/integrationtest/package.json b/packages/platform-server/integrationtest/package.json index 8f57802a956b1..9ce9f58dce9e1 100644 --- a/packages/platform-server/integrationtest/package.json +++ b/packages/platform-server/integrationtest/package.json @@ -34,10 +34,11 @@ "webpack": "^2.2.1" }, "scripts": { + "postinstall": "webdriver-manager update --gecko false --standalone false $CHROMEDRIVER_VERSION_ARG", "build": "./build.sh", "test": "npm run build && concurrently \"npm run serve\" \"npm run protractor\" --kill-others --success first", "serve": "node built/server-bundle.js", - "preprotractor": "webdriver-manager update --gecko false && tsc -p e2e", + "preprotractor": "tsc -p e2e", "protractor": "protractor e2e/protractor.config.js" } } diff --git a/scripts/ci/env.sh b/scripts/ci/env.sh index adcfc73633910..b820e90d88485 100755 --- a/scripts/ci/env.sh +++ b/scripts/ci/env.sh @@ -17,7 +17,7 @@ function setEnvVar() { if [[ ${print} == "print" ]]; then echo ${name}=${value} fi - export ${name}=${value} + export ${name}="${value}" } # use BASH_SOURCE so that we get the right path when this script is called AND source-d @@ -37,6 +37,7 @@ fi setEnvVar NODE_VERSION 6.9.5 setEnvVar YARN_VERSION 1.0.2 setEnvVar CHROMIUM_VERSION 499098 # Chrome 62 linux stable, see https://www.chromium.org/developers/calendar +setEnvVar CHROMEDRIVER_VERSION_ARG "--versions.chrome 2.33" setEnvVar SAUCE_CONNECT_VERSION 4.4.9 setEnvVar PROJECT_ROOT $(cd ${thisDir}/../..; pwd) diff --git a/scripts/ci/install.sh b/scripts/ci/install.sh index 74ba83fe50beb..20479787c9804 100755 --- a/scripts/ci/install.sh +++ b/scripts/ci/install.sh @@ -35,7 +35,7 @@ travisFoldEnd "install-yarn" # Install all npm dependencies according to yarn.lock travisFoldStart "yarn-install" - node tools/npm/check-node-modules --purge || yarn install --freeze-lockfile --non-interactive + (node tools/npm/check-node-modules --purge && yarn update-webdriver) || yarn install --frozen-lockfile --non-interactive travisFoldEnd "yarn-install" @@ -102,12 +102,6 @@ if [[ ${TRAVIS} && (${CI_MODE} == "browserstack_required" || ${CI_MODE} == "brow fi -# Install Selenium WebDriver -travisFoldStart "webdriver-manager-update" - $(npm bin)/webdriver-manager update -travisFoldEnd "webdriver-manager-update" - - # Install bower packages travisFoldStart "bower-install" $(npm bin)/bower install From e9f1d440158c8c91accbb6285a7dfa83af4fbf94 Mon Sep 17 00:00:00 2001 From: George Kalpakas Date: Thu, 7 Dec 2017 16:46:37 +0200 Subject: [PATCH 3/7] ci: downgrade Chromium to a version that does not cause flakes There seems to be some issue that causes Chrome/ChromeDriver to unexpectedly reload during the aio e2e tests, causing flakes. It is not clear what exactly is causing the reloading, but to the best of my knowledge it is something inside Chrome or ChromeDriver. Pinning Chrome to r494239 (between 62.0.3185.0 and 62.0.3186.0) fixes the flakes. Fixes #20159 --- scripts/ci/env.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scripts/ci/env.sh b/scripts/ci/env.sh index b820e90d88485..7c597f8b54a98 100755 --- a/scripts/ci/env.sh +++ b/scripts/ci/env.sh @@ -36,7 +36,9 @@ fi setEnvVar NODE_VERSION 6.9.5 setEnvVar YARN_VERSION 1.0.2 -setEnvVar CHROMIUM_VERSION 499098 # Chrome 62 linux stable, see https://www.chromium.org/developers/calendar +# Pin to a Chromium version that does not cause the aio e2e tests to flake. (See https://github.com/angular/angular/pull/20403.) +# Revision 494239 (which was part of Chrome 62.0.3186.0) is the last version that does not cause flakes. (Latest revision checked: 508578) +setEnvVar CHROMIUM_VERSION 494239 # Chrome 62 linux stable, see https://www.chromium.org/developers/calendar setEnvVar CHROMEDRIVER_VERSION_ARG "--versions.chrome 2.33" setEnvVar SAUCE_CONNECT_VERSION 4.4.9 setEnvVar PROJECT_ROOT $(cd ${thisDir}/../..; pwd) From 0dacf6d5f167963ac863559f371dd64947eb43ab Mon Sep 17 00:00:00 2001 From: George Kalpakas Date: Thu, 18 Jan 2018 20:58:40 +0200 Subject: [PATCH 4/7] ci: use `sudo: false` on Travis (#21641) Related to #21422. PR Close #21641 --- aio/karma.conf.js | 10 ++++++++-- aio/protractor.conf.js | 3 ++- aio/scripts/test-pwa-score.js | 7 +++++-- aio/tools/examples/shared/protractor.config.js | 3 ++- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/aio/karma.conf.js b/aio/karma.conf.js index c2d83c7804636..032dd4145363f 100644 --- a/aio/karma.conf.js +++ b/aio/karma.conf.js @@ -30,8 +30,14 @@ module.exports = function (config) { colors: true, logLevel: config.LOG_INFO, autoWatch: true, - browsers: ['Chrome'], + browsers: ['CustomChrome'], browserNoActivityTimeout: 60000, - singleRun: false + singleRun: false, + customLaunchers: { + CustomChrome: { + base: 'Chrome', + flags: process.env.TRAVIS && ['--no-sandbox'] + } + } }); }; diff --git a/aio/protractor.conf.js b/aio/protractor.conf.js index 1cd695135f7e2..d112804b62c95 100644 --- a/aio/protractor.conf.js +++ b/aio/protractor.conf.js @@ -12,7 +12,8 @@ exports.config = { browserName: 'chrome', // For Travis chromeOptions: { - binary: process.env.CHROME_BIN + binary: process.env.CHROME_BIN, + args: ['--no-sandbox'] } }, directConnect: true, diff --git a/aio/scripts/test-pwa-score.js b/aio/scripts/test-pwa-score.js index 388d76651d233..bf2fc2916a165 100644 --- a/aio/scripts/test-pwa-score.js +++ b/aio/scripts/test-pwa-score.js @@ -17,11 +17,14 @@ const printer = require('lighthouse/lighthouse-cli/printer'); const config = require('lighthouse/lighthouse-core/config/default.js'); // Constants +const CHROME_LAUNCH_OPTS = {}; const VIEWER_URL = 'https://googlechrome.github.io/lighthouse/viewer/'; -// Specify the path to Chrome on Travis + +// Specify the path and flags for Chrome on Travis if (process.env.TRAVIS) { process.env.LIGHTHOUSE_CHROMIUM_PATH = process.env.CHROME_BIN; + CHROME_LAUNCH_OPTS.chromeFlags = ['--no-sandbox']; } // Run @@ -71,7 +74,7 @@ function ignoreHttpsAudits(config) { } function launchChromeAndRunLighthouse(url, flags, config) { - return chromeLauncher.launch().then(chrome => { + return chromeLauncher.launch(CHROME_LAUNCH_OPTS).then(chrome => { flags.port = chrome.port; return lighthouse(url, flags, config). then(results => chrome.kill().then(() => results)). diff --git a/aio/tools/examples/shared/protractor.config.js b/aio/tools/examples/shared/protractor.config.js index b5c090e2dfa78..4e97cc1d6ae72 100644 --- a/aio/tools/examples/shared/protractor.config.js +++ b/aio/tools/examples/shared/protractor.config.js @@ -23,7 +23,8 @@ exports.config = { 'browserName': 'chrome', // For Travis chromeOptions: { - binary: process.env.CHROME_BIN + binary: process.env.CHROME_BIN, + args: ['--no-sandbox'] } }, From 2c5cf19c6d37d1e0edd9b7739d79cf52594d7f92 Mon Sep 17 00:00:00 2001 From: Peter Bacon Darwin Date: Thu, 31 Aug 2017 22:05:18 +0100 Subject: [PATCH 5/7] fix(core): use appropriate inert document strategy for Firefox & Safari (#22077) Both Firefox and Safari are vulnerable to XSS if we use an inert document created via `document.implementation.createHTMLDocument()`. Now we check for those vulnerabilities and then use a DOMParser or XHR strategy if needed. Further the platform-server has its own library for parsing HTML, so we sniff for that (by checking whether DOMParser exists) and fall back to the standard strategy. Thanks to @cure53 for the heads up on this issue. --- .../src/security/html_sanitizer.ts | 116 ++++-------- .../src/security/inert_body.ts | 171 ++++++++++++++++++ .../test/security/html_sanitizer_spec.ts | 41 +++++ 3 files changed, 248 insertions(+), 80 deletions(-) create mode 100644 packages/platform-browser/src/security/inert_body.ts diff --git a/packages/platform-browser/src/security/html_sanitizer.ts b/packages/platform-browser/src/security/html_sanitizer.ts index c0cccf3530984..7365df8813806 100644 --- a/packages/platform-browser/src/security/html_sanitizer.ts +++ b/packages/platform-browser/src/security/html_sanitizer.ts @@ -10,35 +10,9 @@ import {isDevMode} from '@angular/core'; import {DomAdapter, getDOM} from '../dom/dom_adapter'; +import {InertBodyHelper} from './inert_body'; import {sanitizeSrcset, sanitizeUrl} from './url_sanitizer'; -/** A element that can be safely used to parse untrusted HTML. Lazily initialized below. */ -let inertElement: HTMLElement|null = null; -/** Lazily initialized to make sure the DOM adapter gets set before use. */ -let DOM: DomAdapter = null !; - -/** Returns an HTML element that is guaranteed to not execute code when creating elements in it. */ -function getInertElement() { - if (inertElement) return inertElement; - DOM = getDOM(); - - // Prefer using