Skip to content

Commit

Permalink
fix(#3372): Change tests to share pipelines
Browse files Browse the repository at this point in the history
  • Loading branch information
tenthe committed Dec 18, 2024
1 parent 46aebf9 commit 8bdb9d4
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 58 deletions.
93 changes: 37 additions & 56 deletions ui/cypress/tests/userManagement/testUserRolePipeline.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,86 +16,67 @@
*
*/

import { UserBuilder } from '../../support/builder/UserBuilder';
import { UserRole } from '../../../src/app/_enums/user-role.enum';
import { UserUtils } from '../../support/utils/UserUtils';
import { ConnectUtils } from '../../support/utils/connect/ConnectUtils';
import { PipelineUtils } from '../../support/utils/pipeline/PipelineUtils';
import { PipelineElementBuilder } from '../../support/builder/PipelineElementBuilder';
import { PipelineBuilder } from '../../support/builder/PipelineBuilder';
import { GeneralUtils } from '../../support/utils/GeneralUtils';
import { PermissionUtils } from '../../support/utils/user/PermissionUtils';

describe('Test User Roles for Pipelines', () => {
beforeEach('Setup Test', () => {
cy.initStreamPipesTest();
ConnectUtils.addMachineDataSimulator('simulator');
const pipelineInput = PipelineBuilder.create('Pipeline Test')
.addSource('simulator')
.addProcessingElement(
PipelineElementBuilder.create('field_renamer')
.addInput('drop-down', 'convert-property', 'timestamp')
.addInput('input', 'field-name', 't')
.build(),
)
.addSink(
PipelineElementBuilder.create('data_lake')
.addInput('input', 'db_measurement', 'demo')
.build(),
)
.build();

PipelineUtils.addPipeline(pipelineInput);
// Create a machine data simulator with a sample pipeline for the tests
ConnectUtils.addMachineDataSimulator('simulator', true);
});

it('Perform Test', () => {
// Add new user
UserUtils.goToUserConfiguration();

cy.dataCy('user-accounts-table-row', { timeout: 10000 }).should(
'have.length',
1,
it('Pipeline admin should not see pipelines of other users', () => {
const newUser = UserUtils.createUser(
'user',
UserRole.ROLE_PIPELINE_ADMIN,
);

const email = '[email protected]';
const name = 'test_user';
const user = UserBuilder.create(email)
.setName(name)
.setPassword(name)
.addRole(UserRole.ROLE_PIPELINE_USER)
.build();
// Login as user and check if pipeline is visible to user
UserUtils.switchUser(newUser);

GeneralUtils.validateAmountOfNavigationIcons(4);

UserUtils.addUser(user);
PipelineUtils.goToPipelines();
PipelineUtils.checkAmountOfPipelinesPipeline(0);
});

// Check if user is added successfully
cy.dataCy('user-accounts-table-row', { timeout: 10000 }).should(
'have.length',
2,
it('Pipeline admin should see public pipelines of other users', () => {
const newUser = UserUtils.createUser(
'user',
UserRole.ROLE_PIPELINE_ADMIN,
);

// Add new authorized user to pipeline
PipelineUtils.goToPipelines();
cy.dataCy('share').click();
cy.get('label').contains('Authorized Users').click();
cy.get('mat-option').contains(email).click();
cy.dataCy('sp-element-edit-user-save').click();
PermissionUtils.markElementAsPublic();

// Login as user and check if pipeline is visible to user
UserUtils.switchUser(user);

GeneralUtils.validateAmountOfNavigationIcons(3);
UserUtils.switchUser(newUser);

PipelineUtils.goToPipelines();
cy.dataCy('all-pipelines-table', { timeout: 10000 }).should(
'have.length',
1,
);
cy.dataCy('all-pipelines-table', { timeout: 10000 }).should(
'contain',
'Pipeline Test',
PipelineUtils.checkAmountOfPipelinesPipeline(1);
});

it(' Pipeline admin should see shared pipelines of other users', () => {
const newUser = UserUtils.createUser(
'user',
UserRole.ROLE_PIPELINE_ADMIN,
);

// Delete user
UserUtils.switchUser(UserUtils.adminUser);
UserUtils.deleteUser(user);
// Add new authorized user to pipeline
PipelineUtils.goToPipelines();
PermissionUtils.markElementAsPublic();
PermissionUtils.authorizeUser(newUser.email);

// Login as user and check if pipeline is visible to user
UserUtils.switchUser(newUser);

PipelineUtils.goToPipelines();
PipelineUtils.checkAmountOfPipelinesPipeline(1);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ export class ObjectPermissionDialogComponent implements OnInit {

private addUserToSelection(authority: PermissionEntry) {
const user = this.allUsers.find(u => u.principalId === authority.sid);
this.grantedUserAuthorities.push(user);
user && this.grantedUserAuthorities.push(user);
}

private addGroupToSelection(authority: PermissionEntry) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ <h5>{{ pipeline.createdAt | date: 'dd.MM.yyyy HH:mm' }}</h5>
refreshPipelinesEmitter
)
"
data-cy="share"
data-cy="open-manage-permissions"
>
<i class="material-icons">share</i>
</button>
Expand Down

0 comments on commit 8bdb9d4

Please sign in to comment.