ProjectInviteTests.mjs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865
  1. import { expect } from 'chai'
  2. import Async from 'async'
  3. import User from './helpers/User.mjs'
  4. import settings from '@overleaf/settings'
  5. import CollaboratorsEmailHandler from '../../../app/src/Features/Collaborators/CollaboratorsEmailHandler.mjs'
  6. import CollaboratorsInviteHelper from '../../../app/src/Features/Collaborators/CollaboratorsInviteHelper.js'
  7. import Features from '../../../app/src/infrastructure/Features.js'
  8. import cheerio from 'cheerio'
  9. import sinon from 'sinon'
  10. let generateTokenSpy
  11. const createInvite = (sendingUser, projectId, email, callback) => {
  12. sendingUser.getCsrfToken(err => {
  13. if (err) {
  14. return callback(err)
  15. }
  16. sendingUser.request.post(
  17. {
  18. uri: `/project/${projectId}/invite`,
  19. json: {
  20. email,
  21. privileges: 'readAndWrite',
  22. },
  23. },
  24. (err, response, body) => {
  25. if (err) {
  26. return callback(err)
  27. }
  28. expect(response.statusCode).to.equal(200)
  29. expect(body.error).to.not.exist
  30. expect(body.invite).to.exist
  31. callback(null, body.invite)
  32. }
  33. )
  34. })
  35. }
  36. const createProject = (owner, projectName, callback) => {
  37. owner.createProject(projectName, (err, projectId) => {
  38. if (err) {
  39. throw err
  40. }
  41. const fakeProject = {
  42. _id: projectId,
  43. name: projectName,
  44. owner_ref: owner,
  45. }
  46. callback(err, projectId, fakeProject)
  47. })
  48. }
  49. const createProjectAndInvite = (owner, projectName, email, callback) => {
  50. createProject(owner, projectName, (err, projectId, project) => {
  51. if (err) {
  52. return callback(err)
  53. }
  54. createInvite(owner, projectId, email, (err, invite) => {
  55. if (err) {
  56. return callback(err)
  57. }
  58. // attach the token to the invite
  59. invite.token = generateTokenSpy.getCall(0).returnValue
  60. const link = CollaboratorsEmailHandler._buildInviteUrl(project, invite)
  61. callback(null, project, invite, link)
  62. })
  63. })
  64. }
  65. const revokeInvite = (sendingUser, projectId, inviteId, callback) => {
  66. sendingUser.getCsrfToken(err => {
  67. if (err) {
  68. return callback(err)
  69. }
  70. sendingUser.request.delete(
  71. {
  72. uri: `/project/${projectId}/invite/${inviteId}`,
  73. },
  74. err => {
  75. if (err) {
  76. return callback(err)
  77. }
  78. callback()
  79. }
  80. )
  81. })
  82. }
  83. // Actions
  84. const tryFollowInviteLink = (user, link, callback) => {
  85. user.request.get(
  86. {
  87. uri: link,
  88. baseUrl: null,
  89. },
  90. callback
  91. )
  92. }
  93. const tryAcceptInvite = (user, invite, projectId, callback) => {
  94. user.getCsrfToken(err => {
  95. if (err) {
  96. return callback(err)
  97. }
  98. user.request.post(
  99. {
  100. uri: `/project/${projectId}/invite/token/${invite.token}/accept`,
  101. json: {
  102. token: invite.token,
  103. },
  104. },
  105. callback
  106. )
  107. })
  108. }
  109. const tryFollowLoginLink = (user, loginLink, callback) => {
  110. user.getCsrfToken(error => {
  111. if (error != null) {
  112. return callback(error)
  113. }
  114. user.request.get(loginLink, callback)
  115. })
  116. }
  117. const tryLoginUser = (user, callback) => {
  118. user.getCsrfToken(error => {
  119. if (error != null) {
  120. return callback(error)
  121. }
  122. user.request.post(
  123. {
  124. url: '/login',
  125. json: {
  126. email: user.email,
  127. password: user.password,
  128. 'g-recaptcha-response': 'valid',
  129. },
  130. },
  131. callback
  132. )
  133. })
  134. }
  135. const tryGetInviteList = (user, projectId, callback) => {
  136. user.getCsrfToken(error => {
  137. if (error != null) {
  138. return callback(error)
  139. }
  140. user.request.get(
  141. {
  142. url: `/project/${projectId}/invites`,
  143. json: true,
  144. },
  145. callback
  146. )
  147. })
  148. }
  149. const tryJoinProject = (user, projectId, callback) => {
  150. return user.getCsrfToken(error => {
  151. if (error != null) {
  152. return callback(error)
  153. }
  154. user.request.post(
  155. {
  156. url: `/project/${projectId}/join`,
  157. auth: {
  158. user: settings.apis.web.user,
  159. pass: settings.apis.web.pass,
  160. sendImmediately: true,
  161. },
  162. json: { userId: user._id },
  163. jar: false,
  164. },
  165. callback
  166. )
  167. })
  168. }
  169. // Expectations
  170. const expectProjectAccess = (user, projectId, callback) => {
  171. // should have access to project
  172. user.openProject(projectId, err => {
  173. expect(err).not.to.exist
  174. callback()
  175. })
  176. }
  177. const expectNoProjectAccess = (user, projectId, callback) => {
  178. // should not have access to project page
  179. user.openProject(projectId, err => {
  180. expect(err).to.be.instanceof(Error)
  181. callback()
  182. })
  183. }
  184. const expectInvitePage = (user, link, callback) => {
  185. // view invite
  186. tryFollowInviteLink(user, link, (err, response, body) => {
  187. expect(err).not.to.exist
  188. expect(response.statusCode).to.equal(200)
  189. expect(body).to.match(/<title>Project Invite - .*<\/title>/)
  190. callback()
  191. })
  192. }
  193. const expectInvalidInvitePage = (user, link, callback) => {
  194. // view invalid invite
  195. tryFollowInviteLink(user, link, (err, response, body) => {
  196. expect(err).not.to.exist
  197. expect(response.statusCode).to.equal(404)
  198. expect(body).to.match(/<title>Invalid Invite - .*<\/title>/)
  199. callback()
  200. })
  201. }
  202. const expectInviteRedirectToRegister = (user, link, callback) => {
  203. // view invite, redirect to `/register`
  204. tryFollowInviteLink(user, link, (err, response) => {
  205. expect(err).not.to.exist
  206. expect(response.statusCode).to.equal(302)
  207. expect(response.headers.location).to.match(/^\/register.*$/)
  208. user.getSession((err, session) => {
  209. if (err) return callback(err)
  210. expect(session.sharedProjectData).deep.equals({
  211. project_name: PROJECT_NAME,
  212. user_first_name: OWNER_NAME,
  213. })
  214. callback()
  215. })
  216. })
  217. }
  218. const expectLoginPage = (user, callback) => {
  219. tryFollowLoginLink(user, '/login', (err, response, body) => {
  220. expect(err).not.to.exist
  221. expect(response.statusCode).to.equal(200)
  222. expect(body).to.match(/<title>(Login|Log in to Overleaf) - .*<\/title>/)
  223. callback()
  224. })
  225. }
  226. const expectLoginRedirectToInvite = (user, link, callback) => {
  227. tryLoginUser(user, (err, response) => {
  228. expect(err).not.to.exist
  229. expect(response.statusCode).to.equal(200)
  230. callback()
  231. })
  232. }
  233. const expectRegistrationRedirectToInvite = (user, link, callback) => {
  234. user.register((err, _user, response) => {
  235. expect(err).not.to.exist
  236. expect(response.statusCode).to.equal(200)
  237. if (response.body.redir === '/registration/try-premium') {
  238. user.request.get('/registration/onboarding', (err, response) => {
  239. if (err) return callback(err)
  240. expect(response.statusCode).to.equal(200)
  241. const dom = cheerio.load(response.body)
  242. const skipUrl = dom('meta[name="ol-skipUrl"]')[0].attribs.content
  243. expect(new URL(skipUrl, settings.siteUrl).href).to.equal(
  244. new URL(link, settings.siteUrl).href
  245. )
  246. callback()
  247. })
  248. } else {
  249. expect(response.body.redir).to.equal(link)
  250. callback()
  251. }
  252. })
  253. }
  254. const expectInviteRedirectToProject = (user, link, projectId, callback) => {
  255. // view invite, redirect straight to project
  256. tryFollowInviteLink(user, link, (err, response) => {
  257. expect(err).not.to.exist
  258. expect(response.statusCode).to.equal(302)
  259. expect(response.headers.location).to.equal(`/project/${projectId}`)
  260. callback()
  261. })
  262. }
  263. const expectAcceptInviteAndRedirect = (user, invite, projectId, callback) => {
  264. // should accept the invite and redirect to project
  265. tryAcceptInvite(user, invite, projectId, (err, response) => {
  266. expect(err).not.to.exist
  267. expect(response.statusCode).to.equal(302)
  268. expect(response.headers.location).to.equal(`/project/${projectId}`)
  269. callback()
  270. })
  271. }
  272. const expectInviteListCount = (user, projectId, count, callback) => {
  273. tryGetInviteList(user, projectId, (err, response, body) => {
  274. expect(err).not.to.exist
  275. expect(response.statusCode).to.equal(200)
  276. expect(body).to.have.all.keys(['invites'])
  277. expect(body.invites.length).to.equal(count)
  278. callback()
  279. })
  280. }
  281. const expectInvitesInJoinProjectCount = (user, projectId, count, callback) => {
  282. tryJoinProject(user, projectId, (err, response, body) => {
  283. expect(err).not.to.exist
  284. expect(response.statusCode).to.equal(200)
  285. expect(body.project).to.contain.keys(['invites'])
  286. expect(body.project.invites.length).to.equal(count)
  287. callback()
  288. })
  289. }
  290. const PROJECT_NAME = 'project name for sharing test'
  291. const OWNER_NAME = 'sending user name'
  292. describe('ProjectInviteTests', function () {
  293. beforeEach(function (done) {
  294. this.sendingUser = new User()
  295. this.user = new User()
  296. this.site_admin = new User({ email: `admin+${Math.random()}@example.com` })
  297. this.email = `smoketestuser+${Math.random()}@example.com`
  298. generateTokenSpy = sinon.spy(CollaboratorsInviteHelper, 'generateToken')
  299. Async.series(
  300. [
  301. cb => this.sendingUser.ensureUserExists(cb),
  302. cb => this.sendingUser.upgradeFeatures({ collaborators: 10 }, cb),
  303. cb => this.sendingUser.login(cb),
  304. cb =>
  305. this.sendingUser.mongoUpdate(
  306. {
  307. $set: { first_name: OWNER_NAME },
  308. },
  309. cb
  310. ),
  311. ],
  312. done
  313. )
  314. })
  315. afterEach(function () {
  316. generateTokenSpy.restore()
  317. })
  318. describe('creating invites', function () {
  319. describe('creating two invites', function () {
  320. beforeEach(function (done) {
  321. createProject(
  322. this.sendingUser,
  323. PROJECT_NAME,
  324. (err, projectId, project) => {
  325. expect(err).not.to.exist
  326. this.projectId = projectId
  327. this.fakeProject = project
  328. done()
  329. }
  330. )
  331. })
  332. it('should fail if email is not a string', function (done) {
  333. this.sendingUser.getCsrfToken(err => {
  334. if (err) {
  335. return done(err)
  336. }
  337. this.sendingUser.request.post(
  338. {
  339. uri: `/project/${this.projectId}/invite`,
  340. json: {
  341. email: {},
  342. privileges: 'readAndWrite',
  343. },
  344. },
  345. (err, response, body) => {
  346. if (err) {
  347. return done(err)
  348. }
  349. expect(response.statusCode).to.equal(400)
  350. expect(response.body.validation.body.message).to.equal(
  351. '"email" must be a string'
  352. )
  353. done()
  354. }
  355. )
  356. })
  357. })
  358. it('should fail on invalid privileges', function (done) {
  359. this.sendingUser.getCsrfToken(err => {
  360. if (err) {
  361. return done(err)
  362. }
  363. this.sendingUser.request.post(
  364. {
  365. uri: `/project/${this.projectId}/invite`,
  366. json: {
  367. email: this.email,
  368. privileges: 'invalid-privilege',
  369. },
  370. },
  371. (err, response, body) => {
  372. if (err) {
  373. return done(err)
  374. }
  375. expect(response.statusCode).to.equal(400)
  376. expect(response.body.validation.body.message).to.equal(
  377. '"privileges" must be one of [readOnly, readAndWrite, review]'
  378. )
  379. done()
  380. }
  381. )
  382. })
  383. })
  384. it('should allow the project owner to create and remove invites', function (done) {
  385. Async.series(
  386. [
  387. cb => expectProjectAccess(this.sendingUser, this.projectId, cb),
  388. cb =>
  389. expectInviteListCount(this.sendingUser, this.projectId, 0, cb),
  390. // create invite, check invite list count
  391. cb => {
  392. createInvite(
  393. this.sendingUser,
  394. this.projectId,
  395. this.email,
  396. (err, invite) => {
  397. if (err) {
  398. return cb(err)
  399. }
  400. this.invite = invite
  401. cb()
  402. }
  403. )
  404. },
  405. cb =>
  406. expectInviteListCount(this.sendingUser, this.projectId, 1, cb),
  407. cb =>
  408. revokeInvite(
  409. this.sendingUser,
  410. this.projectId,
  411. this.invite._id,
  412. cb
  413. ),
  414. cb =>
  415. expectInviteListCount(this.sendingUser, this.projectId, 0, cb),
  416. // and a second time
  417. cb => {
  418. createInvite(
  419. this.sendingUser,
  420. this.projectId,
  421. this.email,
  422. (err, invite) => {
  423. if (err) {
  424. return cb(err)
  425. }
  426. this.invite = invite
  427. cb()
  428. }
  429. )
  430. },
  431. cb =>
  432. expectInviteListCount(this.sendingUser, this.projectId, 1, cb),
  433. // check the joinProject view
  434. cb =>
  435. expectInvitesInJoinProjectCount(
  436. this.sendingUser,
  437. this.projectId,
  438. 1,
  439. cb
  440. ),
  441. // revoke invite
  442. cb =>
  443. revokeInvite(
  444. this.sendingUser,
  445. this.projectId,
  446. this.invite._id,
  447. cb
  448. ),
  449. cb =>
  450. expectInviteListCount(this.sendingUser, this.projectId, 0, cb),
  451. cb =>
  452. expectInvitesInJoinProjectCount(
  453. this.sendingUser,
  454. this.projectId,
  455. 0,
  456. cb
  457. ),
  458. ],
  459. done
  460. )
  461. })
  462. it('should allow the project owner to create many invites at once', function (done) {
  463. Async.series(
  464. [
  465. cb => expectProjectAccess(this.sendingUser, this.projectId, cb),
  466. cb =>
  467. expectInviteListCount(this.sendingUser, this.projectId, 0, cb),
  468. // create first invite
  469. cb => {
  470. createInvite(
  471. this.sendingUser,
  472. this.projectId,
  473. this.email,
  474. (err, invite) => {
  475. if (err) {
  476. return cb(err)
  477. }
  478. this.inviteOne = invite
  479. cb()
  480. }
  481. )
  482. },
  483. cb =>
  484. expectInviteListCount(this.sendingUser, this.projectId, 1, cb),
  485. // and a second
  486. cb => {
  487. createInvite(
  488. this.sendingUser,
  489. this.projectId,
  490. this.email,
  491. (err, invite) => {
  492. if (err) {
  493. return cb(err)
  494. }
  495. this.inviteTwo = invite
  496. cb()
  497. }
  498. )
  499. },
  500. // should have two
  501. cb =>
  502. expectInviteListCount(this.sendingUser, this.projectId, 2, cb),
  503. cb =>
  504. expectInvitesInJoinProjectCount(
  505. this.sendingUser,
  506. this.projectId,
  507. 2,
  508. cb
  509. ),
  510. // revoke first
  511. cb =>
  512. revokeInvite(
  513. this.sendingUser,
  514. this.projectId,
  515. this.inviteOne._id,
  516. cb
  517. ),
  518. cb =>
  519. expectInviteListCount(this.sendingUser, this.projectId, 1, cb),
  520. // revoke second
  521. cb =>
  522. revokeInvite(
  523. this.sendingUser,
  524. this.projectId,
  525. this.inviteTwo._id,
  526. cb
  527. ),
  528. cb =>
  529. expectInviteListCount(this.sendingUser, this.projectId, 0, cb),
  530. ],
  531. done
  532. )
  533. })
  534. })
  535. })
  536. describe('clicking the invite link', function () {
  537. beforeEach(function (done) {
  538. createProjectAndInvite(
  539. this.sendingUser,
  540. PROJECT_NAME,
  541. this.email,
  542. (err, project, invite, link) => {
  543. expect(err).not.to.exist
  544. this.projectId = project._id
  545. this.fakeProject = project
  546. this.invite = invite
  547. this.link = link
  548. done()
  549. }
  550. )
  551. })
  552. describe('user is logged in already', function () {
  553. beforeEach(function (done) {
  554. this.user.login(done)
  555. })
  556. describe('user is already a member of the project', function () {
  557. beforeEach(function (done) {
  558. Async.series(
  559. [
  560. cb => expectInvitePage(this.user, this.link, cb),
  561. cb =>
  562. expectAcceptInviteAndRedirect(
  563. this.user,
  564. this.invite,
  565. this.projectId,
  566. cb
  567. ),
  568. cb => expectProjectAccess(this.user, this.projectId, cb),
  569. ],
  570. done
  571. )
  572. })
  573. describe('when user clicks on the invite a second time', function () {
  574. it('should just redirect to the project page', function (done) {
  575. Async.series(
  576. [
  577. cb => expectProjectAccess(this.user, this.projectId, cb),
  578. cb =>
  579. expectInviteRedirectToProject(
  580. this.user,
  581. this.link,
  582. this.projectId,
  583. cb
  584. ),
  585. cb => expectProjectAccess(this.user, this.projectId, cb),
  586. ],
  587. done
  588. )
  589. })
  590. describe('when the user recieves another invite to the same project', function () {
  591. it('should redirect to the project page', function (done) {
  592. Async.series(
  593. [
  594. cb => {
  595. createInvite(
  596. this.sendingUser,
  597. this.projectId,
  598. this.email,
  599. (err, invite) => {
  600. if (err) {
  601. throw err
  602. }
  603. this.secondInvite = invite
  604. const token = generateTokenSpy.getCall(1).returnValue
  605. this.secondLink =
  606. CollaboratorsEmailHandler._buildInviteUrl(
  607. this.fakeProject,
  608. { ...invite, token }
  609. )
  610. cb()
  611. }
  612. )
  613. },
  614. cb =>
  615. expectInviteRedirectToProject(
  616. this.user,
  617. this.secondLink,
  618. this.projectId,
  619. cb
  620. ),
  621. cb => expectProjectAccess(this.user, this.projectId, cb),
  622. cb =>
  623. revokeInvite(
  624. this.sendingUser,
  625. this.projectId,
  626. this.secondInvite._id,
  627. cb
  628. ),
  629. ],
  630. done
  631. )
  632. })
  633. })
  634. })
  635. })
  636. describe('user is not a member of the project', function () {
  637. it('should not grant access if the user does not accept the invite', function (done) {
  638. Async.series(
  639. [
  640. cb => expectInvitePage(this.user, this.link, cb),
  641. cb => expectNoProjectAccess(this.user, this.projectId, cb),
  642. ],
  643. done
  644. )
  645. })
  646. it('should render the invalid-invite page if the token is invalid', function (done) {
  647. Async.series(
  648. [
  649. cb => {
  650. const link = this.link.replace(
  651. this.invite.token,
  652. 'not_a_real_token'
  653. )
  654. expectInvalidInvitePage(this.user, link, cb)
  655. },
  656. cb => expectNoProjectAccess(this.user, this.projectId, cb),
  657. cb => expectNoProjectAccess(this.user, this.projectId, cb),
  658. ],
  659. done
  660. )
  661. })
  662. it('should allow the user to accept the invite and access the project', function (done) {
  663. Async.series(
  664. [
  665. cb => expectInvitePage(this.user, this.link, cb),
  666. cb =>
  667. expectAcceptInviteAndRedirect(
  668. this.user,
  669. this.invite,
  670. this.projectId,
  671. cb
  672. ),
  673. cb => expectProjectAccess(this.user, this.projectId, cb),
  674. ],
  675. done
  676. )
  677. })
  678. })
  679. })
  680. describe('user is not logged in initially', function () {
  681. describe('registration prompt workflow with valid token', function () {
  682. before(function () {
  683. if (!Features.hasFeature('registration')) {
  684. this.skip()
  685. }
  686. })
  687. it('should redirect to the register page', function (done) {
  688. expectInviteRedirectToRegister(this.user, this.link, done)
  689. })
  690. it('should allow user to accept the invite if the user registers a new account', function (done) {
  691. Async.series(
  692. [
  693. cb => expectInviteRedirectToRegister(this.user, this.link, cb),
  694. cb =>
  695. expectRegistrationRedirectToInvite(this.user, this.link, cb),
  696. cb => expectInvitePage(this.user, this.link, cb),
  697. cb =>
  698. expectAcceptInviteAndRedirect(
  699. this.user,
  700. this.invite,
  701. this.projectId,
  702. cb
  703. ),
  704. cb => expectProjectAccess(this.user, this.projectId, cb),
  705. ],
  706. done
  707. )
  708. })
  709. })
  710. describe('registration prompt workflow with non-valid token', function () {
  711. before(function () {
  712. if (!Features.hasFeature('registration')) {
  713. this.skip()
  714. }
  715. })
  716. it('should redirect to the register page', function (done) {
  717. Async.series(
  718. [
  719. cb => expectInviteRedirectToRegister(this.user, this.link, cb),
  720. cb => expectNoProjectAccess(this.user, this.projectId, cb),
  721. ],
  722. done
  723. )
  724. })
  725. it('should display invalid-invite right away', function (done) {
  726. const badLink = this.link.replace(
  727. this.invite.token,
  728. 'not_a_real_token'
  729. )
  730. Async.series(
  731. [
  732. cb => expectInvalidInvitePage(this.user, badLink, cb),
  733. cb => expectNoProjectAccess(this.user, this.projectId, cb),
  734. ],
  735. done
  736. )
  737. })
  738. })
  739. describe('login workflow with valid token', function () {
  740. beforeEach(function (done) {
  741. this.user.ensureUserExists(done)
  742. })
  743. it('should redirect to the register page', function (done) {
  744. Async.series(
  745. [
  746. cb => expectInviteRedirectToRegister(this.user, this.link, cb),
  747. cb => expectNoProjectAccess(this.user, this.projectId, cb),
  748. ],
  749. done
  750. )
  751. })
  752. it('should allow the user to login to view the invite', function (done) {
  753. Async.series(
  754. [
  755. cb => expectInviteRedirectToRegister(this.user, this.link, cb),
  756. cb => expectLoginPage(this.user, cb),
  757. cb => expectLoginRedirectToInvite(this.user, this.link, cb),
  758. cb => expectInvitePage(this.user, this.link, cb),
  759. cb => expectNoProjectAccess(this.user, this.projectId, cb),
  760. ],
  761. done
  762. )
  763. })
  764. it('should allow user to accept the invite if the user logs in', function (done) {
  765. Async.series(
  766. [
  767. cb => expectInviteRedirectToRegister(this.user, this.link, cb),
  768. cb => expectLoginPage(this.user, cb),
  769. cb => expectLoginRedirectToInvite(this.user, this.link, cb),
  770. cb => expectInvitePage(this.user, this.link, cb),
  771. cb =>
  772. expectAcceptInviteAndRedirect(
  773. this.user,
  774. this.invite,
  775. this.projectId,
  776. cb
  777. ),
  778. cb => expectProjectAccess(this.user, this.projectId, cb),
  779. ],
  780. done
  781. )
  782. })
  783. })
  784. describe('login workflow with non-valid token', function () {
  785. it('should redirect to the register page', function (done) {
  786. Async.series(
  787. [
  788. cb => expectInviteRedirectToRegister(this.user, this.link, cb),
  789. cb => expectNoProjectAccess(this.user, this.projectId, cb),
  790. ],
  791. done
  792. )
  793. })
  794. it('should show the invalid-invite page right away', function (done) {
  795. const badLink = this.link.replace(
  796. this.invite.token,
  797. 'not_a_real_token'
  798. )
  799. Async.series(
  800. [
  801. cb => expectInvalidInvitePage(this.user, badLink, cb),
  802. cb => expectNoProjectAccess(this.user, this.projectId, cb),
  803. ],
  804. done
  805. )
  806. })
  807. })
  808. })
  809. })
  810. })