passport-mock-strategy
Advanced tools
Comparing version 1.0.0 to 1.1.0
@@ -1,11 +0,12 @@ | ||
'use strict'; | ||
var Passport = require('passport').Passport; | ||
var MockStrategy = require('./passport-mock-strategy'); | ||
var _require = require('./mock-utilities'), | ||
setupSerializeAndDeserialize = _require.setupSerializeAndDeserialize, | ||
connectPassport = _require.connectPassport; | ||
"use strict"; | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; | ||
result["default"] = mod; | ||
return result; | ||
}; | ||
var passport = __importStar(require("passport")); | ||
var mock_utilities_1 = require("./mock-utilities"); | ||
var MockStrategy = require("./passport-mock-strategy"); | ||
/** | ||
@@ -16,14 +17,9 @@ * Sets up a basic passport configuration using the default MockPassport instance. | ||
*/ | ||
function createMockPassport(app) { | ||
var mockPassport = new Passport(); | ||
setupSerializeAndDeserialize(mockPassport); | ||
var mockPassport = new passport.Passport(); | ||
mock_utilities_1.setupSerializeAndDeserialize(mockPassport); | ||
mockPassport.use(new MockStrategy()); | ||
connectPassport(app, mockPassport); | ||
mock_utilities_1.connectPassport(app, mockPassport); | ||
return mockPassport; | ||
} | ||
module.exports = createMockPassport; | ||
module.exports = createMockPassport; |
@@ -1,30 +0,18 @@ | ||
'use strict'; | ||
var MockStrategy = require('./passport-mock-strategy'); | ||
var _require = require('./mock-utilities'), | ||
setupSerializeAndDeserialize = _require.setupSerializeAndDeserialize, | ||
connectPassport = _require.connectPassport; | ||
"use strict"; | ||
var createMockPassport = require("./create-mock-passport"); | ||
var createMockStorage = require("./mock-storage"); | ||
var mockUser = require("./mock-user"); | ||
var mock_utilities_1 = require("./mock-utilities"); | ||
var MockStrategy = require("./passport-mock-strategy"); | ||
/** | ||
* Export MockStrategy. | ||
*/ | ||
exports = module.exports = MockStrategy; | ||
exports.MockStrategy = MockStrategy; | ||
exports.Strategy = MockStrategy; | ||
/** | ||
* Export other modules. | ||
*/ | ||
exports.mockUser = require('./mock-user'); | ||
exports.setupSerializeAndDeserialize = setupSerializeAndDeserialize; | ||
exports.connectPassport = connectPassport; | ||
exports.createMockPassport = require('./create-mock-passport'); | ||
exports.createMockStorage = require('./mock-storage'); | ||
/** | ||
* Export flow types | ||
*/ | ||
var exportModule = MockStrategy; | ||
exportModule.MockStrategy = MockStrategy; | ||
exportModule.Strategy = MockStrategy; | ||
exportModule.mockUser = mockUser; | ||
exportModule.setupSerializeAndDeserialize = mock_utilities_1.setupSerializeAndDeserialize; | ||
exportModule.connectPassport = mock_utilities_1.connectPassport; | ||
exportModule.createMockPassport = createMockPassport; | ||
exportModule.createMockStorage = createMockStorage; | ||
module.exports = exportModule; |
@@ -1,3 +0,11 @@ | ||
'use strict'; | ||
"use strict"; | ||
var __assign = (this && this.__assign) || Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
var es6_promise_1 = require("es6-promise"); | ||
/** | ||
@@ -8,3 +16,2 @@ * Creates and returns a mock storage object. | ||
var storage = {}; | ||
/** | ||
@@ -16,7 +23,4 @@ * Fetches a user with the given id from the storage. | ||
function fetchUser(id) { | ||
return new Promise(function (resolve) { | ||
return resolve(storage[id] || null); | ||
}); | ||
return new es6_promise_1.Promise(function (resolve) { return resolve(storage[id] || null); }); | ||
} | ||
/** | ||
@@ -28,11 +32,9 @@ * Saves a user to a storage and then returns the user. | ||
function saveUser(user) { | ||
return new Promise(function (resolve) { | ||
storage[user.id] = Object.assign({}, user); | ||
return new es6_promise_1.Promise(function (resolve) { | ||
storage[user.id] = __assign({}, user); | ||
return resolve(user); | ||
}); | ||
} | ||
return { fetchUser: fetchUser, saveUser: saveUser }; | ||
} | ||
module.exports = createMockStorage; | ||
module.exports = createMockStorage; |
@@ -1,3 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
var mockUser = { | ||
@@ -8,5 +7,4 @@ id: '1234', | ||
emails: [{ value: 'foo@bar.com', type: 'account' }], | ||
provider: 'mock' | ||
provider: 'mock', | ||
}; | ||
module.exports = mockUser; | ||
module.exports = mockUser; |
@@ -1,17 +0,15 @@ | ||
'use strict'; | ||
var mockUser = require('./mock-user'); | ||
var defaultSerialize = function defaultSerialize(user, done) { | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var mockUser = require("./mock-user"); | ||
var defaultSerialize = function (user, done) { | ||
return done(null, user.id); | ||
}; | ||
var defaultDeserialize = function defaultDeserialize(id, done) { | ||
var defaultDeserialize = function (id, done) { | ||
if (id === mockUser.id) { | ||
done(null, mockUser); | ||
} else { | ||
done(new Error('No such user with id ' + id)); | ||
} | ||
else { | ||
done(new Error("No such user with id " + id)); | ||
} | ||
}; | ||
/** | ||
@@ -27,3 +25,3 @@ * Sets up user serialization and deserialization for a given passport instance. | ||
} | ||
exports.setupSerializeAndDeserialize = setupSerializeAndDeserialize; | ||
/** | ||
@@ -38,4 +36,2 @@ * Initializes the passport instance and connects it to the given node app. | ||
} | ||
exports.setupSerializeAndDeserialize = setupSerializeAndDeserialize; | ||
exports.connectPassport = connectPassport; | ||
exports.connectPassport = connectPassport; |
@@ -1,13 +0,13 @@ | ||
'use strict'; | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
var Strategy = require('passport').Strategy; | ||
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var passport_1 = require("passport"); | ||
/** | ||
@@ -17,5 +17,4 @@ * Mock Passport Strategy for testing purposes. | ||
*/ | ||
var MockStrategy = function (_Strategy) { | ||
_inherits(MockStrategy, _Strategy); | ||
var MockStrategy = /** @class */ (function (_super) { | ||
__extends(MockStrategy, _super); | ||
/** | ||
@@ -52,4 +51,3 @@ * The MockStrategy constructor. | ||
function MockStrategy(options, verify) { | ||
_classCallCheck(this, MockStrategy); | ||
var _this = this; | ||
// Allows verify to be passed as the first parameter and options skipped | ||
@@ -60,7 +58,4 @@ if (typeof options === 'function') { | ||
} | ||
options = options || {}; | ||
var _this = _possibleConstructorReturn(this, (MockStrategy.__proto__ || Object.getPrototypeOf(MockStrategy)).call(this)); | ||
_this = _super.call(this) || this; | ||
_this.name = options.name || 'mock'; | ||
@@ -72,3 +67,2 @@ _this._user = options.user || require('./mock-user'); | ||
} | ||
/** | ||
@@ -81,41 +75,31 @@ * Authenticate request. Always authenticates successfully by default | ||
*/ | ||
_createClass(MockStrategy, [{ | ||
key: 'authenticate', | ||
value: function authenticate(req) { | ||
var self = this; | ||
// If no verify callback was specified automatically authenticate | ||
if (!self._verify) { | ||
return self.success(self._user, null); | ||
MockStrategy.prototype.authenticate = function (req) { | ||
var _this = this; | ||
// If no verify callback was specified automatically authenticate | ||
if (!this._verify) { | ||
return this.success(this._user); | ||
} | ||
var verified = function (error, user, info) { | ||
if (error) { | ||
return _this.error(error); | ||
} | ||
function verified(error, user, info) { | ||
if (error) { | ||
return self.error(error); | ||
} | ||
if (!user) { | ||
return self.fail(info); | ||
} | ||
self.success(user, info); | ||
if (!user) { | ||
return _this.fail(info); | ||
} | ||
try { | ||
if (self._passReqToCallback) { | ||
self._verify(req, self._user, verified); | ||
} else { | ||
self._verify(this._user, verified); | ||
} | ||
} catch (e) { | ||
return self.error(e); | ||
_this.success(user, info); | ||
}; | ||
try { | ||
if (this._passReqToCallback && req) { | ||
this._verify(req, this._user, verified); | ||
} | ||
else { | ||
this._verify(this._user, verified); | ||
} | ||
} | ||
}]); | ||
catch (e) { | ||
return this.error(e); | ||
} | ||
}; | ||
return MockStrategy; | ||
}(Strategy); | ||
module.exports = MockStrategy; | ||
}(passport_1.Strategy)); | ||
module.exports = MockStrategy; |
{ | ||
"name": "passport-mock-strategy", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Mock passport strategy for testing Node.js applications.", | ||
@@ -20,2 +20,3 @@ "keywords": [ | ||
"main": "lib/index.js", | ||
"types": "lib/index.d.ts", | ||
"engines": { | ||
@@ -28,18 +29,12 @@ "node": ">= 6" | ||
"dependencies": { | ||
"@types/express": "^4.11.1", | ||
"@types/passport": "^0.4.5", | ||
"es6-promise": "^4.2.4", | ||
"passport": "^0.4.0" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "^6.26.0", | ||
"babel-eslint": "^8.2.3", | ||
"babel-preset-env": "^1.6.1", | ||
"babel-preset-flow": "^6.23.0", | ||
"cookie-parser": "^1.4.3", | ||
"cookie-session": "^2.0.0-beta.3", | ||
"eslint": "^4.19.1", | ||
"eslint-config-prettier": "^2.9.0", | ||
"eslint-plugin-flowtype": "^2.46.2", | ||
"eslint-plugin-prettier": "^2.6.0", | ||
"express": "^4.16.3", | ||
"flow-bin": "^0.69.0", | ||
"flow-copy-source": "^1.3.0", | ||
"husky": "^0.14.3", | ||
@@ -51,11 +46,16 @@ "jest": "^22.4.3", | ||
"superagent": "^3.8.2", | ||
"supertest": "^3.0.0" | ||
"supertest": "^3.0.0", | ||
"ts-jest": "^22.4.4", | ||
"tslint": "^5.9.1", | ||
"tslint-config-prettier": "^1.12.0", | ||
"tslint-plugin-prettier": "^1.3.0", | ||
"typescript": "^2.8.3" | ||
}, | ||
"scripts": { | ||
"build": "yarn run clean && yarn run build:lib && yarn run build:flow", | ||
"build:lib": "babel src -d lib", | ||
"build:flow": "flow-copy-source src lib", | ||
"build": "yarn run clean && yarn run build:lib && yarn run copy-flow", | ||
"build:lib": "tsc", | ||
"build:watch": "tsc --watch", | ||
"clean": "rm -rf lib", | ||
"eslint": "eslint --fix \"{src,test}/**/*.js\"", | ||
"flow": "flow", | ||
"copy-flow": "cp flow-types/* lib/", | ||
"lint": "tslint -p ./tsconfig.json --fix", | ||
"precommit": "lint-staged", | ||
@@ -65,4 +65,4 @@ "prepare": "yarn run build", | ||
"test": "jest", | ||
"test-watch": "jest --watch" | ||
"test:watch": "jest --watch" | ||
} | ||
} |
@@ -85,4 +85,6 @@ # passport-mock-strategy | ||
## Type Checking | ||
This package uses [flow](https://flow.org/) for type checking. All types used are provided and exported. They can be imported for use. | ||
This package is written in [typescript](https://www.typescriptlang.org/). All type declarations are published with the package and can be used as needed. | ||
Type definitions are also provided for [flow](https://flow.org/). They can be imported for use. | ||
Example: | ||
@@ -89,0 +91,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16
16
355
107
22899
4
1
+ Added@types/express@^4.11.1
+ Added@types/passport@^0.4.5
+ Addedes6-promise@^4.2.4
+ Added@types/body-parser@1.19.5(transitive)
+ Added@types/connect@3.4.38(transitive)
+ Added@types/express@4.17.21(transitive)
+ Added@types/express-serve-static-core@4.19.6(transitive)
+ Added@types/http-errors@2.0.4(transitive)
+ Added@types/mime@1.3.5(transitive)
+ Added@types/node@22.10.2(transitive)
+ Added@types/passport@0.4.7(transitive)
+ Added@types/qs@6.9.17(transitive)
+ Added@types/range-parser@1.2.7(transitive)
+ Added@types/send@0.17.4(transitive)
+ Added@types/serve-static@1.15.7(transitive)
+ Addedes6-promise@4.2.8(transitive)
+ Addedundici-types@6.20.0(transitive)