header_contacts-menu.cy.ts 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /**
  2. * @copyright Copyright (c) 2023 Ferdinand Thiessen <opensource@fthiessen.de>
  3. *
  4. * @author Ferdinand Thiessen <opensource@fthiessen.de>
  5. *
  6. * @license AGPL-3.0-or-later
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License as
  10. * published by the Free Software Foundation, either version 3 of the
  11. * License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. import { User } from '@nextcloud/cypress'
  23. import { clearState, getNextcloudHeader } from '../../support/commonUtils'
  24. // eslint-disable-next-line n/no-extraneous-import
  25. import randomString from 'crypto-random-string'
  26. const admin = new User('admin', 'admin')
  27. const getContactsMenu = () => getNextcloudHeader().find('#header-menu-contactsmenu')
  28. const getContactsMenuToggle = () => getNextcloudHeader().find('#contactsmenu .header-menu__trigger')
  29. const getContactsSearch = () => getContactsMenu().find('#contactsmenu__menu__search')
  30. describe('Header: Contacts menu', { testIsolation: true }, () => {
  31. let user: User
  32. beforeEach(() => {
  33. // clear user and group state
  34. clearState()
  35. // ensure the contacts menu is not restricted
  36. cy.runOccCommand('config:app:set --value no core shareapi_restrict_user_enumeration_to_group')
  37. // create a new user for testing the contacts
  38. cy.createRandomUser().then(($user) => {
  39. user = $user
  40. })
  41. // Given I am logged in as the admin
  42. cy.login(admin)
  43. cy.visit('/')
  44. })
  45. it('Other users are seen in the contacts menu', () => {
  46. // When I open the Contacts menu
  47. getContactsMenuToggle().click()
  48. // I see that the Contacts menu is shown
  49. getContactsMenu().should('exist')
  50. // I see that the contact user in the Contacts menu is shown
  51. getContactsMenu().contains('li.contact', user.userId).should('be.visible')
  52. // I see that the contact "admin" in the Contacts menu is not shown
  53. getContactsMenu().contains('li.contact', admin.userId).should('not.exist')
  54. })
  55. it('Just added users are seen in the contacts menu', () => {
  56. // I create a new user
  57. const newUserName = randomString(7)
  58. // we can not use createRandomUser as it will invalidate the session
  59. cy.runOccCommand(`user:add --password-from-env '${newUserName}'`, { env: { OC_PASS: '1234567' } })
  60. // I open the Contacts menu
  61. getContactsMenuToggle().click()
  62. // I see that the Contacts menu is shown
  63. getContactsMenu().should('exist')
  64. // I see that the contact user in the Contacts menu is shown
  65. getContactsMenu().contains('li.contact', user.userId).should('be.visible')
  66. // I see that the contact of the new user in the Contacts menu is shown
  67. getContactsMenu().contains('li.contact', newUserName).should('be.visible')
  68. // I see that the contact "admin" in the Contacts menu is not shown
  69. getContactsMenu().contains('li.contact', admin.userId).should('not.exist')
  70. })
  71. it('Search for other users in the contacts menu', () => {
  72. cy.createRandomUser().then((otherUser) => {
  73. // Given I am logged in as the admin
  74. cy.login(admin)
  75. cy.visit('/')
  76. // I open the Contacts menu
  77. getContactsMenuToggle().click()
  78. // I see that the Contacts menu is shown
  79. getContactsMenu().should('exist')
  80. // I see that the contact user in the Contacts menu is shown
  81. getContactsMenu().contains('li.contact', user.userId).should('be.visible')
  82. // I see that the contact of the new user in the Contacts menu is shown
  83. getContactsMenu().contains('li.contact', otherUser.userId).should('be.visible')
  84. // I see that the Contacts menu search input is shown
  85. getContactsSearch().should('exist')
  86. // I search for the otherUser
  87. getContactsSearch().type(otherUser.userId)
  88. // I see that the contact otherUser in the Contacts menu is shown
  89. getContactsMenu().contains('li.contact', otherUser.userId).should('be.visible')
  90. // I see that the contact user in the Contacts menu is not shown
  91. getContactsMenu().contains('li.contact', user.userId).should('not.exist')
  92. // I see that the contact "admin" in the Contacts menu is not shown
  93. getContactsMenu().contains('li.contact', admin.userId).should('not.exist')
  94. })
  95. })
  96. it('Search for unknown users in the contacts menu', () => {
  97. // I open the Contacts menu
  98. getContactsMenuToggle().click()
  99. // I see that the Contacts menu is shown
  100. getContactsMenu().should('exist')
  101. // I see that the contact user in the Contacts menu is shown
  102. getContactsMenu().contains('li.contact', user.userId).should('be.visible')
  103. // I see that the Contacts menu search input is shown
  104. getContactsSearch().should('exist')
  105. // I search for an unknown user
  106. getContactsSearch().type('surely-unknown-user')
  107. // I see that the no results message in the Contacts menu is shown
  108. getContactsMenu().find('ul li').should('have.length', 0)
  109. // I see that the contact user in the Contacts menu is not shown
  110. getContactsMenu().contains('li.contact', user.userId).should('not.exist')
  111. // I see that the contact "admin" in the Contacts menu is not shown
  112. getContactsMenu().contains('li.contact', admin.userId).should('not.exist')
  113. })
  114. it('Users from other groups are not seen in the contacts menu when autocompletion is restricted within the same group', () => {
  115. // I enable restricting username autocompletion to groups
  116. cy.runOccCommand('config:app:set --value yes core shareapi_restrict_user_enumeration_to_group')
  117. // I open the Contacts menu
  118. getContactsMenuToggle().click()
  119. // I see that the Contacts menu is shown
  120. getContactsMenu().should('exist')
  121. // I see that the contact user in the Contacts menu is not shown
  122. getContactsMenu().contains('li.contact', user.userId).should('not.exist')
  123. // I see that the contact "admin" in the Contacts menu is not shown
  124. getContactsMenu().contains('li.contact', admin.userId).should('not.exist')
  125. // I close the Contacts menu
  126. getContactsMenuToggle().click()
  127. // I disable restricting username autocompletion to groups
  128. cy.runOccCommand('config:app:set --value no core shareapi_restrict_user_enumeration_to_group')
  129. // I open the Contacts menu
  130. getContactsMenuToggle().click()
  131. // I see that the Contacts menu is shown
  132. getContactsMenu().should('exist')
  133. // I see that the contact user in the Contacts menu is shown
  134. getContactsMenu().contains('li.contact', user.userId).should('be.visible')
  135. // I see that the contact "admin" in the Contacts menu is not shown
  136. getContactsMenu().contains('li.contact', admin.userId).should('not.exist')
  137. })
  138. })