Skip to content

Commit

Permalink
Use consistent naming in the standard role editor (#50351) (#50491)
Browse files Browse the repository at this point in the history
  • Loading branch information
bl-nero authored Dec 20, 2024
1 parent 360ceb8 commit 9c314ad
Show file tree
Hide file tree
Showing 11 changed files with 254 additions and 243 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import {
RuleModel,
verbOptions,
} from './standardmodel';
import { Section, SectionProps } from './sections';
import { SectionBox, SectionProps } from './sections';

export function AccessRules({
value,
Expand Down Expand Up @@ -86,7 +86,7 @@ function AccessRule({
}) {
const { resources, verbs } = value;
return (
<Section
<SectionBox
title="Access Rule"
tooltip="A rule that gives users access to certain kinds of resources"
removable
Expand Down Expand Up @@ -114,7 +114,7 @@ function AccessRule({
rule={precomputed(validation.fields.verbs)}
mb={0}
/>
</Section>
</SectionBox>
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import Text from 'design/Text';

import { LabelsInput } from 'teleport/components/LabelsInput';

import { Section, SectionProps } from './sections';
import { SectionBox, SectionProps } from './sections';
import { MetadataModel } from './standardmodel';
import { MetadataValidationResult } from './validation';

Expand All @@ -34,7 +34,7 @@ export const MetadataSection = ({
validation,
onChange,
}: SectionProps<MetadataModel, MetadataValidationResult>) => (
<Section
<SectionBox
title="Role Metadata"
tooltip="Basic information about the role resource"
isProcessing={isProcessing}
Expand Down Expand Up @@ -66,5 +66,5 @@ export const MetadataSection = ({
setLabels={labels => onChange?.({ ...value, labels })}
rule={precomputed(validation.fields.labels)}
/>
</Section>
</SectionBox>
);
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,39 @@ import { Validator } from 'shared/components/Validation';
import selectEvent from 'react-select-event';

import {
AppAccessSpec,
DatabaseAccessSpec,
KubernetesAccessSpec,
newAccessSpec,
ServerAccessSpec,
WindowsDesktopAccessSpec,
ServerAccess,
newResourceAccess,
KubernetesAccess,
AppAccess,
DatabaseAccess,
WindowsDesktopAccess,
} from './standardmodel';
import { AccessSpecValidationResult, validateAccessSpec } from './validation';
import {
ServerAccessSpecSection,
KubernetesAccessSpecSection,
AppAccessSpecSection,
DatabaseAccessSpecSection,
WindowsDesktopAccessSpecSection,
ResourceAccessValidationResult,
validateResourceAccess,
} from './validation';
import {
ServerAccessSection,
KubernetesAccessSection,
AppAccessSection,
DatabaseAccessSection,
WindowsDesktopAccessSection,
} from './Resources';
import { StatefulSection } from './StatefulSection';

describe('ServerAccessSpecSection', () => {
describe('ServerAccessSection', () => {
const setup = () => {
const onChange = jest.fn();
let validator: Validator;
render(
<StatefulSection<ServerAccessSpec, AccessSpecValidationResult>
component={ServerAccessSpecSection}
defaultValue={newAccessSpec('node')}
<StatefulSection<ServerAccess, ResourceAccessValidationResult>
component={ServerAccessSection}
defaultValue={newResourceAccess('node')}
onChange={onChange}
validatorRef={v => {
validator = v;
}}
validate={validateAccessSpec}
validate={validateResourceAccess}
/>
);
return { user: userEvent.setup(), onChange, validator };
Expand Down Expand Up @@ -80,7 +83,7 @@ describe('ServerAccessSpecSection', () => {
expect.objectContaining({ label: 'root', value: 'root' }),
expect.objectContaining({ label: 'some-user', value: 'some-user' }),
],
} as ServerAccessSpec);
} as ServerAccess);
});

test('validation', async () => {
Expand All @@ -99,25 +102,25 @@ describe('ServerAccessSpecSection', () => {
});
});

describe('KubernetesAccessSpecSection', () => {
describe('KubernetesAccessSection', () => {
const setup = () => {
const onChange = jest.fn();
let validator: Validator;
render(
<StatefulSection<KubernetesAccessSpec, AccessSpecValidationResult>
component={KubernetesAccessSpecSection}
defaultValue={newAccessSpec('kube_cluster')}
<StatefulSection<KubernetesAccess, ResourceAccessValidationResult>
component={KubernetesAccessSection}
defaultValue={newResourceAccess('kube_cluster')}
onChange={onChange}
validatorRef={v => {
validator = v;
}}
validate={validateAccessSpec}
validate={validateResourceAccess}
/>
);
return { user: userEvent.setup(), onChange, validator };
};

test('editing the spec', async () => {
test('editing', async () => {
const { user, onChange } = setup();

await selectEvent.create(screen.getByLabelText('Groups'), 'group1', {
Expand Down Expand Up @@ -167,7 +170,7 @@ describe('KubernetesAccessSpecSection', () => {
],
},
],
} as KubernetesAccessSpec);
} as KubernetesAccess);
});

test('adding and removing resources', async () => {
Expand Down Expand Up @@ -242,19 +245,19 @@ describe('KubernetesAccessSpecSection', () => {
});
});

describe('AppAccessSpecSection', () => {
describe('AppAccessSection', () => {
const setup = () => {
const onChange = jest.fn();
let validator: Validator;
render(
<StatefulSection<AppAccessSpec, AccessSpecValidationResult>
component={AppAccessSpecSection}
defaultValue={newAccessSpec('app')}
<StatefulSection<AppAccess, ResourceAccessValidationResult>
component={AppAccessSection}
defaultValue={newResourceAccess('app')}
onChange={onChange}
validatorRef={v => {
validator = v;
}}
validate={validateAccessSpec}
validate={validateResourceAccess}
/>
);
return { user: userEvent.setup(), onChange, validator };
Expand Down Expand Up @@ -314,7 +317,7 @@ describe('AppAccessSpecSection', () => {
'{{internal.gcp_service_accounts}}',
'[email protected]',
],
} as AppAccessSpec);
} as AppAccess);
});

test('validation', async () => {
Expand Down Expand Up @@ -348,19 +351,19 @@ describe('AppAccessSpecSection', () => {
});
});

describe('DatabaseAccessSpecSection', () => {
describe('DatabaseAccessSection', () => {
const setup = () => {
const onChange = jest.fn();
let validator: Validator;
render(
<StatefulSection<DatabaseAccessSpec, AccessSpecValidationResult>
component={DatabaseAccessSpecSection}
defaultValue={newAccessSpec('db')}
<StatefulSection<DatabaseAccess, ResourceAccessValidationResult>
component={DatabaseAccessSection}
defaultValue={newResourceAccess('db')}
onChange={onChange}
validatorRef={v => {
validator = v;
}}
validate={validateAccessSpec}
validate={validateResourceAccess}
/>
);
return { user: userEvent.setup(), onChange, validator };
Expand Down Expand Up @@ -395,7 +398,7 @@ describe('DatabaseAccessSpecSection', () => {
expect.objectContaining({ value: '{{internal.db_users}}' }),
expect.objectContaining({ label: 'mary', value: 'mary' }),
],
} as DatabaseAccessSpec);
} as DatabaseAccess);
});

test('validation', async () => {
Expand All @@ -414,19 +417,19 @@ describe('DatabaseAccessSpecSection', () => {
});
});

describe('WindowsDesktopAccessSpecSection', () => {
describe('WindowsDesktopAccessSection', () => {
const setup = () => {
const onChange = jest.fn();
let validator: Validator;
render(
<StatefulSection<WindowsDesktopAccessSpec, AccessSpecValidationResult>
component={WindowsDesktopAccessSpecSection}
defaultValue={newAccessSpec('windows_desktop')}
<StatefulSection<WindowsDesktopAccess, ResourceAccessValidationResult>
component={WindowsDesktopAccessSection}
defaultValue={newResourceAccess('windows_desktop')}
onChange={onChange}
validatorRef={v => {
validator = v;
}}
validate={validateAccessSpec}
validate={validateResourceAccess}
/>
);
return { user: userEvent.setup(), onChange, validator };
Expand All @@ -447,7 +450,7 @@ describe('WindowsDesktopAccessSpecSection', () => {
expect.objectContaining({ value: '{{internal.windows_logins}}' }),
expect.objectContaining({ label: 'julio', value: 'julio' }),
],
} as WindowsDesktopAccessSpec);
} as WindowsDesktopAccess);
});

test('validation', async () => {
Expand Down
Loading

0 comments on commit 9c314ad

Please sign in to comment.