AuthenticationControllerTests.coffee 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  1. sinon = require('sinon')
  2. chai = require('chai')
  3. should = chai.should()
  4. expect = chai.expect
  5. modulePath = "../../../../app/js/Features/Authentication/AuthenticationController.js"
  6. SandboxedModule = require('sandboxed-module')
  7. events = require "events"
  8. tk = require("timekeeper")
  9. MockRequest = require("../helpers/MockRequest")
  10. MockResponse = require("../helpers/MockResponse")
  11. ObjectId = require("mongojs").ObjectId
  12. describe "AuthenticationController", ->
  13. beforeEach ->
  14. @AuthenticationController = SandboxedModule.require modulePath, requires:
  15. "./AuthenticationManager": @AuthenticationManager = {}
  16. "../User/UserGetter" : @UserGetter = {}
  17. "../User/UserUpdater" : @UserUpdater = {}
  18. "metrics-sharelatex": @Metrics = { inc: sinon.stub() }
  19. "../Security/LoginRateLimiter": @LoginRateLimiter = { processLoginRequest:sinon.stub(), recordSuccessfulLogin:sinon.stub() }
  20. "../User/UserHandler": @UserHandler = {setupLoginData:sinon.stub()}
  21. "../Analytics/AnalyticsManager": @AnalyticsManager = { recordEvent: sinon.stub() }
  22. "logger-sharelatex": @logger = { log: sinon.stub(), error: sinon.stub(), err: sinon.stub() }
  23. "settings-sharelatex": {}
  24. "passport": @passport =
  25. authenticate: sinon.stub().returns(sinon.stub())
  26. "../User/UserSessionsManager": @UserSessionsManager =
  27. trackSession: sinon.stub()
  28. untrackSession: sinon.stub()
  29. revokeAllUserSessions: sinon.stub().callsArgWith(1, null)
  30. "../../infrastructure/GeoIpLookup": @GeoIpLookup =
  31. getDetails: sinon.stub().callsArgWith(1, null, {})
  32. @user =
  33. _id: ObjectId()
  34. email: @email = "USER@example.com"
  35. first_name: "bob"
  36. last_name: "brown"
  37. referal_id: 1234
  38. isAdmin: false
  39. @password = "banana"
  40. @req = new MockRequest()
  41. @res = new MockResponse()
  42. @callback = @next = sinon.stub()
  43. tk.freeze(Date.now())
  44. afterEach ->
  45. tk.reset()
  46. describe 'isUserLoggedIn', () ->
  47. beforeEach ->
  48. @stub = sinon.stub(@AuthenticationController, 'getLoggedInUserId')
  49. afterEach ->
  50. @stub.restore()
  51. it 'should do the right thing in all cases', () ->
  52. @AuthenticationController.getLoggedInUserId.returns('some_id')
  53. expect(@AuthenticationController.isUserLoggedIn(@req)).to.equal true
  54. @AuthenticationController.getLoggedInUserId.returns(null)
  55. expect(@AuthenticationController.isUserLoggedIn(@req)).to.equal false
  56. @AuthenticationController.getLoggedInUserId.returns(false)
  57. expect(@AuthenticationController.isUserLoggedIn(@req)).to.equal false
  58. @AuthenticationController.getLoggedInUserId.returns(undefined)
  59. expect(@AuthenticationController.isUserLoggedIn(@req)).to.equal false
  60. describe 'setInSessionUser', () ->
  61. beforeEach ->
  62. @user = {
  63. _id: 'id'
  64. first_name: 'a'
  65. last_name: 'b'
  66. email: 'c'
  67. }
  68. @req.session.passport = {user: @user}
  69. @req.session.user = @user
  70. it 'should update the right properties', () ->
  71. @AuthenticationController.setInSessionUser(@req, {first_name: 'new_first_name', email: 'new_email'})
  72. expectedUser = {
  73. _id: 'id'
  74. first_name: 'new_first_name'
  75. last_name: 'b'
  76. email: 'new_email'
  77. }
  78. expect(@req.session.passport.user).to.deep.equal(expectedUser)
  79. expect(@req.session.user).to.deep.equal(expectedUser)
  80. describe 'passportLogin', ->
  81. beforeEach ->
  82. @info = null
  83. @req.login = sinon.stub().callsArgWith(1, null)
  84. @res.json = sinon.stub()
  85. @req.session = @session = {
  86. passport: {user: @user},
  87. postLoginRedirect: "/path/to/redir/to"
  88. }
  89. @req.session.destroy = sinon.stub().callsArgWith(0, null)
  90. @req.session.save = sinon.stub().callsArgWith(0, null)
  91. @req.sessionStore = {generate: sinon.stub()}
  92. @passport.authenticate.callsArgWith(1, null, @user, @info)
  93. @err = new Error('woops')
  94. it 'should call passport.authenticate', () ->
  95. @AuthenticationController.passportLogin @req, @res, @next
  96. @passport.authenticate.callCount.should.equal 1
  97. describe 'when authenticate produces an error', ->
  98. beforeEach ->
  99. @passport.authenticate.callsArgWith(1, @err)
  100. it 'should return next with an error', () ->
  101. @AuthenticationController.passportLogin @req, @res, @next
  102. @next.calledWith(@err).should.equal true
  103. describe 'when authenticate produces a user', ->
  104. beforeEach ->
  105. @req.session.postLoginRedirect = 'some_redirect'
  106. @passport.authenticate.callsArgWith(1, null, @user, @info)
  107. afterEach ->
  108. delete @req.session.postLoginRedirect
  109. it 'should call req.login', () ->
  110. @AuthenticationController.passportLogin @req, @res, @next
  111. @req.login.callCount.should.equal 1
  112. @req.login.calledWith(@user).should.equal true
  113. it 'should send a json response with redirect', () ->
  114. @AuthenticationController.passportLogin @req, @res, @next
  115. @res.json.callCount.should.equal 1
  116. @res.json.calledWith({redir: 'some_redirect'}).should.equal true
  117. describe 'when session.save produces an error', () ->
  118. beforeEach ->
  119. @req.session.save = sinon.stub().callsArgWith(0, new Error('woops'))
  120. it 'should return next with an error', () ->
  121. @AuthenticationController.passportLogin @req, @res, @next
  122. @next.calledWith(@err).should.equal true
  123. it 'should not return json', () ->
  124. @AuthenticationController.passportLogin @req, @res, @next
  125. @res.json.callCount.should.equal 0
  126. describe 'when authenticate does not produce a user', ->
  127. beforeEach ->
  128. @info = {text: 'a', type: 'b'}
  129. @passport.authenticate.callsArgWith(1, null, false, @info)
  130. it 'should not call req.login', () ->
  131. @AuthenticationController.passportLogin @req, @res, @next
  132. @req.login.callCount.should.equal 0
  133. it 'should not send a json response with redirect', () ->
  134. @AuthenticationController.passportLogin @req, @res, @next
  135. @res.json.callCount.should.equal 1
  136. @res.json.calledWith({message: @info}).should.equal true
  137. expect(@res.json.lastCall.args[0].redir?).to.equal false
  138. describe 'afterLoginSessionSetup', ->
  139. beforeEach ->
  140. @req.login = sinon.stub().callsArgWith(1, null)
  141. @req.session = @session = {passport: {user: @user}}
  142. @req.session =
  143. passport: {user: {_id: "one"}}
  144. @req.session.destroy = sinon.stub().callsArgWith(0, null)
  145. @req.session.save = sinon.stub().callsArgWith(0, null)
  146. @req.sessionStore = {generate: sinon.stub()}
  147. @UserSessionsManager.trackSession = sinon.stub()
  148. @GeoIpLookup.getDetails = sinon.stub()
  149. .callsArgWith(1, null, @geoDetails = {country_code: 'US'})
  150. @call = (callback) =>
  151. @AuthenticationController.afterLoginSessionSetup @req, @user, callback
  152. it 'should not produce an error', (done) ->
  153. @call (err) =>
  154. expect(err).to.equal null
  155. done()
  156. it 'should call req.login', (done) ->
  157. @call (err) =>
  158. @req.login.callCount.should.equal 1
  159. done()
  160. it 'should call UserSessionsManager.trackSession', (done) ->
  161. @call (err) =>
  162. @UserSessionsManager.trackSession.callCount.should.equal 1
  163. done()
  164. it 'should call GeoIpLookup.getDetails', (done) ->
  165. @call (err) =>
  166. @GeoIpLookup.getDetails.callCount.should.equal 1
  167. @req.session.countryCode.should.exist
  168. @req.session.countryCode.should.equal @geoDetails.country_code
  169. done()
  170. it 'should call req.session.save', (done) ->
  171. @call (err) =>
  172. @req.session.save.callCount.should.equal 1
  173. done()
  174. describe 'when req.session.save produces an error', ->
  175. beforeEach ->
  176. @req.session.save = sinon.stub().callsArgWith(0, new Error('woops'))
  177. it 'should produce an error', (done) ->
  178. @call (err) =>
  179. expect(err).to.not.be.oneOf [null, undefined]
  180. expect(err).to.be.instanceof Error
  181. done()
  182. it 'should not call UserSessionsManager.trackSession', (done) ->
  183. @call (err) =>
  184. @UserSessionsManager.trackSession.callCount.should.equal 0
  185. done()
  186. describe 'when GeoIpLookup produces an error', ->
  187. beforeEach ->
  188. @GeoIpLookup.getDetails = sinon.stub()
  189. .callsArgWith(1, new Error('woops'))
  190. it 'should not produce an error', (done) ->
  191. @call (err) =>
  192. expect(err).to.not.exist
  193. done()
  194. it 'should still call req.session.save', (done) ->
  195. @call (err) =>
  196. @req.session.save.callCount.should.equal 1
  197. expect(@req.session.countryCode).to.equal null
  198. done()
  199. describe 'when GeoIpLookup produces no data', ->
  200. beforeEach ->
  201. @GeoIpLookup.getDetails = sinon.stub()
  202. .callsArgWith(1, null, undefined)
  203. it 'should not produce an error', (done) ->
  204. @call (err) =>
  205. expect(err).to.not.exist
  206. done()
  207. it 'should still call req.session.save', (done) ->
  208. @call (err) =>
  209. @req.session.save.callCount.should.equal 1
  210. expect(@req.session.countryCode).to.equal null
  211. done()
  212. describe 'getSessionUser', ->
  213. it 'should get the user object from session', ->
  214. @req.session =
  215. passport:
  216. user: {_id: 'one'}
  217. user = @AuthenticationController.getSessionUser(@req)
  218. expect(user).to.deep.equal {_id: 'one'}
  219. it 'should work with legacy sessions', ->
  220. @req.session =
  221. user: {_id: 'one'}
  222. user = @AuthenticationController.getSessionUser(@req)
  223. expect(user).to.deep.equal {_id: 'one'}
  224. describe "doPassportLogin", ->
  225. beforeEach ->
  226. @AuthenticationController._recordFailedLogin = sinon.stub()
  227. @AuthenticationController._recordSuccessfulLogin = sinon.stub()
  228. # @AuthenticationController.establishUserSession = sinon.stub().callsArg(2)
  229. @req.body =
  230. email: @email
  231. password: @password
  232. session:
  233. postLoginRedirect: "/path/to/redir/to"
  234. @cb = sinon.stub()
  235. describe "when the users rate limit", ->
  236. beforeEach ->
  237. @LoginRateLimiter.processLoginRequest.callsArgWith(1, null, false)
  238. it "should block the request if the limit has been exceeded", (done)->
  239. @AuthenticationController.doPassportLogin(@req, @req.body.email, @req.body.password, @cb)
  240. @cb.callCount.should.equal 1
  241. @cb.calledWith(null, null).should.equal true
  242. done()
  243. describe 'when the user is authenticated', ->
  244. beforeEach ->
  245. @cb = sinon.stub()
  246. @LoginRateLimiter.processLoginRequest.callsArgWith(1, null, true)
  247. @AuthenticationManager.authenticate = sinon.stub().callsArgWith(2, null, @user)
  248. @req.sessionID = Math.random()
  249. @AnalyticsManager.identifyUser = sinon.stub()
  250. @AuthenticationController.doPassportLogin(@req, @req.body.email, @req.body.password, @cb)
  251. it "should attempt to authorise the user", ->
  252. @AuthenticationManager.authenticate
  253. .calledWith(email: @email.toLowerCase(), @password)
  254. .should.equal true
  255. it "should call identifyUser", ->
  256. @AnalyticsManager.identifyUser.calledWith(@user._id, @req.sessionID).should.equal true
  257. it "should setup the user data in the background", ->
  258. @UserHandler.setupLoginData.calledWith(@user).should.equal true
  259. it "should establish the user's session", ->
  260. @cb.calledWith(null, @user).should.equal true
  261. it "should set res.session.justLoggedIn", ->
  262. @req.session.justLoggedIn.should.equal true
  263. it "should record the successful login", ->
  264. @AuthenticationController._recordSuccessfulLogin
  265. .calledWith(@user._id)
  266. .should.equal true
  267. it "should tell the rate limiter that there was a success for that email", ->
  268. @LoginRateLimiter.recordSuccessfulLogin.calledWith(@email.toLowerCase()).should.equal true
  269. it "should log the successful login", ->
  270. @logger.log
  271. .calledWith(email: @email.toLowerCase(), user_id: @user._id.toString(), "successful log in")
  272. .should.equal true
  273. it "should track the login event", ->
  274. @AnalyticsManager.recordEvent
  275. .calledWith(@user._id, "user-logged-in")
  276. .should.equal true
  277. describe 'when the user is not authenticated', ->
  278. beforeEach ->
  279. @LoginRateLimiter.processLoginRequest.callsArgWith(1, null, true)
  280. @AuthenticationManager.authenticate = sinon.stub().callsArgWith(2, null, null)
  281. @cb = sinon.stub()
  282. @AuthenticationController.doPassportLogin(@req, @req.body.email, @req.body.password, @cb)
  283. it "should not establish the login", ->
  284. @cb.callCount.should.equal 1
  285. @cb.calledWith(null, false)
  286. # @res.body.should.exist
  287. expect(@cb.lastCall.args[2]).to.contain.all.keys ['text', 'type']
  288. # message:
  289. # text: 'Your email or password were incorrect. Please try again',
  290. # type: 'error'
  291. it "should not setup the user data in the background", ->
  292. @UserHandler.setupLoginData.called.should.equal false
  293. it "should record a failed login", ->
  294. @AuthenticationController._recordFailedLogin.called.should.equal true
  295. it "should log the failed login", ->
  296. @logger.log
  297. .calledWith(email: @email.toLowerCase(), "failed log in")
  298. .should.equal true
  299. describe "getLoggedInUserId", ->
  300. beforeEach ->
  301. @req =
  302. session :{}
  303. it "should return the user id from the session", ()->
  304. @user_id = "2134"
  305. @req.session.user =
  306. _id:@user_id
  307. result = @AuthenticationController.getLoggedInUserId @req
  308. expect(result).to.equal @user_id
  309. it 'should return user for passport session', () ->
  310. @user_id = "2134"
  311. @req.session = {
  312. passport: {
  313. user: {
  314. _id:@user_id
  315. }
  316. }
  317. }
  318. result = @AuthenticationController.getLoggedInUserId @req
  319. expect(result).to.equal @user_id
  320. it "should return null if there is no user on the session", ()->
  321. result = @AuthenticationController.getLoggedInUserId @req
  322. expect(result).to.equal null
  323. it "should return null if there is no session", ()->
  324. @req = {}
  325. result = @AuthenticationController.getLoggedInUserId @req
  326. expect(result).to.equal null
  327. it "should return null if there is no req", ()->
  328. @req = {}
  329. result = @AuthenticationController.getLoggedInUserId @req
  330. expect(result).to.equal null
  331. describe "requireLogin", ->
  332. beforeEach ->
  333. @user =
  334. _id: "user-id-123"
  335. email: "user@sharelatex.com"
  336. @middleware = @AuthenticationController.requireLogin()
  337. describe "when the user is logged in", ->
  338. beforeEach ->
  339. @req.session =
  340. user: @user = {
  341. _id: "user-id-123"
  342. email: "user@sharelatex.com"
  343. }
  344. @middleware(@req, @res, @next)
  345. it "should call the next method in the chain", ->
  346. @next.called.should.equal true
  347. describe "when the user is not logged in", ->
  348. beforeEach ->
  349. @req.session = {}
  350. @AuthenticationController._redirectToLoginOrRegisterPage = sinon.stub()
  351. @req.query = {}
  352. @middleware(@req, @res, @next)
  353. it "should redirect to the register or login page", ->
  354. @AuthenticationController._redirectToLoginOrRegisterPage.calledWith(@req, @res).should.equal true
  355. describe "requireGlobalLogin", ->
  356. beforeEach ->
  357. @req.headers = {}
  358. @AuthenticationController.httpAuth = sinon.stub()
  359. @_setRedirect = sinon.spy(@AuthenticationController, '_setRedirectInSession')
  360. afterEach ->
  361. @_setRedirect.restore()
  362. describe "with white listed url", ->
  363. beforeEach ->
  364. @AuthenticationController.addEndpointToLoginWhitelist "/login"
  365. @req._parsedUrl.pathname = "/login"
  366. @AuthenticationController.requireGlobalLogin @req, @res, @next
  367. it "should call next() directly", ->
  368. @next.called.should.equal true
  369. describe "with white listed url and a query string", ->
  370. beforeEach ->
  371. @AuthenticationController.addEndpointToLoginWhitelist "/login"
  372. @req._parsedUrl.pathname = "/login"
  373. @req.url = "/login?query=something"
  374. @AuthenticationController.requireGlobalLogin @req, @res, @next
  375. it "should call next() directly", ->
  376. @next.called.should.equal true
  377. describe "with http auth", ->
  378. beforeEach ->
  379. @req.headers["authorization"] = "Mock Basic Auth"
  380. @AuthenticationController.requireGlobalLogin @req, @res, @next
  381. it "should pass the request onto httpAuth", ->
  382. @AuthenticationController.httpAuth
  383. .calledWith(@req, @res, @next)
  384. .should.equal true
  385. describe "with a user session", ->
  386. beforeEach ->
  387. @req.session =
  388. user: {"mock": "user", "_id": "some_id"}
  389. @AuthenticationController.requireGlobalLogin @req, @res, @next
  390. it "should call next() directly", ->
  391. @next.called.should.equal true
  392. describe "with no login credentials", ->
  393. beforeEach ->
  394. @req.session = {}
  395. @AuthenticationController.requireGlobalLogin @req, @res, @next
  396. it 'should have called setRedirectInSession', ->
  397. @_setRedirect.callCount.should.equal 1
  398. it "should redirect to the /login page", ->
  399. @res.redirectedTo.should.equal "/login"
  400. describe "_redirectToLoginOrRegisterPage", ->
  401. beforeEach ->
  402. @middleware = @AuthenticationController.requireLogin(@options = { load_from_db: false })
  403. @req.session = {}
  404. @AuthenticationController._redirectToRegisterPage = sinon.stub()
  405. @AuthenticationController._redirectToLoginPage = sinon.stub()
  406. @req.query = {}
  407. describe "they have come directly to the url", ->
  408. beforeEach ->
  409. @req.query = {}
  410. @middleware(@req, @res, @next)
  411. it "should redirect to the login page", ->
  412. @AuthenticationController._redirectToRegisterPage.calledWith(@req, @res).should.equal false
  413. @AuthenticationController._redirectToLoginPage.calledWith(@req, @res).should.equal true
  414. describe "they have come via a templates link", ->
  415. beforeEach ->
  416. @req.query.zipUrl = "something"
  417. @middleware(@req, @res, @next)
  418. it "should redirect to the register page", ->
  419. @AuthenticationController._redirectToRegisterPage.calledWith(@req, @res).should.equal true
  420. @AuthenticationController._redirectToLoginPage.calledWith(@req, @res).should.equal false
  421. describe "they have been invited to a project", ->
  422. beforeEach ->
  423. @req.query.project_name = "something"
  424. @middleware(@req, @res, @next)
  425. it "should redirect to the register page", ->
  426. @AuthenticationController._redirectToRegisterPage.calledWith(@req, @res).should.equal true
  427. @AuthenticationController._redirectToLoginPage.calledWith(@req, @res).should.equal false
  428. describe "_redirectToRegisterPage", ->
  429. beforeEach ->
  430. @req.path = "/target/url"
  431. @req.query =
  432. extra_query: "foo"
  433. @AuthenticationController._redirectToRegisterPage(@req, @res)
  434. it "should redirect to the register page with a query string attached", ->
  435. @req.session.postLoginRedirect.should.equal '/target/url?extra_query=foo'
  436. @res.redirectedTo.should.equal "/register?extra_query=foo"
  437. it "should log out a message", ->
  438. @logger.log
  439. .calledWith(url: @url, "user not logged in so redirecting to register page")
  440. .should.equal true
  441. describe "_redirectToLoginPage", ->
  442. beforeEach ->
  443. @req.path = "/target/url"
  444. @req.query =
  445. extra_query: "foo"
  446. @AuthenticationController._redirectToLoginPage(@req, @res)
  447. it "should redirect to the register page with a query string attached", ->
  448. @req.session.postLoginRedirect.should.equal '/target/url?extra_query=foo'
  449. @res.redirectedTo.should.equal "/login?extra_query=foo"
  450. describe "_recordSuccessfulLogin", ->
  451. beforeEach ->
  452. @UserUpdater.updateUser = sinon.stub().callsArg(2)
  453. @AuthenticationController._recordSuccessfulLogin(@user._id, @callback)
  454. it "should increment the user.login.success metric", ->
  455. @Metrics.inc
  456. .calledWith("user.login.success")
  457. .should.equal true
  458. it "should update the user's login count and last logged in date", ->
  459. @UserUpdater.updateUser.args[0][1]["$set"]["lastLoggedIn"].should.not.equal undefined
  460. @UserUpdater.updateUser.args[0][1]["$inc"]["loginCount"].should.equal 1
  461. it "should call the callback", ->
  462. @callback.called.should.equal true
  463. describe "_recordFailedLogin", ->
  464. beforeEach ->
  465. @AuthenticationController._recordFailedLogin(@callback)
  466. it "should increment the user.login.failed metric", ->
  467. @Metrics.inc
  468. .calledWith("user.login.failed")
  469. .should.equal true
  470. it "should call the callback", ->
  471. @callback.called.should.equal true
  472. describe '_setRedirectInSession', ->
  473. beforeEach ->
  474. @req = {session: {}}
  475. @req.path = "/somewhere"
  476. @req.query = {one: "1"}
  477. it 'should set redirect property on session', ->
  478. @AuthenticationController._setRedirectInSession(@req)
  479. expect(@req.session.postLoginRedirect).to.equal "/somewhere?one=1"
  480. it 'should set the supplied value', ->
  481. @AuthenticationController._setRedirectInSession(@req, '/somewhere/specific')
  482. expect(@req.session.postLoginRedirect).to.equal "/somewhere/specific"
  483. describe 'with a png', ->
  484. beforeEach ->
  485. @req = {session: {}}
  486. it 'should not set the redirect', ->
  487. @AuthenticationController._setRedirectInSession(@req, '/something.png')
  488. expect(@req.session.postLoginRedirect).to.equal undefined
  489. describe 'with a js path', ->
  490. beforeEach ->
  491. @req = {session: {}}
  492. it 'should not set the redirect', ->
  493. @AuthenticationController._setRedirectInSession(@req, '/js/something.js')
  494. expect(@req.session.postLoginRedirect).to.equal undefined
  495. describe '_getRedirectFromSession', ->
  496. beforeEach ->
  497. @req = {session: {postLoginRedirect: "/a?b=c"}}
  498. it 'should get redirect property from session', ->
  499. expect(@AuthenticationController._getRedirectFromSession(@req)).to.equal "/a?b=c"
  500. describe '_clearRedirectFromSession', ->
  501. beforeEach ->
  502. @req = {session: {postLoginRedirect: "/a?b=c"}}
  503. it 'should remove the redirect property from session', ->
  504. @AuthenticationController._clearRedirectFromSession(@req)
  505. expect(@req.session.postLoginRedirect).to.equal undefined