Skip to content

Commit

Permalink
fix: remove mockery due to security vulnerability alert (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
joeyguerra committed Sep 13, 2023
1 parent 0aaad28 commit 642f8ee
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 22 deletions.
7 changes: 0 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"chai": "^4.3.7",
"matchdep": "^2.0.0",
"mocha": "^10.2.0",
"mockery": "^2.1.0",
"nyc": "^15.1.0",
"semantic-release": "^21.0.2",
"sinon": "^15.0.4",
Expand Down
19 changes: 19 additions & 0 deletions test/fixtures/RequireMocker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const Module = require('module')
const originalRequire = Module.prototype.require
const hookModuleToReturnMockFromRequire = (module, mock) => {
Module.prototype.require = function () {
if (arguments[0] === module) {
return mock
}
return originalRequire.apply(this, arguments)
}
}

const resetModuleMocks = () => {
Module.prototype.require = originalRequire
}

module.exports = {
hook: hookModuleToReturnMockFromRequire,
reset: resetModuleMocks
}
10 changes: 3 additions & 7 deletions test/help_message_visibility_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const path = require('path')

const chai = require('chai')
const expect = chai.expect
const mockery = require('mockery')
const { hook, reset } = require('./fixtures/RequireMocker.js')

chai.use(require('sinon-chai'))

Expand All @@ -31,19 +31,15 @@ const newTestRobot = function newTestRobot () {

describe('help in private', () => describe('message visibility', () => {
beforeEach(function () {
mockery.enable({
warnOnReplace: false,
warnOnUnregistered: false
})
mockery.registerMock('hubot-mock-adapter', require('./fixtures/MockAdapter.js'))
hook('hubot-mock-adapter', require('./fixtures/MockAdapter.js'))
this.robot = newTestRobot()
this.robot.run()
this.user = this.robot.brain.userForName('john')
})

afterEach(function () {
this.robot.shutdown()
mockery.disable()
reset()
})

context('when HUBOT_HELP_REPLY_IN_PRIVATE is unset', () => it('replies in the same room', function (done) {
Expand Down
10 changes: 3 additions & 7 deletions test/help_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const path = require('path')

const chai = require('chai')
const expect = chai.expect
const mockery = require('mockery')
const { hook, reset } = require('./fixtures/RequireMocker.js')

chai.use(require('sinon-chai'))

Expand All @@ -30,19 +30,15 @@ const newTestRobot = function newTestRobot () {

describe('help', () => describe('getHelpCommands', () => {
beforeEach(function () {
mockery.enable({
warnOnReplace: false,
warnOnUnregistered: false
})
mockery.registerMock('hubot-mock-adapter', require('./fixtures/MockAdapter.js'))
hook('hubot-mock-adapter', require('./fixtures/MockAdapter.js'))
this.robot = newTestRobot()
this.robot.run()
this.user = this.robot.brain.userForName('john')
})

afterEach(function () {
this.robot.shutdown()
mockery.disable()
reset()
})

context('when HUBOT_HELP_HIDDEN_COMMANDS is not set', () => it('lists all commands', function (done) {
Expand Down

0 comments on commit 642f8ee

Please sign in to comment.