ProjectInviteTests.mjs 24 KB

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