-
Notifications
You must be signed in to change notification settings - Fork 3.3k
/
Copy pathchrome_policy_check.js
72 lines (55 loc) · 1.93 KB
/
chrome_policy_check.js
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
require('../../spec_helper')
const _ = require('lodash')
const { stripIndent } = require('common-tags')
const chromePolicyCheck = require(`${root}../lib/util/chrome_policy_check`)
describe('lib/util/chrome_policy_check', () => {
context('.getRunner returns a function', () => {
it('calls callback with an error if policies are found', () => {
const run = chromePolicyCheck.getRunner({
enumerateValues (hkey, key) {
// mock a registry with a couple of policies
return _.get({
'HKEY_LOCAL_MACHINE': {
'Software\\Policies\\Google\\Chrome': [
{ name: 'ProxyServer' },
],
},
'HKEY_CURRENT_USER': {
'Software\\Policies\\Google\\Chromium': [
{ name: 'ExtensionSettings' },
],
},
}, `${hkey}.${key}`, [])
},
})
const cb = sinon.stub()
run(cb)
expect(cb).to.be.calledOnce
expect(cb.getCall(0).args[0].message).to.eq(stripIndent(`\
Cypress detected policy settings on your computer that may cause issues.
The following policies were detected that may prevent Cypress from automating Chrome:
> HKEY_LOCAL_MACHINE\\Software\\Policies\\Google\\Chrome\\ProxyServer
> HKEY_CURRENT_USER\\Software\\Policies\\Google\\Chromium\\ExtensionSettings
For more information, see https://on.cypress.io/bad-browser-policy\
`))
})
it('does not call callback if no policies are found', () => {
const run = chromePolicyCheck.getRunner({
enumerateValues: _.constant([]),
})
const cb = sinon.stub()
run(cb)
expect(cb).to.not.be.called
})
it('fails silently if enumerateValues throws', () => {
const run = chromePolicyCheck.getRunner({
enumerateValues () {
throw new Error('blah')
},
})
const cb = sinon.stub()
run(cb)
expect(cb).to.not.be.called
})
})
})