admin.spec.ts 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402
  1. import { isExcludedBySharding, startWith } from './helpers/config'
  2. import {
  3. activateUser,
  4. createMongoUser,
  5. ensureUserExists,
  6. login,
  7. } from './helpers/login'
  8. import { v4 as uuid } from 'uuid'
  9. import { createProject } from './helpers/project'
  10. import { beforeWithReRunOnTestRetry } from './helpers/beforeWithReRunOnTestRetry'
  11. import { openEmail } from './helpers/email'
  12. describe('admin panel', function () {
  13. function registrationTests() {
  14. it('via GUI and opening URL manually', function () {
  15. const user = `${uuid()}@example.com`
  16. cy.findByLabelText('Emails to register new users').type(user + '{enter}')
  17. cy.findByRole('cell', { name: /\/user\/activate/ }).then($td => {
  18. const url = $td.text().trim()
  19. activateUser(url)
  20. })
  21. })
  22. it('via GUI and email', function () {
  23. const user = `${uuid()}@example.com`
  24. cy.findByLabelText('Emails to register new users').type(user + '{enter}')
  25. let url: string
  26. cy.findByRole('cell', { name: /\/user\/activate/ }).then($td => {
  27. url = $td.text().trim()
  28. })
  29. cy.then(() => {
  30. openEmail(
  31. 'Activate your E2E test Account',
  32. (frame, { url }) => {
  33. frame.contains('a', 'Set password').then(el => {
  34. expect(el.attr('href')!).to.equal(url)
  35. })
  36. },
  37. { url }
  38. )
  39. // Run activateUser in the main origin instead of inside openEmail. See docs on openEmail.
  40. activateUser(url)
  41. })
  42. })
  43. it('via script and opening URL manually', function () {
  44. const user = `${uuid()}@example.com`
  45. let url: string
  46. cy.then(async () => {
  47. ;({ url } = await createMongoUser({ email: user }))
  48. })
  49. cy.then(() => {
  50. activateUser(url)
  51. })
  52. })
  53. it('via script and email', function () {
  54. const user = `${uuid()}@example.com`
  55. let url: string
  56. cy.then(async () => {
  57. ;({ url } = await createMongoUser({ email: user }))
  58. })
  59. cy.then(() => {
  60. openEmail(
  61. 'Activate your E2E test Account',
  62. (frame, { url }) => {
  63. frame.contains('a', 'Set password').then(el => {
  64. expect(el.attr('href')!).to.equal(url)
  65. })
  66. },
  67. { url }
  68. )
  69. // Run activateUser in the main origin instead of inside openEmail. See docs on openEmail.
  70. activateUser(url)
  71. })
  72. })
  73. }
  74. describe('in CE', function () {
  75. if (isExcludedBySharding('CE_DEFAULT')) return
  76. startWith({ pro: false, version: 'latest' })
  77. const admin = 'admin@example.com'
  78. const user = `user+${uuid()}@example.com`
  79. ensureUserExists({ email: admin, isAdmin: true })
  80. ensureUserExists({ email: user })
  81. describe('create users', function () {
  82. beforeEach(function () {
  83. login(admin)
  84. cy.visit('/project')
  85. cy.findByRole('menuitem', { name: 'Admin' }).click()
  86. cy.findByRole('menuitem', { name: 'Manage Users' }).click()
  87. })
  88. registrationTests()
  89. })
  90. })
  91. describe('in server pro', function () {
  92. const admin = 'admin@example.com'
  93. const user1 = 'user@example.com'
  94. const user2 = 'user2@example.com'
  95. let testProjectName = ''
  96. let testProjectId = ''
  97. let deletedProjectName = ''
  98. let projectToDeleteId = ''
  99. const findProjectRow = (projectName: string) => {
  100. cy.log('find project row')
  101. return cy.findByText(projectName).parent().parent()
  102. }
  103. if (isExcludedBySharding('PRO_DEFAULT_2')) return
  104. startWith({
  105. pro: true,
  106. })
  107. ensureUserExists({ email: admin, isAdmin: true })
  108. ensureUserExists({ email: user1 })
  109. ensureUserExists({ email: user2 })
  110. beforeWithReRunOnTestRetry(() => {
  111. testProjectName = `project-${uuid()}`
  112. deletedProjectName = `deleted-project-${uuid()}`
  113. login(user1)
  114. createProject(testProjectName, { open: false }).then(
  115. id => (testProjectId = id)
  116. )
  117. createProject(deletedProjectName, { open: false }).then(
  118. id => (projectToDeleteId = id)
  119. )
  120. })
  121. describe('admin menu items', function () {
  122. beforeEach(function () {
  123. login(admin)
  124. cy.visit('/project')
  125. })
  126. it('displays expected admin menu items', function () {
  127. const menuitems = ['Manage Site', 'Manage Users', 'Project URL Lookup']
  128. menuitems.forEach(name => {
  129. cy.findByRole('menuitem', { name: 'Admin' }).click()
  130. cy.findByRole('menu')
  131. .findAllByRole('menuitem')
  132. .should('have.length', menuitems.length)
  133. cy.findByRole('menu').findByRole('menuitem', { name }).click()
  134. })
  135. })
  136. })
  137. describe('manage site', function () {
  138. beforeEach(function () {
  139. login(admin)
  140. cy.visit('/project')
  141. cy.findByRole('menuitem', { name: 'Admin' }).click()
  142. cy.findByRole('menuitem', { name: 'Manage Site' }).click()
  143. })
  144. it('publish and clear admin messages', function () {
  145. const message = 'Admin Message ' + uuid()
  146. cy.log('create system message')
  147. cy.findByRole('tab', { name: 'System Messages' }).click()
  148. cy.findByLabelText('Message').type(message)
  149. cy.findByRole('button', { name: 'Post Message' }).click()
  150. cy.findByText(message)
  151. login(user1)
  152. cy.visit('/project')
  153. cy.findByText(message)
  154. cy.log('clear system messages')
  155. login(admin)
  156. cy.visit('/project')
  157. cy.findByRole('menuitem', { name: 'Admin' }).click()
  158. cy.findByRole('menuitem', { name: 'Manage Site' }).click()
  159. cy.findByRole('tab', { name: 'System Messages' }).click()
  160. cy.findByRole('button', { name: 'Clear all messages' }).click()
  161. cy.log('verify system messages are no longer displayed')
  162. login(user1)
  163. cy.visit('/project')
  164. cy.findByText(message).should('not.exist')
  165. })
  166. })
  167. describe('manage users', function () {
  168. beforeEach(function () {
  169. login(admin)
  170. cy.visit('/project')
  171. cy.findByRole('menuitem', { name: 'Admin' }).click()
  172. cy.findByRole('menuitem', { name: 'Manage Users' }).click()
  173. })
  174. it('displays expected tabs', function () {
  175. const tabs = ['Users', 'License Usage']
  176. cy.findAllByRole('tab').should('have.length', tabs.length)
  177. tabs.forEach(tabName => {
  178. cy.findByRole('tab', { name: tabName }).click()
  179. })
  180. })
  181. it('license usage tab', function () {
  182. cy.findByRole('tab', { name: 'License Usage' }).click()
  183. cy.findByText(
  184. 'An active user is one who has opened a project in this Server Pro instance in the last 12 months.'
  185. )
  186. })
  187. describe('create users', function () {
  188. beforeEach(function () {
  189. cy.findByRole('link', { name: 'New User' }).click()
  190. })
  191. registrationTests()
  192. })
  193. it('user list RegExp search', function () {
  194. cy.findByLabelText('RegExp').click()
  195. cy.findByPlaceholderText('Search users by email or id…').type(
  196. 'user[0-9]{enter}'
  197. )
  198. cy.findByRole('link', { name: user2 })
  199. cy.findByRole('link', { name: user1 }).should('not.exist')
  200. })
  201. })
  202. describe('user page', function () {
  203. beforeEach(function () {
  204. login(admin)
  205. cy.visit('/project')
  206. cy.findByRole('menuitem', { name: 'Admin' }).click()
  207. cy.findByRole('menuitem', { name: 'Manage Users' }).click()
  208. cy.findByPlaceholderText('Search users by email or id…').type(
  209. user1 + '{enter}'
  210. )
  211. cy.findByRole('link', { name: user1 }).click()
  212. cy.url().should('match', /\/admin\/user\/[a-fA-F0-9]{24}/)
  213. })
  214. it('displays expected tabs', function () {
  215. const tabs = [
  216. 'User Info',
  217. 'Projects',
  218. 'Deleted Projects',
  219. 'Audit Log',
  220. 'Sessions',
  221. 'Personal Access Tokens',
  222. ]
  223. cy.findAllByRole('tab').should('have.length', tabs.length)
  224. tabs.forEach(tabName => {
  225. cy.findByRole('tab', { name: tabName }).click()
  226. })
  227. })
  228. describe('user info tab', function () {
  229. beforeEach(function () {
  230. cy.findByRole('tab', { name: 'User Info' }).click()
  231. })
  232. it('displays required sections', function () {
  233. // not exhaustive list, checks the tab content is rendered
  234. cy.findByRole('heading', { name: 'Profile' })
  235. cy.findByRole('heading', { name: 'Editor Settings' })
  236. })
  237. it('should not display SaaS-only sections', function () {
  238. cy.findByLabelText('Referred User Count').should('not.exist')
  239. cy.findByRole('heading', { name: /Split Test Assignments/ }).should(
  240. 'not.exist'
  241. )
  242. cy.findByRole('heading', { name: 'Experimental Features' }).should(
  243. 'not.exist'
  244. )
  245. cy.findByRole('heading', { name: 'Service Integration' }).should(
  246. 'not.exist'
  247. )
  248. cy.findByRole('heading', { name: 'SSO Integrations' }).should(
  249. 'not.exist'
  250. )
  251. cy.findByRole('heading', { name: 'Security' }).should('not.exist')
  252. })
  253. })
  254. it('transfer project ownership', function () {
  255. cy.log("access project admin through owners' project list")
  256. cy.findByRole('tablist').within(() => {
  257. cy.findByRole('tab', { name: 'Projects' }).click()
  258. })
  259. cy.findByRole('link', { name: testProjectName })
  260. .parent()
  261. .parent()
  262. .within(() => {
  263. cy.findByRole('link', { name: 'Project information' }).click()
  264. })
  265. cy.findByRole('button', { name: 'Transfer Ownership' }).click()
  266. cy.findByRole('dialog').within(() => {
  267. cy.findByRole('heading', { name: 'Transfer Ownership of Project' })
  268. cy.findByRole('button', { name: 'Find' }).should('be.disabled')
  269. cy.findByRole('button', { name: 'Confirm' }).should('be.disabled')
  270. cy.findByPlaceholderText('User ID or Email').type(user2)
  271. cy.findByRole('button', { name: 'Find' }).should('not.be.disabled')
  272. cy.findByRole('button', { name: 'Find' }).click()
  273. cy.findByText('Transfer project to this user?')
  274. cy.findByRole('cell', { name: 'ID' })
  275. cy.findByRole('cell', { name: 'Name' })
  276. cy.findByRole('cell', { name: 'Email' })
  277. cy.findByRole('cell', { name: user2 })
  278. cy.findByRole('button', { name: 'Confirm' }).should('not.be.disabled')
  279. cy.findByRole('button', { name: 'Confirm' }).click()
  280. })
  281. cy.log('check the project is displayed in the new owner projects tab')
  282. cy.findByPlaceholderText('Search users by email or id…').type(
  283. user2 + '{enter}'
  284. )
  285. cy.findByRole('link', { name: user2 }).click()
  286. cy.findByRole('tablist').within(() => {
  287. cy.findByRole('tab', { name: 'Projects' }).click()
  288. })
  289. cy.findByRole('link', { name: testProjectName })
  290. .parent()
  291. .parent()
  292. .within(() => {
  293. cy.findByRole('link', { name: 'Project information' }).click()
  294. })
  295. })
  296. })
  297. describe('project page', function () {
  298. beforeEach(function () {
  299. login(admin)
  300. cy.visit(`/admin/project/${testProjectId}`)
  301. })
  302. it('displays expected tabs', function () {
  303. const tabs = ['Project Info', 'Deleted Docs', 'Audit Log']
  304. cy.findAllByRole('tab').should('have.length', tabs.length)
  305. tabs.forEach(tabName => {
  306. cy.findByRole('tab', { name: tabName }).click()
  307. })
  308. })
  309. })
  310. it('restore deleted projects', function () {
  311. login(user1)
  312. cy.visit('/project')
  313. cy.log('select project to delete')
  314. findProjectRow(deletedProjectName).within(() =>
  315. cy
  316. .findByRole('checkbox', { name: `Select ${deletedProjectName}` })
  317. .first()
  318. .check()
  319. )
  320. cy.log('delete project')
  321. findProjectRow(deletedProjectName).within(() =>
  322. cy.findByRole('button', { name: 'Trash' }).click()
  323. )
  324. cy.findByRole('button', { name: 'Confirm' }).click()
  325. cy.findByRole('link', { name: deletedProjectName }).should('not.exist')
  326. cy.log('navigate to thrashed projects and delete the project')
  327. cy.findByRole('navigation', {
  328. name: 'Project categories and tags',
  329. })
  330. .findByRole('button', { name: 'Trashed projects' })
  331. .click()
  332. findProjectRow(deletedProjectName).within(() =>
  333. cy.findByRole('button', { name: 'Delete' }).click()
  334. )
  335. cy.findByRole('button', { name: 'Confirm' }).click()
  336. cy.findByRole('link', { name: deletedProjectName }).should('not.exist')
  337. cy.log('login as an admin and navigate to the deleted project')
  338. login(admin)
  339. cy.visit('/admin/user')
  340. cy.findByPlaceholderText('Search users by email or id…').type(
  341. user1 + '{enter}'
  342. )
  343. cy.findByRole('link', { name: user1 }).click()
  344. cy.findByRole('tab', { name: 'Deleted Projects' }).click()
  345. cy.findByRole('link', { name: deletedProjectName }).click()
  346. cy.log('undelete the project')
  347. cy.findByRole('button', { name: 'Undelete' }).click()
  348. cy.findByRole('button', { name: 'Undelete' }).should('not.exist')
  349. cy.url().should('contain', `/admin/project/${projectToDeleteId}`)
  350. cy.log('login as the user and verify the project is restored')
  351. login(user1)
  352. cy.visit('/project')
  353. cy.findByRole('navigation', {
  354. name: 'Project categories and tags',
  355. })
  356. .findByRole('button', { name: 'Trashed projects' })
  357. .click()
  358. cy.findByRole('link', { name: `${deletedProjectName} (Restored)` })
  359. })
  360. })
  361. })