Skip to content

Commit

Permalink
Merge branch 'develop' into issue-4952
Browse files Browse the repository at this point in the history
  • Loading branch information
flotwig authored Sep 17, 2019
2 parents 9a17ac2 + 72b082d commit 10f6e8d
Show file tree
Hide file tree
Showing 8 changed files with 693 additions and 602 deletions.
45 changes: 0 additions & 45 deletions packages/server/test/unit/blacklist_spec.coffee

This file was deleted.

53 changes: 53 additions & 0 deletions packages/server/test/unit/blacklist_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
require('../spec_helper')

const blacklist = require(`${root}lib/util/blacklist`)

const hosts = [
'*.google.com',
'shop.apple.com',
'localhost:6666',
'adwords.com',
'*yahoo.com',
]

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

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

const matchesArray = function (url, val) {
const m = blacklist.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)
}

describe('lib/util/blacklist', () => {
it('handles hosts, ports, wildcards', () => {
matchesArray('https://mail.google.com/foo', true)
matchesArray('https://shop.apple.com/bar', true)
matchesArray('http://localhost:6666/', true)
matchesArray('https://localhost:6666/', true)
matchesArray('https://adwords.com:443/', true)
matchesArray('http://adwords.com:80/quux', true)
matchesArray('https://yahoo.com:443/asdf', true)
matchesArray('http://mail.yahoo.com:443/asdf', true)

matchesArray('https://buy.adwords.com:443/', false)
matchesArray('http://localhost:66667', false)
matchesArray('http://mac.apple.com/', false)

matchesStr('https://localhost:6666/foo', 'localhost:6666', true)
matchesStr('https://localhost:6666/foo', 'localhost:5555', false)
})

it('returns the matched host', () => {
matchesHost('https://shop.apple.com:443/foo', 'shop.apple.com')
matchesHost('http://mail.yahoo.com:80/bar', '*yahoo.com')
matchesHost('https://localhost:6666/bar', 'localhost:6666')
})
})
66 changes: 0 additions & 66 deletions packages/server/test/unit/buffers_spec.coffee

This file was deleted.

77 changes: 77 additions & 0 deletions packages/server/test/unit/buffers_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
require('../spec_helper')

const buffers = require(`${root}lib/util/buffers`)

describe('lib/util/buffers', () => {
beforeEach(() => {
buffers.reset()
})

afterEach(() => {
buffers.reset()
})

context('#get', () => {
it('returns buffer by url', () => {
const obj = { url: 'foo' }

buffers.set(obj)

const buffer = buffers.get('foo')

expect(buffer).to.deep.eq(obj)
})

it('falls back to setting the port when buffer could not be found', () => {
const obj = { url: 'https://www.google.com/' }

buffers.set(obj)

const buffer = buffers.get('https://www.google.com:443/')

expect(buffer).to.deep.eq(obj)
})
})

context('#getByOriginalUrl', () => {
it('returns buffer by originalUrl', () => {
const obj = { originalUrl: 'foo' }

buffers.set(obj)

const buffer = buffers.getByOriginalUrl('foo')

expect(buffer).to.deep.eq(obj)
})
})

context('#take', () => {
it('removes the found buffer', () => {
const obj = { url: 'https://www.google.com/' }

buffers.set(obj)

expect(buffers.all()).to.have.length(1)

const buffer = buffers.take('https://www.google.com:443/')

expect(buffer).to.deep.eq(obj)

expect(buffers.all()).to.have.length(0)
})

it('does not remove anything when not found', () => {
const obj = { url: 'https://www.google.com/' }

buffers.set(obj)

expect(buffers.all()).to.have.length(1)

const buffer = buffers.take('asdf')

expect(buffer).to.be.undefined

expect(buffers.all()).to.have.length(1)
})
})
})
Loading

0 comments on commit 10f6e8d

Please sign in to comment.