Skip to content

Commit

Permalink
Update code around blacklistHosts to use blocklist terminology
Browse files Browse the repository at this point in the history
  • Loading branch information
jennifer-shehane committed Jun 9, 2020
1 parent c22541d commit 52e68d5
Show file tree
Hide file tree
Showing 12 changed files with 37 additions and 37 deletions.
4 changes: 2 additions & 2 deletions packages/driver/src/cy/aliases.js
Expand Up @@ -7,7 +7,7 @@ const aliasRe = /^@.+/
const aliasDisplayRe = /^([@]+)/
const requestXhrRe = /\.request$/

const blacklist = ['test', 'runnable', 'timeout', 'slow', 'skip', 'inspect']
const blocklist = ['test', 'runnable', 'timeout', 'slow', 'skip', 'inspect']

const aliasDisplayName = (name) => {
return name.replace(aliasDisplayRe, '')
Expand Down Expand Up @@ -39,7 +39,7 @@ const validateAlias = (alias) => {
$errUtils.throwErrByPath('as.empty_string')
}

if (blacklist.includes(alias)) {
if (blocklist.includes(alias)) {
return $errUtils.throwErrByPath('as.reserved_word', { args: { alias } })
}
}
Expand Down
16 changes: 8 additions & 8 deletions packages/driver/test/cypress/integration/commands/agents_spec.js
Expand Up @@ -352,11 +352,11 @@ describe('src/cy/commands/agents', () => {
}).to.throw('`cy.as()` cannot be passed an empty string.')
})

_.each(['test', 'runnable', 'timeout', 'slow', 'skip', 'inspect'], (blacklist) => {
it(`throws on a blacklisted word: ${blacklist}`, () => {
_.each(['test', 'runnable', 'timeout', 'slow', 'skip', 'inspect'], (blocklist) => {
it(`throws on a blocklisted word: ${blocklist}`, () => {
expect(() => {
cy.stub().as(blacklist)
}).to.throw(`\`cy.as()\` cannot be aliased as: \`${blacklist}\`. This word is reserved.`)
cy.stub().as(blocklist)
}).to.throw(`\`cy.as()\` cannot be aliased as: \`${blocklist}\`. This word is reserved.`)
})
})
})
Expand Down Expand Up @@ -433,11 +433,11 @@ describe('src/cy/commands/agents', () => {
}).to.throw('`cy.as()` cannot be passed an empty string.')
})

_.each(['test', 'runnable', 'timeout', 'slow', 'skip', 'inspect'], (blacklist) => {
it(`throws on a blacklisted word: ${blacklist}`, () => {
_.each(['test', 'runnable', 'timeout', 'slow', 'skip', 'inspect'], (blocklist) => {
it(`throws on a blocklisted word: ${blocklist}`, () => {
expect(() => {
cy.stub().as(blacklist)
}).to.throw(`\`cy.as()\` cannot be aliased as: \`${blacklist}\`. This word is reserved.`)
cy.stub().as(blocklist)
}).to.throw(`\`cy.as()\` cannot be aliased as: \`${blocklist}\`. This word is reserved.`)
})
})
})
Expand Down
Expand Up @@ -232,16 +232,16 @@ describe('src/cy/commands/aliasing', () => {
cy.get('@my@Alias')
})

_.each(['test', 'runnable', 'timeout', 'slow', 'skip', 'inspect'], (blacklist) => {
it(`throws on a blacklisted word: ${blacklist}`, (done) => {
_.each(['test', 'runnable', 'timeout', 'slow', 'skip', 'inspect'], (blocklist) => {
it(`throws on a blocklisted word: ${blocklist}`, (done) => {
cy.on('fail', (err) => {
expect(err.message).to.eq(`\`cy.as()\` cannot be aliased as: \`${blacklist}\`. This word is reserved.`)
expect(err.message).to.eq(`\`cy.as()\` cannot be aliased as: \`${blocklist}\`. This word is reserved.`)
expect(err.docsUrl).to.eq('https://on.cypress.io/as')

done()
})

cy.get('div:first').as(blacklist)
cy.get('div:first').as(blocklist)
})
})
})
Expand Down
2 changes: 1 addition & 1 deletion packages/network/README.md
Expand Up @@ -8,7 +8,7 @@ You can see a list of the modules exported from this package in [./lib/index.ts]

* `agent` is a HTTP/HTTPS [agent][1] with support for HTTP/HTTPS proxies and keepalive whenever possible
* `allowDestroy` can be used to wrap a `net.Server` to add a `.destroy()` method
* `blacklist` is a utility for matching glob blacklists
* `blocklist` is a utility for matching glob blocklists
* `concatStream` is a wrapper around [`concat-stream@1.6.2`][2] that makes it always yield a `Buffer`
* `connect` contains utilities for making network connections, including `createRetryingSocket`
* `cors` contains utilities for Cross-Origin Resource Sharing
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions packages/network/lib/index.ts
@@ -1,12 +1,12 @@
import agent from './agent'
import * as blacklist from './blacklist'
import * as blocklist from './blocklist'
import * as connect from './connect'
import * as cors from './cors'
import * as uri from './uri'

export {
agent,
blacklist,
blocklist,
connect,
cors,
uri,
Expand Down
10 changes: 5 additions & 5 deletions packages/network/test/unit/blacklist_spec.ts
@@ -1,4 +1,4 @@
import { blacklist } from '../..'
import { blocklist } from '../..'
import { expect } from 'chai'

const hosts = [
Expand All @@ -10,22 +10,22 @@ const hosts = [
]

const matchesStr = function (url, host, val) {
const m = blacklist.matches(url, host)
const m = blocklist.matches(url, host)

expect(!!m).to.eq(val, `url: '${url}' did not pass`)
}

const matchesArray = function (url, val) {
const m = blacklist.matches(url, hosts)
const m = blocklist.matches(url, hosts)

expect(!!m).to.eq(val, `url: '${url}' did not pass`)
}

const matchesHost = (url, host) => {
expect(blacklist.matches(url, hosts)).to.eq(host)
expect(blocklist.matches(url, hosts)).to.eq(host)
}

describe('lib/blacklist', () => {
describe('lib/blocklist', () => {
it('handles hosts, ports, wildcards', () => {
matchesArray('https://mail.google.com/foo', true)
matchesArray('https://shop.apple.com/bar', true)
Expand Down
8 changes: 4 additions & 4 deletions packages/proxy/lib/http/request-middleware.ts
@@ -1,6 +1,6 @@
import _ from 'lodash'
import debugModule from 'debug'
import { blacklist, cors } from '@packages/network'
import { blocklist, cors } from '@packages/network'
import { HttpMiddleware } from './'

export type RequestMiddleware = HttpMiddleware<{
Expand Down Expand Up @@ -50,11 +50,11 @@ const EndRequestsToBlacklistedHosts: RequestMiddleware = function () {
const { blocklistHosts } = this.config

if (blocklistHosts) {
const matches = blacklist.matches(this.req.proxiedUrl, blocklistHosts)
const matches = blocklist.matches(this.req.proxiedUrl, blocklistHosts)

if (matches) {
this.res.set('x-cypress-matched-blacklisted-host', matches)
debug('blacklisting request %o', {
this.res.set('x-cypress-matched-blocklisted-host', matches)
debug('blocklisting request %o', {
url: this.req.proxiedUrl,
matches,
})
Expand Down
10 changes: 5 additions & 5 deletions packages/server/lib/server.js
Expand Up @@ -15,7 +15,7 @@ const compression = require('compression')
const debug = require('debug')('cypress:server:server')
const {
agent,
blacklist,
blocklist,
concatStream,
cors,
uri,
Expand Down Expand Up @@ -293,16 +293,16 @@ class Server {
// if we are currently matching then we're
// not making a direct connection anyway
// so we only need to check this if we
// have blacklist hosts and are not matching.
// have blocklist hosts and are not matching.
//
// if we have blacklisted hosts lets
// if we have blocklisted hosts lets
// see if this matches - if so then
// we cannot allow it to make a direct
// connection
if (blocklistHosts && !isMatching) {
isMatching = blacklist.matches(urlToCheck, blocklistHosts)
isMatching = blocklist.matches(urlToCheck, blocklistHosts)

debug(`HTTPS request ${urlToCheck} matches blacklist?`, isMatching)
debug(`HTTPS request ${urlToCheck} matches blocklist?`, isMatching)
}

// make a direct connection only if
Expand Down
4 changes: 2 additions & 2 deletions packages/server/test/e2e/1_blacklist_hosts_spec.js
Expand Up @@ -14,7 +14,7 @@ const onServer = function (app) {
})
}

describe('e2e blacklist', () => {
describe('e2e blocklist', () => {
e2e.setup({
servers: [{
port: 3131,
Expand All @@ -31,7 +31,7 @@ describe('e2e blacklist', () => {

it('passes', function () {
return e2e.exec(this, {
spec: 'blacklist_hosts_spec.coffee',
spec: 'blocklist_hosts_spec.coffee',
snapshot: true,
})
})
Expand Down
4 changes: 2 additions & 2 deletions packages/server/test/integration/http_requests_spec.js
Expand Up @@ -3727,7 +3727,7 @@ describe('Routes', () => {
})
})

context('blacklisted hosts', () => {
context('blocklisted hosts', () => {
beforeEach(function () {
return this.setup({
config: {
Expand All @@ -3744,7 +3744,7 @@ describe('Routes', () => {

it('returns 503 and custom headers for all hosts', function () {
const expectedHeader = (res, val) => {
expect(res.headers['x-cypress-matched-blacklisted-host']).to.eq(val)
expect(res.headers['x-cypress-matched-blocklisted-host']).to.eq(val)
}

return Promise.all([
Expand Down
@@ -1,5 +1,5 @@
describe "blacklist", ->
it "forces blacklisted hosts to return 503", ->
describe "blocklist", ->
it "forces blocklisted hosts to return 503", ->
cy
.visit("http://localhost:3232")

Expand Down

0 comments on commit 52e68d5

Please sign in to comment.