disabled.test.js 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 testURL = 'http://localhost:4567/providers'
  10. describe('File upload with Providers', () => {
  11. beforeEach(() => {
  12. // close other tabs that might be left from failed tests
  13. while (browser.getTabIds().length > 1) {
  14. browser.switchTab(browser.getTabIds()[1])
  15. browser.close()
  16. }
  17. browser.url(testURL)
  18. })
  19. // not using arrow functions as cb so to keep mocha in the 'this' context
  20. it('should upload a file completely with Google Drive', function () {
  21. if (process.env.UPPY_GOOGLE_EMAIL == undefined) {
  22. console.log('skipping Google Drive integration test')
  23. return this.skip()
  24. }
  25. // ensure session is cleared
  26. startUploadTest(browser, 'GoogleDrive')
  27. signIntoGoogle(browser)
  28. finishUploadTest(browser)
  29. })
  30. // not using arrow functions as cb so to keep mocha in the 'this' context
  31. it('should upload a file completely with Instagram', function () {
  32. const isFirefox = browser.desiredCapabilities.browserName === 'firefox'
  33. if (process.env.UPPY_INSTAGRAM_USERNAME == undefined || !isFirefox) {
  34. console.log('skipping Instagram integration test')
  35. return this.skip()
  36. }
  37. // ensure session is cleared
  38. startUploadTest(browser, 'Instagram')
  39. // do oauth authentication
  40. browser.waitForExist('input[name=username]', 20000)
  41. browser.setValue('input[name=username]', process.env.UPPY_INSTAGRAM_USERNAME)
  42. browser.setValue('input[name=password]', process.env.UPPY_INSTAGRAM_PASSWORD)
  43. browser.click('form button[type=submit]')
  44. if (browser.getTabIds().length > 1) {
  45. // wait a bit for submission
  46. browser.pause(3000)
  47. // if suspicious login was detected, the window will remain unclosed
  48. // so we have to input the security code sent
  49. if (browser.isExisting('input[name="choice"]')) {
  50. browser.click('form button')
  51. browser.waitForExist('input[name=security_code]')
  52. // we can't automate the submission of security code
  53. // because it is sent to the email. So we wait till it is filled manually
  54. browser.waitUntil(
  55. () => browser('input[name=security_code]').getValue(),
  56. 30000, 'expected security code to be manually entered')
  57. }
  58. // instagram may ask for auth confirmation to allow companion
  59. if (browser.isExisting('button[value="Authorize"]')) {
  60. browser.click('button[value="Authorize"]')
  61. }
  62. }
  63. finishUploadTest(browser)
  64. })
  65. // not using arrow functions as cb so to keep mocha in the 'this' context
  66. it('should upload a file completely with Dropbox', function () {
  67. if (process.env.UPPY_GOOGLE_EMAIL === undefined) {
  68. console.log('skipping Dropbox integration test')
  69. return this.skip()
  70. }
  71. // ensure session is cleared
  72. startUploadTest(browser, 'Dropbox')
  73. // do oauth authentication
  74. browser.waitForVisible('button.auth-google')
  75. browser.click('button.auth-google')
  76. browser.pause(3000)
  77. // we login with google to avoid captcha
  78. signIntoGoogle(browser)
  79. browser.pause(5000)
  80. // if we dropbox displays a warning about trusting the companion app
  81. // we allow it because we trust companion. Companion is our friend.
  82. if (browser.isExisting('#warning-button-continue')) {
  83. browser.click('#warning-button-continue')
  84. }
  85. browser.pause(3000)
  86. // finish oauth
  87. browser.waitForVisible('button[name=allow_access]')
  88. browser.click('button[name=allow_access]')
  89. finishUploadTest(browser)
  90. })
  91. })
  92. const startUploadTest = (browser, providerName) => {
  93. browser.click(`.uppy-DashboardTab-btn[aria-controls=uppy-DashboardContent-panel--${providerName}]`)
  94. browser.waitForVisible('.uppy-Provider-authBtn', 3000)
  95. browser.click('.uppy-Provider-authBtn')
  96. // move control to instagram auth tab
  97. browser.switchTab(browser.getTabIds()[1])
  98. }
  99. const finishUploadTest = (browser) => {
  100. // switch back to uppy tab
  101. browser.switchTab(browser.getTabIds()[0])
  102. browser.waitForVisible('.uppy-ProviderBrowser-list li.uppy-ProviderBrowserItem')
  103. browser.click('.uppy-ProviderBrowser-list li.uppy-ProviderBrowserItem:last-child button')
  104. browser.waitForVisible('.uppy-ProviderBrowser-footer .uppy-u-reset.uppy-c-btn.uppy-c-btn-primary')
  105. browser.click('.uppy-ProviderBrowser-footer .uppy-u-reset.uppy-c-btn.uppy-c-btn-primary')
  106. browser.waitForVisible('.uppy-StatusBar-content[title="Complete"]', 20000)
  107. }
  108. const signIntoGoogle = (browser) => {
  109. if (browser.isExisting(`li div[data-identifier="${process.env.UPPY_GOOGLE_EMAIL}"]`)) {
  110. // if user is already signed in, just select user
  111. browser.click(`li div[data-identifier="${process.env.UPPY_GOOGLE_EMAIL}"]`)
  112. return
  113. }
  114. browser.waitForExist('#identifierId')
  115. browser.setValue('#identifierId', process.env.UPPY_GOOGLE_EMAIL)
  116. browser.click('#identifierNext')
  117. browser.waitForVisible('input[name=password]')
  118. browser.setValue('input[name=password]', process.env.UPPY_GOOGLE_PASSWORD)
  119. browser.click('#passwordNext')
  120. // if suspicious login was detected, the window will remain unclosed
  121. // so we have to confirm the recovery email or phone no
  122. if (browser.getTabIds().length > 1) {
  123. // confirm recovery email option
  124. if (browser.isExisting('li div[data-challengetype="12"]')) {
  125. browser.click('li div[data-challengetype="12"]')
  126. browser.waitForVisible('input[name=knowledgePreregisteredEmailResponse]')
  127. browser.setValue('input[name=knowledgePreregisteredEmailResponse]', process.env.UPPY_GOOGLE_RECOVERY_EMAIL)
  128. browser.click('#next[role=button]')
  129. // confirm recovery phone number
  130. } else if (browser.isExisting('#countryList')) {
  131. browser.click('div#countryList')
  132. browser.click('div[data-value=nl]')
  133. browser.setValue('input#phoneNumberId', process.env.UPPY_GOOGLE_PHONE_NO)
  134. browser.click('#next[role=button]')
  135. }
  136. }
  137. }