ProjectInviteTests.mjs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867
  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(
  223. /<title[^>]*>(Login|Log in to Overleaf) - .*<\/title>/
  224. )
  225. callback()
  226. })
  227. }
  228. const expectLoginRedirectToInvite = (user, link, callback) => {
  229. tryLoginUser(user, (err, response) => {
  230. expect(err).not.to.exist
  231. expect(response.statusCode).to.equal(200)
  232. callback()
  233. })
  234. }
  235. const expectRegistrationRedirectToInvite = (user, link, callback) => {
  236. user.register((err, _user, response) => {
  237. expect(err).not.to.exist
  238. expect(response.statusCode).to.equal(200)
  239. if (response.body.redir === '/registration/try-premium') {
  240. user.request.get('/registration/onboarding', (err, response) => {
  241. if (err) return callback(err)
  242. expect(response.statusCode).to.equal(200)
  243. const dom = cheerio.load(response.body)
  244. const skipUrl = dom('meta[name="ol-skipUrl"]')[0].attribs.content
  245. expect(new URL(skipUrl, settings.siteUrl).href).to.equal(
  246. new URL(link, settings.siteUrl).href
  247. )
  248. callback()
  249. })
  250. } else {
  251. expect(response.body.redir).to.equal(link)
  252. callback()
  253. }
  254. })
  255. }
  256. const expectInviteRedirectToProject = (user, link, projectId, callback) => {
  257. // view invite, redirect straight to project
  258. tryFollowInviteLink(user, link, (err, response) => {
  259. expect(err).not.to.exist
  260. expect(response.statusCode).to.equal(302)
  261. expect(response.headers.location).to.equal(`/project/${projectId}`)
  262. callback()
  263. })
  264. }
  265. const expectAcceptInviteAndRedirect = (user, invite, projectId, callback) => {
  266. // should accept the invite and redirect to project
  267. tryAcceptInvite(user, invite, projectId, (err, response) => {
  268. expect(err).not.to.exist
  269. expect(response.statusCode).to.equal(302)
  270. expect(response.headers.location).to.equal(`/project/${projectId}`)
  271. callback()
  272. })
  273. }
  274. const expectInviteListCount = (user, projectId, count, callback) => {
  275. tryGetInviteList(user, projectId, (err, response, body) => {
  276. expect(err).not.to.exist
  277. expect(response.statusCode).to.equal(200)
  278. expect(body).to.have.all.keys(['invites'])
  279. expect(body.invites.length).to.equal(count)
  280. callback()
  281. })
  282. }
  283. const expectInvitesInJoinProjectCount = (user, projectId, count, callback) => {
  284. tryJoinProject(user, projectId, (err, response, body) => {
  285. expect(err).not.to.exist
  286. expect(response.statusCode).to.equal(200)
  287. expect(body.project).to.contain.keys(['invites'])
  288. expect(body.project.invites.length).to.equal(count)
  289. callback()
  290. })
  291. }
  292. const PROJECT_NAME = 'project name for sharing test'
  293. const OWNER_NAME = 'sending user name'
  294. describe('ProjectInviteTests', function () {
  295. beforeEach(function (done) {
  296. this.sendingUser = new User()
  297. this.user = new User()
  298. this.site_admin = new User({ email: `admin+${Math.random()}@example.com` })
  299. this.email = `smoketestuser+${Math.random()}@example.com`
  300. generateTokenSpy = sinon.spy(CollaboratorsInviteHelper, 'generateToken')
  301. Async.series(
  302. [
  303. cb => this.sendingUser.ensureUserExists(cb),
  304. cb => this.sendingUser.upgradeFeatures({ collaborators: 10 }, cb),
  305. cb => this.sendingUser.login(cb),
  306. cb =>
  307. this.sendingUser.mongoUpdate(
  308. {
  309. $set: { first_name: OWNER_NAME },
  310. },
  311. cb
  312. ),
  313. ],
  314. done
  315. )
  316. })
  317. afterEach(function () {
  318. generateTokenSpy.restore()
  319. })
  320. describe('creating invites', function () {
  321. describe('creating two invites', function () {
  322. beforeEach(function (done) {
  323. createProject(
  324. this.sendingUser,
  325. PROJECT_NAME,
  326. (err, projectId, project) => {
  327. expect(err).not.to.exist
  328. this.projectId = projectId
  329. this.fakeProject = project
  330. done()
  331. }
  332. )
  333. })
  334. it('should fail if email is not a string', function (done) {
  335. this.sendingUser.getCsrfToken(err => {
  336. if (err) {
  337. return done(err)
  338. }
  339. this.sendingUser.request.post(
  340. {
  341. uri: `/project/${this.projectId}/invite`,
  342. json: {
  343. email: {},
  344. privileges: 'readAndWrite',
  345. },
  346. },
  347. (err, response, body) => {
  348. if (err) {
  349. return done(err)
  350. }
  351. expect(response.statusCode).to.equal(400)
  352. expect(response.body.validation.body.message).to.equal(
  353. '"email" must be a string'
  354. )
  355. done()
  356. }
  357. )
  358. })
  359. })
  360. it('should fail on invalid privileges', function (done) {
  361. this.sendingUser.getCsrfToken(err => {
  362. if (err) {
  363. return done(err)
  364. }
  365. this.sendingUser.request.post(
  366. {
  367. uri: `/project/${this.projectId}/invite`,
  368. json: {
  369. email: this.email,
  370. privileges: 'invalid-privilege',
  371. },
  372. },
  373. (err, response, body) => {
  374. if (err) {
  375. return done(err)
  376. }
  377. expect(response.statusCode).to.equal(400)
  378. expect(response.body.validation.body.message).to.equal(
  379. '"privileges" must be one of [readOnly, readAndWrite, review]'
  380. )
  381. done()
  382. }
  383. )
  384. })
  385. })
  386. it('should allow the project owner to create and remove invites', function (done) {
  387. Async.series(
  388. [
  389. cb => expectProjectAccess(this.sendingUser, this.projectId, cb),
  390. cb =>
  391. expectInviteListCount(this.sendingUser, this.projectId, 0, cb),
  392. // create invite, check invite list count
  393. cb => {
  394. createInvite(
  395. this.sendingUser,
  396. this.projectId,
  397. this.email,
  398. (err, invite) => {
  399. if (err) {
  400. return cb(err)
  401. }
  402. this.invite = invite
  403. cb()
  404. }
  405. )
  406. },
  407. cb =>
  408. expectInviteListCount(this.sendingUser, this.projectId, 1, cb),
  409. cb =>
  410. revokeInvite(
  411. this.sendingUser,
  412. this.projectId,
  413. this.invite._id,
  414. cb
  415. ),
  416. cb =>
  417. expectInviteListCount(this.sendingUser, this.projectId, 0, cb),
  418. // and a second time
  419. cb => {
  420. createInvite(
  421. this.sendingUser,
  422. this.projectId,
  423. this.email,
  424. (err, invite) => {
  425. if (err) {
  426. return cb(err)
  427. }
  428. this.invite = invite
  429. cb()
  430. }
  431. )
  432. },
  433. cb =>
  434. expectInviteListCount(this.sendingUser, this.projectId, 1, cb),
  435. // check the joinProject view
  436. cb =>
  437. expectInvitesInJoinProjectCount(
  438. this.sendingUser,
  439. this.projectId,
  440. 1,
  441. cb
  442. ),
  443. // revoke invite
  444. cb =>
  445. revokeInvite(
  446. this.sendingUser,
  447. this.projectId,
  448. this.invite._id,
  449. cb
  450. ),
  451. cb =>
  452. expectInviteListCount(this.sendingUser, this.projectId, 0, cb),
  453. cb =>
  454. expectInvitesInJoinProjectCount(
  455. this.sendingUser,
  456. this.projectId,
  457. 0,
  458. cb
  459. ),
  460. ],
  461. done
  462. )
  463. })
  464. it('should allow the project owner to create many invites at once', function (done) {
  465. Async.series(
  466. [
  467. cb => expectProjectAccess(this.sendingUser, this.projectId, cb),
  468. cb =>
  469. expectInviteListCount(this.sendingUser, this.projectId, 0, cb),
  470. // create first invite
  471. cb => {
  472. createInvite(
  473. this.sendingUser,
  474. this.projectId,
  475. this.email,
  476. (err, invite) => {
  477. if (err) {
  478. return cb(err)
  479. }
  480. this.inviteOne = invite
  481. cb()
  482. }
  483. )
  484. },
  485. cb =>
  486. expectInviteListCount(this.sendingUser, this.projectId, 1, cb),
  487. // and a second
  488. cb => {
  489. createInvite(
  490. this.sendingUser,
  491. this.projectId,
  492. this.email,
  493. (err, invite) => {
  494. if (err) {
  495. return cb(err)
  496. }
  497. this.inviteTwo = invite
  498. cb()
  499. }
  500. )
  501. },
  502. // should have two
  503. cb =>
  504. expectInviteListCount(this.sendingUser, this.projectId, 2, cb),
  505. cb =>
  506. expectInvitesInJoinProjectCount(
  507. this.sendingUser,
  508. this.projectId,
  509. 2,
  510. cb
  511. ),
  512. // revoke first
  513. cb =>
  514. revokeInvite(
  515. this.sendingUser,
  516. this.projectId,
  517. this.inviteOne._id,
  518. cb
  519. ),
  520. cb =>
  521. expectInviteListCount(this.sendingUser, this.projectId, 1, cb),
  522. // revoke second
  523. cb =>
  524. revokeInvite(
  525. this.sendingUser,
  526. this.projectId,
  527. this.inviteTwo._id,
  528. cb
  529. ),
  530. cb =>
  531. expectInviteListCount(this.sendingUser, this.projectId, 0, cb),
  532. ],
  533. done
  534. )
  535. })
  536. })
  537. })
  538. describe('clicking the invite link', function () {
  539. beforeEach(function (done) {
  540. createProjectAndInvite(
  541. this.sendingUser,
  542. PROJECT_NAME,
  543. this.email,
  544. (err, project, invite, link) => {
  545. expect(err).not.to.exist
  546. this.projectId = project._id
  547. this.fakeProject = project
  548. this.invite = invite
  549. this.link = link
  550. done()
  551. }
  552. )
  553. })
  554. describe('user is logged in already', function () {
  555. beforeEach(function (done) {
  556. this.user.login(done)
  557. })
  558. describe('user is already a member of the project', function () {
  559. beforeEach(function (done) {
  560. Async.series(
  561. [
  562. cb => expectInvitePage(this.user, this.link, cb),
  563. cb =>
  564. expectAcceptInviteAndRedirect(
  565. this.user,
  566. this.invite,
  567. this.projectId,
  568. cb
  569. ),
  570. cb => expectProjectAccess(this.user, this.projectId, cb),
  571. ],
  572. done
  573. )
  574. })
  575. describe('when user clicks on the invite a second time', function () {
  576. it('should just redirect to the project page', function (done) {
  577. Async.series(
  578. [
  579. cb => expectProjectAccess(this.user, this.projectId, cb),
  580. cb =>
  581. expectInviteRedirectToProject(
  582. this.user,
  583. this.link,
  584. this.projectId,
  585. cb
  586. ),
  587. cb => expectProjectAccess(this.user, this.projectId, cb),
  588. ],
  589. done
  590. )
  591. })
  592. describe('when the user recieves another invite to the same project', function () {
  593. it('should redirect to the project page', function (done) {
  594. Async.series(
  595. [
  596. cb => {
  597. createInvite(
  598. this.sendingUser,
  599. this.projectId,
  600. this.email,
  601. (err, invite) => {
  602. if (err) {
  603. throw err
  604. }
  605. this.secondInvite = invite
  606. const token = generateTokenSpy.getCall(1).returnValue
  607. this.secondLink =
  608. CollaboratorsEmailHandler._buildInviteUrl(
  609. this.fakeProject,
  610. { ...invite, token }
  611. )
  612. cb()
  613. }
  614. )
  615. },
  616. cb =>
  617. expectInviteRedirectToProject(
  618. this.user,
  619. this.secondLink,
  620. this.projectId,
  621. cb
  622. ),
  623. cb => expectProjectAccess(this.user, this.projectId, cb),
  624. cb =>
  625. revokeInvite(
  626. this.sendingUser,
  627. this.projectId,
  628. this.secondInvite._id,
  629. cb
  630. ),
  631. ],
  632. done
  633. )
  634. })
  635. })
  636. })
  637. })
  638. describe('user is not a member of the project', function () {
  639. it('should not grant access if the user does not accept the invite', function (done) {
  640. Async.series(
  641. [
  642. cb => expectInvitePage(this.user, this.link, cb),
  643. cb => expectNoProjectAccess(this.user, this.projectId, cb),
  644. ],
  645. done
  646. )
  647. })
  648. it('should render the invalid-invite page if the token is invalid', function (done) {
  649. Async.series(
  650. [
  651. cb => {
  652. const link = this.link.replace(
  653. this.invite.token,
  654. 'not_a_real_token'
  655. )
  656. expectInvalidInvitePage(this.user, link, cb)
  657. },
  658. cb => expectNoProjectAccess(this.user, this.projectId, cb),
  659. cb => expectNoProjectAccess(this.user, this.projectId, cb),
  660. ],
  661. done
  662. )
  663. })
  664. it('should allow the user to accept the invite and access the project', function (done) {
  665. Async.series(
  666. [
  667. cb => expectInvitePage(this.user, this.link, cb),
  668. cb =>
  669. expectAcceptInviteAndRedirect(
  670. this.user,
  671. this.invite,
  672. this.projectId,
  673. cb
  674. ),
  675. cb => expectProjectAccess(this.user, this.projectId, cb),
  676. ],
  677. done
  678. )
  679. })
  680. })
  681. })
  682. describe('user is not logged in initially', function () {
  683. describe('registration prompt workflow with valid token', function () {
  684. before(function () {
  685. if (!Features.hasFeature('registration')) {
  686. this.skip()
  687. }
  688. })
  689. it('should redirect to the register page', function (done) {
  690. expectInviteRedirectToRegister(this.user, this.link, done)
  691. })
  692. it('should allow user to accept the invite if the user registers a new account', function (done) {
  693. Async.series(
  694. [
  695. cb => expectInviteRedirectToRegister(this.user, this.link, cb),
  696. cb =>
  697. expectRegistrationRedirectToInvite(this.user, this.link, cb),
  698. cb => expectInvitePage(this.user, this.link, cb),
  699. cb =>
  700. expectAcceptInviteAndRedirect(
  701. this.user,
  702. this.invite,
  703. this.projectId,
  704. cb
  705. ),
  706. cb => expectProjectAccess(this.user, this.projectId, cb),
  707. ],
  708. done
  709. )
  710. })
  711. })
  712. describe('registration prompt workflow with non-valid token', function () {
  713. before(function () {
  714. if (!Features.hasFeature('registration')) {
  715. this.skip()
  716. }
  717. })
  718. it('should redirect to the register page', function (done) {
  719. Async.series(
  720. [
  721. cb => expectInviteRedirectToRegister(this.user, this.link, cb),
  722. cb => expectNoProjectAccess(this.user, this.projectId, cb),
  723. ],
  724. done
  725. )
  726. })
  727. it('should display invalid-invite right away', function (done) {
  728. const badLink = this.link.replace(
  729. this.invite.token,
  730. 'not_a_real_token'
  731. )
  732. Async.series(
  733. [
  734. cb => expectInvalidInvitePage(this.user, badLink, cb),
  735. cb => expectNoProjectAccess(this.user, this.projectId, cb),
  736. ],
  737. done
  738. )
  739. })
  740. })
  741. describe('login workflow with valid token', function () {
  742. beforeEach(function (done) {
  743. this.user.ensureUserExists(done)
  744. })
  745. it('should redirect to the register page', function (done) {
  746. Async.series(
  747. [
  748. cb => expectInviteRedirectToRegister(this.user, this.link, cb),
  749. cb => expectNoProjectAccess(this.user, this.projectId, cb),
  750. ],
  751. done
  752. )
  753. })
  754. it('should allow the user to login to view the invite', 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 => expectNoProjectAccess(this.user, this.projectId, cb),
  762. ],
  763. done
  764. )
  765. })
  766. it('should allow user to accept the invite if the user logs in', function (done) {
  767. Async.series(
  768. [
  769. cb => expectInviteRedirectToRegister(this.user, this.link, cb),
  770. cb => expectLoginPage(this.user, cb),
  771. cb => expectLoginRedirectToInvite(this.user, this.link, cb),
  772. cb => expectInvitePage(this.user, this.link, cb),
  773. cb =>
  774. expectAcceptInviteAndRedirect(
  775. this.user,
  776. this.invite,
  777. this.projectId,
  778. cb
  779. ),
  780. cb => expectProjectAccess(this.user, this.projectId, cb),
  781. ],
  782. done
  783. )
  784. })
  785. })
  786. describe('login workflow with non-valid token', function () {
  787. it('should redirect to the register page', function (done) {
  788. Async.series(
  789. [
  790. cb => expectInviteRedirectToRegister(this.user, this.link, cb),
  791. cb => expectNoProjectAccess(this.user, this.projectId, cb),
  792. ],
  793. done
  794. )
  795. })
  796. it('should show the invalid-invite page right away', function (done) {
  797. const badLink = this.link.replace(
  798. this.invite.token,
  799. 'not_a_real_token'
  800. )
  801. Async.series(
  802. [
  803. cb => expectInvalidInvitePage(this.user, badLink, cb),
  804. cb => expectNoProjectAccess(this.user, this.projectId, cb),
  805. ],
  806. done
  807. )
  808. })
  809. })
  810. })
  811. })
  812. })