|
| 1 | +/** |
| 2 | + * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors |
| 3 | + * SPDX-License-Identifier: AGPL-3.0-or-later |
| 4 | + * |
| 5 | + * Regression test for: https://github.com/nextcloud/server/issues/55785 |
| 6 | + * |
| 7 | + * Tests that group display names are shown correctly in the user editor, |
| 8 | + * even when the group ID differs from the display name (e.g., when long |
| 9 | + * group names get hashed to create the group ID). |
| 10 | + */ |
| 11 | + |
| 12 | +import { User } from '@nextcloud/cypress' |
| 13 | +import { getUserListRow, handlePasswordConfirmation, toggleEditButton } from './usersUtils' |
| 14 | + |
| 15 | +// eslint-disable-next-line n/no-extraneous-import |
| 16 | +import randomString from 'crypto-random-string' |
| 17 | + |
| 18 | +const admin = new User('admin', 'admin') |
| 19 | + |
| 20 | +describe('Settings: Group names persist after reload (issue #55785)', () => { |
| 21 | + let testUser: User |
| 22 | + // Use a very long name to ensure Nextcloud hashes it to create the group ID. |
| 23 | + // This creates a test case where group ID !== group display name. |
| 24 | + const randomPart = randomString(80) |
| 25 | + const groupName = `Test Group with Very Long Name ${randomPart}` |
| 26 | + |
| 27 | + before(() => { |
| 28 | + cy.createRandomUser().then((user) => { |
| 29 | + testUser = user |
| 30 | + }) |
| 31 | + cy.runOccCommand(`group:add '${groupName}'`).then(() => { |
| 32 | + // Verify that the group ID is different from the display name |
| 33 | + // (this confirms our test case is valid) |
| 34 | + cy.runOccCommand('group:list --output=json').then((result) => { |
| 35 | + const groups = JSON.parse(result.stdout) |
| 36 | + const groupEntry = Object.entries(groups).find(([, displayName]) => |
| 37 | + (displayName as string).includes(randomPart) |
| 38 | + ) |
| 39 | + if (groupEntry) { |
| 40 | + const [groupId, displayName] = groupEntry |
| 41 | + cy.log(`Group ID: ${groupId}`) |
| 42 | + cy.log(`Display name: ${displayName}`) |
| 43 | + // Assert that ID and name are different (this is what triggers the bug) |
| 44 | + expect(groupId).to.not.equal(displayName) |
| 45 | + } |
| 46 | + }) |
| 47 | + }) |
| 48 | + cy.login(admin) |
| 49 | + cy.intercept('GET', '**/ocs/v2.php/cloud/groups/details?search=&offset=*&limit=*').as('loadGroups') |
| 50 | + cy.visit('/settings/users') |
| 51 | + cy.wait('@loadGroups') |
| 52 | + }) |
| 53 | + |
| 54 | + it('Assign user to group', () => { |
| 55 | + toggleEditButton(testUser) |
| 56 | + |
| 57 | + getUserListRow(testUser.userId) |
| 58 | + .find('[data-cy-user-list-input-groups] input') |
| 59 | + .click({ force: true }) |
| 60 | + |
| 61 | + getUserListRow(testUser.userId) |
| 62 | + .find('[data-cy-user-list-input-groups] input') |
| 63 | + .type(randomPart.slice(0, 10)) |
| 64 | + |
| 65 | + cy.contains('li.vs__dropdown-option', groupName) |
| 66 | + .should('exist') |
| 67 | + .click({ force: true }) |
| 68 | + |
| 69 | + handlePasswordConfirmation(admin.password) |
| 70 | + |
| 71 | + toggleEditButton(testUser, false) |
| 72 | + }) |
| 73 | + |
| 74 | + it('After page reload, selected group still shows correct name', () => { |
| 75 | + // Visit the users page again to simulate a fresh page load |
| 76 | + cy.visit('/settings/users') |
| 77 | + |
| 78 | + toggleEditButton(testUser) |
| 79 | + |
| 80 | + // Verify the selected group displays the name, not the hashed ID |
| 81 | + getUserListRow(testUser.userId) |
| 82 | + .find('[data-cy-user-list-input-groups]') |
| 83 | + .should('exist') |
| 84 | + .within(() => { |
| 85 | + cy.get('.vs__selected').invoke('text').then((displayedText) => { |
| 86 | + expect(displayedText.trim()).to.include('Test Group with Very Long Name') |
| 87 | + }) |
| 88 | + }) |
| 89 | + |
| 90 | + toggleEditButton(testUser, false) |
| 91 | + }) |
| 92 | +}) |
0 commit comments