provider.dropbox.test.js 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. const { finishUploadTest, startUploadTest } = require('./helper')
  10. const testURL = 'http://localhost:4567/providers'
  11. describe('File upload with Dropbox Provider', () => {
  12. beforeEach(async () => {
  13. await browser.url(testURL)
  14. })
  15. // not using arrow functions as cb so to keep mocha in the 'this' context
  16. it('should upload a file completely with Dropbox', async function () {
  17. if (!process.env.UPPY_GOOGLE_EMAIL) {
  18. console.log('skipping Dropbox integration test')
  19. return this.skip()
  20. }
  21. // ensure session is cleared
  22. await startUploadTest(browser, 'Dropbox', /dropbox/)
  23. // do oauth authentication
  24. const authButton = await browser.$('button.auth-google')
  25. await authButton.waitForDisplayed()
  26. await authButton.click()
  27. await browser.pause(3000)
  28. // we login with google to avoid captcha
  29. await signIntoGoogle(browser)
  30. await browser.pause(5000)
  31. // if we dropbox displays a warning about trusting the companion app
  32. // we allow it because we trust companion. Companion is our friend.
  33. const acceptWarning = await browser.$('#warning-button-continue')
  34. if (await acceptWarning.isExisting()) {
  35. await acceptWarning.click()
  36. }
  37. await browser.pause(3000)
  38. // finish oauth
  39. const allowAccessButton = await browser.$('button[name=allow_access]')
  40. await allowAccessButton.waitForDisplayed()
  41. await allowAccessButton.click()
  42. await finishUploadTest(browser)
  43. })
  44. })
  45. const signIntoGoogle = async (browser) => {
  46. const emailInput = await browser.$('#identifierId')
  47. await emailInput.waitForExist(30000)
  48. await emailInput.setValue(process.env.UPPY_GOOGLE_EMAIL)
  49. let nextButton = await browser.$('#identifierNext')
  50. await nextButton.click()
  51. const passwordInput = await browser.$('input[name=password]')
  52. await passwordInput.waitForDisplayed(30000)
  53. await passwordInput.setValue(process.env.UPPY_GOOGLE_PASSWORD)
  54. nextButton = await browser.$('#passwordNext')
  55. await nextButton.click()
  56. await browser.pause(3000)
  57. const emailListItem = await browser.$(`li div[data-identifier="${process.env.UPPY_GOOGLE_EMAIL}"]`)
  58. if (await emailListItem.isExisting()) {
  59. // if user is already signed in, just select user
  60. await emailListItem.click()
  61. }
  62. const allowDropboxButton = await browser.$('#submit_approve_access')
  63. if (await allowDropboxButton.isExisting()) {
  64. // if dropbox has never been allowed, allow it
  65. await allowDropboxButton.click()
  66. }
  67. }