Files
cypress/packages/server/test/unit/util/socket_allowed_spec.ts
Jennifer Shehane 639df99036 Rename uses of term 'whitelist' (#7782)
* Rename non-user facing instances of whitelist

* Rename server option 'whitelist' to 'ignore'

* Update use of whitelist with server to throw instead of warn

* Rename Cypress.Cookies.defaults 'whitelist' option to 'preserve'

* fix circle yml parameter parsing consistent

* compose cloning an external repo and switching to the NEXT_DEV_VERSION branch consistently

* add cypress org to repo parameter

* cd into the right dir before switching branches

* one line git checkout

* simplify passing repo

* cd into the right dir

* clone into the right dir

* oh my cd 101

* replace kitchen sink strings for 5.0.0

Co-authored-by: Brian Mann <brian.mann86@gmail.com>
2020-06-30 02:27:29 -04:00

43 lines
1.1 KiB
TypeScript

import '../../spec_helper'
import { expect } from 'chai'
import { Request } from 'express'
import { SocketAllowed } from '../../../lib/util/socket_allowed'
import { EventEmitter } from 'events'
import { Socket } from 'net'
describe('lib/util/socket_allowed', function () {
let sw: SocketAllowed
beforeEach(() => {
sw = new SocketAllowed()
})
context('#add', () => {
it('adds localPort to allowed list and removes it when closed', () => {
const socket = new EventEmitter as Socket
// @ts-ignore readonly
socket.localPort = 12345
const req = {
socket: {
remotePort: socket.localPort,
remoteAddress: '127.0.0.1',
},
} as Request
expect(sw.allowedLocalPorts).to.deep.eq([])
expect(sw.isRequestAllowed(req)).to.be.false
sw.add(socket)
expect(sw.allowedLocalPorts).to.deep.eq([socket.localPort])
expect(sw.isRequestAllowed(req)).to.be.true
socket.emit('close')
expect(sw.allowedLocalPorts).to.deep.eq([])
expect(sw.isRequestAllowed(req)).to.be.false
})
})
})