Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decaf proxy tests #5156

Merged
merged 3 commits into from
Sep 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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