Skip to content

Commit

Permalink
fixes #1951, disable site isolation trials
Browse files Browse the repository at this point in the history
  • Loading branch information
brian-mann committed Jul 1, 2018
1 parent 1514e47 commit cd5fd04
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 20 deletions.
14 changes: 7 additions & 7 deletions packages/server/__snapshots__/web_security_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,12 @@ exports['e2e web security when disabled passes 1'] = `

Running: web_security_spec.coffee... (1 of 1)

Warning: Cypress can only record videos when using the built in 'electron' browser.

You have set the browser to: 'chrome'

A video will not be recorded when using this browser.


web security
✓ fails when clicking <a> to another origin
Expand All @@ -201,18 +207,12 @@ exports['e2e web security when disabled passes 1'] = `
Pending: 0
Skipped: 0
Screenshots: 0
Video: true
Video: false
Duration: X seconds │
Spec Ran: web_security_spec.coffee
└────────────────────────────────────────┘


(Video)

- Started processing: Compressing to 32 CRF
- Finished processing: /foo/bar/.projects/e2e/cypress/videos/abc123.mp4 (X seconds)


====================================================================================================

(Run Finished)
Expand Down
4 changes: 4 additions & 0 deletions packages/server/lib/browsers/chrome.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ defaultArgs = [
"--disable-device-discovery-notifications"
"--disable-blink-features=RootLayerScrolling"

## http://www.chromium.org/Home/chromium-security/site-isolation
## https://github.com/cypress-io/cypress/issues/1951
"--disable-site-isolation-trials"

## the following come frome chromedriver
## https://code.google.com/p/chromium/codesearch#chromium/src/chrome/test/chromedriver/chrome_launcher.cc&sq=package:chromium&l=70
"--metrics-recording-only"
Expand Down
21 changes: 16 additions & 5 deletions packages/server/test/e2e/web_security_spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ e2e = require("../support/helpers/e2e")

onServer = (app) ->
app.get "/link", (req, res) ->
res.send("<html><h1>link</h1><a href='http://localhost:55665/cross_origin'>second</a></html>")
res.send("<html><h1>link</h1><a href='https://www.foo.com:55665/cross_origin'>second</a></html>")

app.get "/cross_origin", (req, res) ->
res.send("<html><h1>cross origin</h1></html>")
Expand All @@ -12,22 +12,22 @@ onServer = (app) ->
res.send("""
<html>
<h1>form</h1>
<form method='POST' action='http://localhost:55665/submit'>
<form method='POST' action='https://www.foo.com:55665/submit'>
<input type='submit' name='foo' value='bar' />
</form>
</html>
""")

app.post "/submit", (req, res) ->
res.redirect("http://localhost:55665/cross_origin")
res.redirect("https://www.foo.com:55665/cross_origin")

app.get "/javascript", (req, res) ->
res.send("""
<html>
<script type='text/javascript'>
window.redirect = function(){
debugger
window.location.href = 'http://localhost:55665/cross_origin'
window.location.href = 'https://www.foo.com:55665/cross_origin'
}
</script>
<h1>javascript</h1>
Expand All @@ -37,16 +37,22 @@ onServer = (app) ->

describe "e2e web security", ->
require("mocha-banner").register()

context "when enabled", ->
e2e.setup({
servers: [{
port: 5566
onServer: onServer
}, {
port: 55665
https: true
onServer: onServer
}]
settings: {
hosts: {
"*.foo.com": "127.0.0.1"
}
}
})

it "fails", ->
Expand All @@ -63,16 +69,21 @@ describe "e2e web security", ->
onServer: onServer
}, {
port: 55665
https: true
onServer: onServer
}]
settings: {
chromeWebSecurity: false
hosts: {
"*.foo.com": "127.0.0.1"
}
}
})

it "passes", ->
e2e.exec(@, {
spec: "web_security_spec.coffee"
browser: "chrome"
snapshot: true
expectedExitCode: 0
})
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ describe "web security", ->
cy
.visit("http://localhost:5566/link")
.get("a").click()
.url().should("eq", "http://localhost:55665/cross_origin")
.url().should("eq", "https://www.foo.com:55665/cross_origin")

cy.contains("h1", "cross origin")

it "fails when submitted a form and being redirected to another origin", ->
cy
.visit("http://localhost:5566/form")
.get("input").click()
.url().should("eq", "http://localhost:55665/cross_origin")
.url().should("eq", "https://www.foo.com:55665/cross_origin")

cy.contains("h1", "cross origin")

it "fails when using a javascript redirect to another origin", ->
cy
.visit("http://localhost:5566/javascript")
.get("button").click()
.url().should("eq", "http://localhost:55665/cross_origin")
.url().should("eq", "https://www.foo.com:55665/cross_origin")

cy.contains("h1", "cross origin")
14 changes: 9 additions & 5 deletions packages/server/test/support/helpers/e2e.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ express = require("express")
Promise = require("bluebird")
snapshot = require("snap-shot-it")
debug = require("debug")("cypress:support:e2e")
httpsProxy = require("@packages/https-proxy")
Fixtures = require("./fixtures")
fs = require("#{root}../lib/util/fs")
allowDestroy = require("#{root}../lib/util/server_destroy")
Expand All @@ -33,15 +34,15 @@ e2ePath = Fixtures.projectPath("e2e")
pathUpToProjectName = Fixtures.projectPath("")

stackTraceLinesRe = /(\s+)at\s(.+)/g
browserNameVersionRe = /(Browser\:\s+)(Electron|Chrome|Canary|Chromium)(\s\d+)(\s\(\w+\))?/
browserNameVersionRe = /(Browser\:\s+)(Electron|Chrome|Canary|Chromium|Firefox)(\s\d+)(\s\(\w+\))?(\s+)/
availableBrowsersRe = /(Available browsers found are: )(.+)/g

replaceStackTraceLines = (str) ->
str.replace(stackTraceLinesRe, "$1at stack trace line")

replaceBrowserName = (str, p1, p2, p3, p4) ->
replaceBrowserName = (str, p1, p2, p3, p4, p5) ->
## get the padding for the existing browser string
lengthOfExistingBrowserString = _.sum([p2.length, p3.length, _.get(p4, "length", 0)])
lengthOfExistingBrowserString = _.sum([p2.length, p3.length, _.get(p4, "length", 0), p5.length])

## this ensures we add whitespace so the border is not shifted
p1 + _.padEnd("FooBrowser 88", lengthOfExistingBrowserString)
Expand Down Expand Up @@ -79,11 +80,14 @@ normalizeStdout = (str) ->
.join("\n")

startServer = (obj) ->
{onServer, port} = obj
{ onServer, port, https } = obj

app = express()

srv = http.Server(app)
if https
srv = httpsProxy.httpsServer(app)
else
srv = http.Server(app)

allowDestroy(srv)

Expand Down

0 comments on commit cd5fd04

Please sign in to comment.