Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update error page for advance authorization errors #1123

Merged
merged 2 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ const brandingData = {
} as BrandingData;

describe('Issue component', () => {
it('should render the sessionExpired error', () => {
const issue = {
type: 'sessionExpired',
error: new Error('401 Unauthorized'),
} as Issue;
const component = <IssueComponent branding={brandingData} issue={issue} />;

expect(renderer.create(component).toJSON()).toMatchSnapshot();
});

it('should render the SSO error', () => {
const issue = {
type: 'sso',
Expand Down Expand Up @@ -143,6 +153,16 @@ describe('Issue component', () => {
expect(renderer.create(component).toJSON()).toMatchSnapshot();
});

it('should render namespace provision error', () => {
const issue = {
type: 'namespaceProvisioningError',
error: new Error('500 Internal Server Error'),
} as Issue;
const component = <IssueComponent branding={brandingData} issue={issue} />;

expect(renderer.create(component).toJSON()).toMatchSnapshot();
});

it('should render an unknown error', () => {
const issue = {
type: 'unknown',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ export class IssueComponent extends React.PureComponent<Props> {
return this.renderWorkspaceStoppedWithError(issue.error, issue.data);
case 'workspaceStopped':
return this.renderWorkspaceStopped(issue.data);
case 'namespaceProvisioningError':
return this.renderNamespaceProvisionError(issue.error);
default:
return this.renderUnknownError(issue.error);
}
Expand Down Expand Up @@ -254,6 +256,24 @@ export class IssueComponent extends React.PureComponent<Props> {
);
}

private renderNamespaceProvisionError(error: Error): React.ReactNode {
const errorTextbox = !error ? undefined : (
<Text component={TextVariants.pre} className={styles.errorMessage}>
{error.message}
</Text>
);

return (
<TextContent className={styles.messageContainer}>
<Text component={TextVariants.h1}>
<WarningTriangleIcon className={styles.warningIcon} />
Error
</Text>
{errorTextbox}
</TextContent>
);
}

private renderUnknownError(error: Error): React.ReactNode {
const errorTextbox = !error ? undefined : (
<Text component={TextVariants.pre} className={styles.errorMessage}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,26 +118,6 @@ exports[`Layout component snapshot of the namespace provisioning error page 1`]
>
Namespace provisioning error
</pre>
<p
className=""
data-ouia-component-id="OUIA-Generated-Text-3"
data-ouia-component-type="PF4/Text"
data-ouia-safe={true}
data-pf-content={true}
>
Please try
<kbd
className="keybinding"
>
Shift
</kbd>
+
<kbd
className="keybinding"
>
Refresh
</kbd>
</p>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,168 +65,4 @@ describe('Check namespace provision warnings', () => {
},
]);
});

it('should register the advanced authorization warning for allowGroups', () => {
const store = new FakeStoreBuilder()
.withDwServerConfig({
networking: {
auth: {
advancedAuthorization: {
allowGroups: ['test-group'],
},
},
},
})
.build();

checkNamespaceProvisionWarnings(store.getState);

expect(warningsReporterService.hasWarning).toBeTruthy();
expect(warningsReporterService.reportAllWarnings()).toEqual([
{
key: 'advancedAuthorizationGroupsWarning',
title:
'Advanced authorization is enabled. User might not be allowed. Please, contact the administrator.',
},
]);
});

it('should register the advanced authorization warning for denyGroups', () => {
const store = new FakeStoreBuilder()
.withDwServerConfig({
networking: {
auth: {
advancedAuthorization: {
denyGroups: ['test-group'],
},
},
},
})
.build();

checkNamespaceProvisionWarnings(store.getState);

expect(warningsReporterService.hasWarning).toBeTruthy();
expect(warningsReporterService.reportAllWarnings()).toEqual([
{
key: 'advancedAuthorizationGroupsWarning',
title:
'Advanced authorization is enabled. User might not be allowed. Please, contact the administrator.',
},
]);
});

it('should register the advanced authorization warning for allowGroups', () => {
const store = new FakeStoreBuilder()
.withDwServerConfig({
networking: {
auth: {
advancedAuthorization: {
allowGroups: ['test-group'],
},
},
},
})
.build();

checkNamespaceProvisionWarnings(store.getState);

expect(warningsReporterService.hasWarning).toBeTruthy();
expect(warningsReporterService.reportAllWarnings()).toEqual([
{
key: 'advancedAuthorizationGroupsWarning',
title:
'Advanced authorization is enabled. User might not be allowed. Please, contact the administrator.',
},
]);
});

it('should register the advanced authorization warning for allowUsers', () => {
const store = new FakeStoreBuilder()
.withDwServerConfig({
networking: {
auth: {
advancedAuthorization: {
allowUsers: ['user0'],
},
},
},
})
.build();

checkNamespaceProvisionWarnings(store.getState);

expect(warningsReporterService.hasWarning).toBeTruthy();
expect(warningsReporterService.reportAllWarnings()).toEqual([
{
key: 'advancedAuthorizationUsersWarning',
title:
'Advanced authorization is enabled. User might not be allowed. Please, contact the administrator.',
},
]);
});

it('should register the advanced authorization warning for denyUsers', () => {
const store = new FakeStoreBuilder()
.withDwServerConfig({
networking: {
auth: {
advancedAuthorization: {
denyUsers: ['test-user'],
},
},
},
})
.build();

checkNamespaceProvisionWarnings(store.getState);

expect(warningsReporterService.hasWarning).toBeTruthy();
expect(warningsReporterService.reportAllWarnings()).toEqual([
{
key: 'advancedAuthorizationUsersWarning',
title:
'Advanced authorization is enabled. User might not be allowed. Please, contact the administrator.',
},
]);
});

it('should register all possible warnings', () => {
const store = new FakeStoreBuilder()
.withDwServerConfig({
defaultNamespace: {
autoProvision: false,
},
networking: {
auth: {
advancedAuthorization: {
denyUsers: ['test-user'],
denyGroups: ['test-group'],
},
},
},
})
.build();

checkNamespaceProvisionWarnings(store.getState);

expect(warningsReporterService.hasWarning).toBeTruthy();
expect(warningsReporterService.reportAllWarnings()).toEqual([
{
key: 'autoProvisionWarning',
title:
'Automatic namespace provisioning is disabled. Namespace might not have been configured yet. Please, contact the administrator.',
},
{
key: 'advancedAuthorizationGroupsWarning',
title:
'Advanced authorization is enabled. User might not be allowed. Please, contact the administrator.',
},
{
key: 'advancedAuthorizationUsersWarning',
title:
'Advanced authorization is enabled. User might not be allowed. Please, contact the administrator.',
},
]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import { container } from '@/inversify.config';
import { WarningsReporterService } from '@/services/bootstrap/warningsReporter';
import { AppState } from '@/store';
import { selectAdvancedAuthorization, selectAutoProvision } from '@/store/ServerConfig/selectors';
import { selectAutoProvision } from '@/store/ServerConfig/selectors';

const warningsReporterService = container.get(WarningsReporterService);

Expand All @@ -26,21 +26,4 @@ export function checkNamespaceProvisionWarnings(getState: () => AppState): void
`Automatic namespace provisioning is disabled. Namespace might not have been configured yet. Please, contact the administrator.`,
);
}

const advancedAuthorization = selectAdvancedAuthorization(state);
if (advancedAuthorization === undefined || Object.keys(advancedAuthorization).length === 0) {
return;
}
if (advancedAuthorization.allowGroups || advancedAuthorization.denyGroups) {
warningsReporterService.registerWarning(
'advancedAuthorizationGroupsWarning',
`Advanced authorization is enabled. User might not be allowed. Please, contact the administrator.`,
);
}
if (advancedAuthorization.allowUsers || advancedAuthorization.denyUsers) {
warningsReporterService.registerWarning(
'advancedAuthorizationUsersWarning',
`Advanced authorization is enabled. User might not be allowed. Please, contact the administrator.`,
);
}
}
Loading
Loading