mirror of https://github.com/rancher/dashboard.git
Improve createUser params
This commit is contained in:
parent
cff5228461
commit
0080233b60
|
|
@ -50,6 +50,14 @@ describe('Rancher setup', { tags: '@adminUser' }, () => {
|
||||||
cy.login();
|
cy.login();
|
||||||
|
|
||||||
// Note: the username argument here should match the TEST_USERNAME env var used when running non-admin tests
|
// Note: the username argument here should match the TEST_USERNAME env var used when running non-admin tests
|
||||||
cy.createUser('standard_user', 'user');
|
cy.createUser({
|
||||||
|
username: 'standard_user0',
|
||||||
|
globalRole: { role: 'user' },
|
||||||
|
projectRole: {
|
||||||
|
clusterId: 'local',
|
||||||
|
projectName: 'Default',
|
||||||
|
role: 'project-member',
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,22 @@ import { UserPreferences } from '@shell/types/userPreferences';
|
||||||
|
|
||||||
type Matcher = '$' | '^' | '~' | '*' | '';
|
type Matcher = '$' | '^' | '~' | '*' | '';
|
||||||
|
|
||||||
|
export type CreateUserParams = {
|
||||||
|
username: string,
|
||||||
|
globalRole?: {
|
||||||
|
role: string,
|
||||||
|
},
|
||||||
|
clusterRole?: {
|
||||||
|
clusterId: string,
|
||||||
|
role: string,
|
||||||
|
},
|
||||||
|
projectRole?: {
|
||||||
|
clusterId: string,
|
||||||
|
projectName: string,
|
||||||
|
role: string,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line no-unused-vars
|
// eslint-disable-next-line no-unused-vars
|
||||||
declare namespace Cypress {
|
declare namespace Cypress {
|
||||||
interface Chainable {
|
interface Chainable {
|
||||||
|
|
@ -12,7 +28,7 @@ declare namespace Cypress {
|
||||||
login(username?: string, password?: string, cacheSession?: boolean): Chainable<Element>;
|
login(username?: string, password?: string, cacheSession?: boolean): Chainable<Element>;
|
||||||
byLabel(label: string): Chainable<Element>;
|
byLabel(label: string): Chainable<Element>;
|
||||||
|
|
||||||
createUser(username: string, role?: string): Chainable;
|
createUser(params: CreateUserParams): Chainable;
|
||||||
setGlobalRoleBinding(userId: string, role: string): Chainable;
|
setGlobalRoleBinding(userId: string, role: string): Chainable;
|
||||||
setClusterRoleBinding(clusterId: string, userPrincipalId: string, role: string): Chainable;
|
setClusterRoleBinding(clusterId: string, userPrincipalId: string, role: string): Chainable;
|
||||||
setProjectRoleBinding(clusterId: string, userPrincipalId: string, projectName: string, role: string): Chainable;
|
setProjectRoleBinding(clusterId: string, userPrincipalId: string, projectName: string, role: string): Chainable;
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import { LoginPagePo } from '@/cypress/e2e/po/pages/login-page.po';
|
import { LoginPagePo } from '@/cypress/e2e/po/pages/login-page.po';
|
||||||
import { Matcher } from '@/cypress/support/types';
|
import { Matcher } from '@/cypress/support/types';
|
||||||
|
import { CreateUserParams } from '@/cypress/globals';
|
||||||
|
|
||||||
let token: any;
|
let token: any;
|
||||||
|
|
||||||
|
|
@ -60,7 +61,11 @@ Cypress.Commands.add('login', (
|
||||||
/**
|
/**
|
||||||
* Create user via api request
|
* Create user via api request
|
||||||
*/
|
*/
|
||||||
Cypress.Commands.add('createUser', (username, role?) => {
|
Cypress.Commands.add('createUser', (params: CreateUserParams) => {
|
||||||
|
const {
|
||||||
|
username, globalRole, clusterRole, projectRole
|
||||||
|
} = params;
|
||||||
|
|
||||||
return cy.request({
|
return cy.request({
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: `${ Cypress.env('api') }/v3/users`,
|
url: `${ Cypress.env('api') }/v3/users`,
|
||||||
|
|
@ -87,9 +92,22 @@ Cypress.Commands.add('createUser', (username, role?) => {
|
||||||
|
|
||||||
const userPrincipalId = resp.body.principalIds[0];
|
const userPrincipalId = resp.body.principalIds[0];
|
||||||
|
|
||||||
if (role) {
|
if (globalRole) {
|
||||||
return cy.setGlobalRoleBinding(resp.body.id, role)
|
return cy.setGlobalRoleBinding(resp.body.id, globalRole.role)
|
||||||
.then(() => cy.setProjectRoleBinding('local', userPrincipalId, 'Default', 'project-member'));
|
.then(() => {
|
||||||
|
if (clusterRole) {
|
||||||
|
const { clusterId, role } = clusterRole;
|
||||||
|
|
||||||
|
return cy.setClusterRoleBinding(clusterId, userPrincipalId, role);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
if (projectRole) {
|
||||||
|
const { clusterId, projectName, role } = projectRole;
|
||||||
|
|
||||||
|
return cy.setProjectRoleBinding(clusterId, userPrincipalId, projectName, role);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -147,7 +165,7 @@ Cypress.Commands.add('setClusterRoleBinding', (clusterId, userPrincipalId, role)
|
||||||
*/
|
*/
|
||||||
Cypress.Commands.add('setProjectRoleBinding', (clusterId, userPrincipalId, projectName, role) => {
|
Cypress.Commands.add('setProjectRoleBinding', (clusterId, userPrincipalId, projectName, role) => {
|
||||||
return cy.getProject(clusterId, projectName)
|
return cy.getProject(clusterId, projectName)
|
||||||
.then((project) => cy.request({
|
.then((project: any) => cy.request({
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: `${ Cypress.env('api') }/v3/projectroletemplatebindings`,
|
url: `${ Cypress.env('api') }/v3/projectroletemplatebindings`,
|
||||||
headers: {
|
headers: {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue