provider.box.test.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /* global browser */
  2. /*
  3. WARNING! PLEASE READ THIS BEFORE ENABLING THIS TEST ON TRAVIS.
  4. Before enabling this test on travis, please keep in mind that with this "no_ssl_bump_domains" option set
  5. here https://github.com/transloadit/uppy/blob/998c7b1805acb8d305a562dd9726ebae98575e07/.travis.yml#L33
  6. SSL encryption may not be enabled between the running companion and the testing browser client.
  7. Hence, provider tokens (Google, Instagram, Dropbox) may be at risk of getting hijacked.
  8. */
  9. // TODO: @cartfisk - box provider
  10. const { finishUploadTest, startUploadTest, uploadWithRetry } = require('./helper')
  11. const testURL = 'http://localhost:4567/providers'
  12. describe('File upload with Box Provider', () => {
  13. beforeEach(async () => {
  14. await browser.url(testURL)
  15. })
  16. // not using arrow functions as cb so to keep mocha in the 'this' context
  17. it('should upload a file completely with Box', async function () {
  18. if (!process.env.UPPY_GOOGLE_EMAIL) {
  19. console.log('skipping Box integration test')
  20. return this.skip()
  21. }
  22. // ensure session is cleared
  23. await startUploadTest(browser, 'Box', /box/)
  24. // do oauth authentication
  25. const authButton = await browser.$('button.auth-google')
  26. await authButton.waitForDisplayed()
  27. await authButton.click()
  28. await browser.pause(3000)
  29. // we login with google to avoid captcha
  30. await signIntoGoogle(browser)
  31. await browser.pause(5000)
  32. // if we box displays a warning about trusting the companion app
  33. // we allow it because we trust companion. Companion is our friend.
  34. const acceptWarning = await browser.$('#warning-button-continue')
  35. if (await acceptWarning.isExisting()) {
  36. await acceptWarning.click()
  37. }
  38. await browser.pause(3000)
  39. // finish oauth
  40. const allowAccessButton = await browser.$('button[name=allow_access]')
  41. await allowAccessButton.waitForDisplayed()
  42. await allowAccessButton.click()
  43. await finishUploadTest(browser)
  44. })
  45. // not using arrow functions as cb so to keep mocha in the 'this' context
  46. it('should resume uploads when retry is triggered with Box', async function () {
  47. if (!process.env.UPPY_GOOGLE_EMAIL) {
  48. console.log('skipping Box integration test')
  49. return this.skip()
  50. }
  51. await uploadWithRetry(browser, 'Box', testURL)
  52. })
  53. })
  54. const signIntoGoogle = async (browser) => {
  55. const emailInput = await browser.$('#identifierId')
  56. await emailInput.waitForExist(30000)
  57. await emailInput.setValue(process.env.UPPY_GOOGLE_EMAIL)
  58. let nextButton = await browser.$('#identifierNext')
  59. await nextButton.click()
  60. const passwordInput = await browser.$('input[name=password]')
  61. await passwordInput.waitForDisplayed(30000)
  62. await passwordInput.setValue(process.env.UPPY_GOOGLE_PASSWORD)
  63. nextButton = await browser.$('#passwordNext')
  64. await nextButton.click()
  65. await browser.pause(3000)
  66. const emailListItem = await browser.$(`li div[data-identifier="${process.env.UPPY_GOOGLE_EMAIL}"]`)
  67. if (await emailListItem.isExisting()) {
  68. // if user is already signed in, just select user
  69. await emailListItem.click()
  70. }
  71. const allowBoxButton = await browser.$('#submit_approve_access')
  72. if (await allowBoxButton.isExisting()) {
  73. // if box has never been allowed, allow it
  74. await allowBoxButton.click()
  75. }
  76. }