ProjectInviteTests.mjs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861
  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 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. expect(response.body.validation.body.message).to.equal(
  347. '"email" must be a string'
  348. )
  349. done()
  350. }
  351. )
  352. })
  353. })
  354. it('should fail on invalid privileges', function (done) {
  355. this.sendingUser.getCsrfToken(err => {
  356. if (err) {
  357. return done(err)
  358. }
  359. this.sendingUser.request.post(
  360. {
  361. uri: `/project/${this.projectId}/invite`,
  362. json: {
  363. email: this.email,
  364. privileges: 'invalid-privilege',
  365. },
  366. },
  367. (err, response, body) => {
  368. if (err) {
  369. return done(err)
  370. }
  371. expect(response.statusCode).to.equal(400)
  372. expect(response.body.validation.body.message).to.equal(
  373. '"privileges" must be one of [readOnly, readAndWrite, review]'
  374. )
  375. done()
  376. }
  377. )
  378. })
  379. })
  380. it('should allow the project owner to create and remove invites', function (done) {
  381. Async.series(
  382. [
  383. cb => expectProjectAccess(this.sendingUser, this.projectId, cb),
  384. cb =>
  385. expectInviteListCount(this.sendingUser, this.projectId, 0, cb),
  386. // create invite, check invite list count
  387. cb => {
  388. createInvite(
  389. this.sendingUser,
  390. this.projectId,
  391. this.email,
  392. (err, invite) => {
  393. if (err) {
  394. return cb(err)
  395. }
  396. this.invite = invite
  397. cb()
  398. }
  399. )
  400. },
  401. cb =>
  402. expectInviteListCount(this.sendingUser, this.projectId, 1, cb),
  403. cb =>
  404. revokeInvite(
  405. this.sendingUser,
  406. this.projectId,
  407. this.invite._id,
  408. cb
  409. ),
  410. cb =>
  411. expectInviteListCount(this.sendingUser, this.projectId, 0, cb),
  412. // and a second time
  413. cb => {
  414. createInvite(
  415. this.sendingUser,
  416. this.projectId,
  417. this.email,
  418. (err, invite) => {
  419. if (err) {
  420. return cb(err)
  421. }
  422. this.invite = invite
  423. cb()
  424. }
  425. )
  426. },
  427. cb =>
  428. expectInviteListCount(this.sendingUser, this.projectId, 1, cb),
  429. // check the joinProject view
  430. cb =>
  431. expectInvitesInJoinProjectCount(
  432. this.sendingUser,
  433. this.projectId,
  434. 1,
  435. cb
  436. ),
  437. // revoke invite
  438. cb =>
  439. revokeInvite(
  440. this.sendingUser,
  441. this.projectId,
  442. this.invite._id,
  443. cb
  444. ),
  445. cb =>
  446. expectInviteListCount(this.sendingUser, this.projectId, 0, cb),
  447. cb =>
  448. expectInvitesInJoinProjectCount(
  449. this.sendingUser,
  450. this.projectId,
  451. 0,
  452. cb
  453. ),
  454. ],
  455. done
  456. )
  457. })
  458. it('should allow the project owner to create many invites at once', function (done) {
  459. Async.series(
  460. [
  461. cb => expectProjectAccess(this.sendingUser, this.projectId, cb),
  462. cb =>
  463. expectInviteListCount(this.sendingUser, this.projectId, 0, cb),
  464. // create first invite
  465. cb => {
  466. createInvite(
  467. this.sendingUser,
  468. this.projectId,
  469. this.email,
  470. (err, invite) => {
  471. if (err) {
  472. return cb(err)
  473. }
  474. this.inviteOne = invite
  475. cb()
  476. }
  477. )
  478. },
  479. cb =>
  480. expectInviteListCount(this.sendingUser, this.projectId, 1, cb),
  481. // and a second
  482. cb => {
  483. createInvite(
  484. this.sendingUser,
  485. this.projectId,
  486. this.email,
  487. (err, invite) => {
  488. if (err) {
  489. return cb(err)
  490. }
  491. this.inviteTwo = invite
  492. cb()
  493. }
  494. )
  495. },
  496. // should have two
  497. cb =>
  498. expectInviteListCount(this.sendingUser, this.projectId, 2, cb),
  499. cb =>
  500. expectInvitesInJoinProjectCount(
  501. this.sendingUser,
  502. this.projectId,
  503. 2,
  504. cb
  505. ),
  506. // revoke first
  507. cb =>
  508. revokeInvite(
  509. this.sendingUser,
  510. this.projectId,
  511. this.inviteOne._id,
  512. cb
  513. ),
  514. cb =>
  515. expectInviteListCount(this.sendingUser, this.projectId, 1, cb),
  516. // revoke second
  517. cb =>
  518. revokeInvite(
  519. this.sendingUser,
  520. this.projectId,
  521. this.inviteTwo._id,
  522. cb
  523. ),
  524. cb =>
  525. expectInviteListCount(this.sendingUser, this.projectId, 0, cb),
  526. ],
  527. done
  528. )
  529. })
  530. })
  531. })
  532. describe('clicking the invite link', function () {
  533. beforeEach(function (done) {
  534. createProjectAndInvite(
  535. this.sendingUser,
  536. PROJECT_NAME,
  537. this.email,
  538. (err, project, invite, link) => {
  539. expect(err).not.to.exist
  540. this.projectId = project._id
  541. this.fakeProject = project
  542. this.invite = invite
  543. this.link = link
  544. done()
  545. }
  546. )
  547. })
  548. describe('user is logged in already', function () {
  549. beforeEach(function (done) {
  550. this.user.login(done)
  551. })
  552. describe('user is already a member of the project', function () {
  553. beforeEach(function (done) {
  554. Async.series(
  555. [
  556. cb => expectInvitePage(this.user, this.link, cb),
  557. cb =>
  558. expectAcceptInviteAndRedirect(
  559. this.user,
  560. this.invite,
  561. this.projectId,
  562. cb
  563. ),
  564. cb => expectProjectAccess(this.user, this.projectId, cb),
  565. ],
  566. done
  567. )
  568. })
  569. describe('when user clicks on the invite a second time', function () {
  570. it('should just redirect to the project page', function (done) {
  571. Async.series(
  572. [
  573. cb => expectProjectAccess(this.user, this.projectId, cb),
  574. cb =>
  575. expectInviteRedirectToProject(
  576. this.user,
  577. this.link,
  578. this.projectId,
  579. cb
  580. ),
  581. cb => expectProjectAccess(this.user, this.projectId, cb),
  582. ],
  583. done
  584. )
  585. })
  586. describe('when the user recieves another invite to the same project', function () {
  587. it('should redirect to the project page', function (done) {
  588. Async.series(
  589. [
  590. cb => {
  591. createInvite(
  592. this.sendingUser,
  593. this.projectId,
  594. this.email,
  595. (err, invite) => {
  596. if (err) {
  597. throw err
  598. }
  599. this.secondInvite = invite
  600. const token = generateTokenSpy.getCall(1).returnValue
  601. this.secondLink =
  602. CollaboratorsEmailHandler._buildInviteUrl(
  603. this.fakeProject,
  604. { ...invite, token }
  605. )
  606. cb()
  607. }
  608. )
  609. },
  610. cb =>
  611. expectInviteRedirectToProject(
  612. this.user,
  613. this.secondLink,
  614. this.projectId,
  615. cb
  616. ),
  617. cb => expectProjectAccess(this.user, this.projectId, cb),
  618. cb =>
  619. revokeInvite(
  620. this.sendingUser,
  621. this.projectId,
  622. this.secondInvite._id,
  623. cb
  624. ),
  625. ],
  626. done
  627. )
  628. })
  629. })
  630. })
  631. })
  632. describe('user is not a member of the project', function () {
  633. it('should not grant access if the user does not accept the invite', function (done) {
  634. Async.series(
  635. [
  636. cb => expectInvitePage(this.user, this.link, cb),
  637. cb => expectNoProjectAccess(this.user, this.projectId, cb),
  638. ],
  639. done
  640. )
  641. })
  642. it('should render the invalid-invite page if the token is invalid', function (done) {
  643. Async.series(
  644. [
  645. cb => {
  646. const link = this.link.replace(
  647. this.invite.token,
  648. 'not_a_real_token'
  649. )
  650. expectInvalidInvitePage(this.user, link, cb)
  651. },
  652. cb => expectNoProjectAccess(this.user, this.projectId, cb),
  653. cb => expectNoProjectAccess(this.user, this.projectId, cb),
  654. ],
  655. done
  656. )
  657. })
  658. it('should allow the user to accept the invite and access the project', function (done) {
  659. Async.series(
  660. [
  661. cb => expectInvitePage(this.user, this.link, cb),
  662. cb =>
  663. expectAcceptInviteAndRedirect(
  664. this.user,
  665. this.invite,
  666. this.projectId,
  667. cb
  668. ),
  669. cb => expectProjectAccess(this.user, this.projectId, cb),
  670. ],
  671. done
  672. )
  673. })
  674. })
  675. })
  676. describe('user is not logged in initially', function () {
  677. describe('registration prompt workflow with valid token', function () {
  678. before(function () {
  679. if (!Features.hasFeature('registration')) {
  680. this.skip()
  681. }
  682. })
  683. it('should redirect to the register page', function (done) {
  684. expectInviteRedirectToRegister(this.user, this.link, done)
  685. })
  686. it('should allow user to accept the invite if the user registers a new account', function (done) {
  687. Async.series(
  688. [
  689. cb => expectInviteRedirectToRegister(this.user, this.link, cb),
  690. cb =>
  691. expectRegistrationRedirectToInvite(this.user, this.link, cb),
  692. cb => expectInvitePage(this.user, this.link, cb),
  693. cb =>
  694. expectAcceptInviteAndRedirect(
  695. this.user,
  696. this.invite,
  697. this.projectId,
  698. cb
  699. ),
  700. cb => expectProjectAccess(this.user, this.projectId, cb),
  701. ],
  702. done
  703. )
  704. })
  705. })
  706. describe('registration prompt workflow with non-valid token', function () {
  707. before(function () {
  708. if (!Features.hasFeature('registration')) {
  709. this.skip()
  710. }
  711. })
  712. it('should redirect to the register page', function (done) {
  713. Async.series(
  714. [
  715. cb => expectInviteRedirectToRegister(this.user, this.link, cb),
  716. cb => expectNoProjectAccess(this.user, this.projectId, cb),
  717. ],
  718. done
  719. )
  720. })
  721. it('should display invalid-invite right away', function (done) {
  722. const badLink = this.link.replace(
  723. this.invite.token,
  724. 'not_a_real_token'
  725. )
  726. Async.series(
  727. [
  728. cb => expectInvalidInvitePage(this.user, badLink, cb),
  729. cb => expectNoProjectAccess(this.user, this.projectId, cb),
  730. ],
  731. done
  732. )
  733. })
  734. })
  735. describe('login workflow with valid token', function () {
  736. beforeEach(function (done) {
  737. this.user.ensureUserExists(done)
  738. })
  739. it('should redirect to the register page', function (done) {
  740. Async.series(
  741. [
  742. cb => expectInviteRedirectToRegister(this.user, this.link, cb),
  743. cb => expectNoProjectAccess(this.user, this.projectId, cb),
  744. ],
  745. done
  746. )
  747. })
  748. it('should allow the user to login to view the invite', function (done) {
  749. Async.series(
  750. [
  751. cb => expectInviteRedirectToRegister(this.user, this.link, cb),
  752. cb => expectLoginPage(this.user, cb),
  753. cb => expectLoginRedirectToInvite(this.user, this.link, cb),
  754. cb => expectInvitePage(this.user, this.link, cb),
  755. cb => expectNoProjectAccess(this.user, this.projectId, cb),
  756. ],
  757. done
  758. )
  759. })
  760. it('should allow user to accept the invite if the user logs in', function (done) {
  761. Async.series(
  762. [
  763. cb => expectInviteRedirectToRegister(this.user, this.link, cb),
  764. cb => expectLoginPage(this.user, cb),
  765. cb => expectLoginRedirectToInvite(this.user, this.link, cb),
  766. cb => expectInvitePage(this.user, this.link, cb),
  767. cb =>
  768. expectAcceptInviteAndRedirect(
  769. this.user,
  770. this.invite,
  771. this.projectId,
  772. cb
  773. ),
  774. cb => expectProjectAccess(this.user, this.projectId, cb),
  775. ],
  776. done
  777. )
  778. })
  779. })
  780. describe('login workflow with non-valid token', function () {
  781. it('should redirect to the register page', function (done) {
  782. Async.series(
  783. [
  784. cb => expectInviteRedirectToRegister(this.user, this.link, cb),
  785. cb => expectNoProjectAccess(this.user, this.projectId, cb),
  786. ],
  787. done
  788. )
  789. })
  790. it('should show the invalid-invite page right away', function (done) {
  791. const badLink = this.link.replace(
  792. this.invite.token,
  793. 'not_a_real_token'
  794. )
  795. Async.series(
  796. [
  797. cb => expectInvalidInvitePage(this.user, badLink, cb),
  798. cb => expectNoProjectAccess(this.user, this.projectId, cb),
  799. ],
  800. done
  801. )
  802. })
  803. })
  804. })
  805. })
  806. })