Skip to content

Commit

Permalink
Review#1: return 403 instead of 404 if current license does not suppo…
Browse files Browse the repository at this point in the history
…rt access agreement, minor test fixes.
  • Loading branch information
azasypkin committed Apr 28, 2020
1 parent 99332b2 commit 3c7cf49
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ describe('license features', function() {
}
});

it('should show login page and other security elements, allow RBAC but forbid role mappings, access agreement, DLS, and sub-feature privileges if license is basic.', () => {
it('should show login page and other security elements, allow RBAC but forbid paid features if license is basic.', () => {
const mockRawLicense = licensingMock.createLicense({
features: { security: { isEnabled: true, isAvailable: true } },
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,16 +458,16 @@ describe('Common authentication routes', () => {
expect(routeConfig.validate).toBe(false);
});

it('returns 404 if current license doesnt allow access agreement acknowledgement.', async () => {
it(`returns 403 if current license doesn't allow access agreement acknowledgement.`, async () => {
license.getFeatures.mockReturnValue({
allowAccessAgreement: false,
} as SecurityLicenseFeatures);

const request = httpServerMock.createKibanaRequest();
await expect(routeHandler(mockContext, request, kibanaResponseFactory)).resolves.toEqual({
status: 404,
payload: 'Not Found',
options: {},
status: 403,
payload: { message: `Current license doesn't support access agreement.` },
options: { body: { message: `Current license doesn't support access agreement.` } },
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,10 @@ export function defineCommonRoutes({
createLicensedRouteHandler(async (context, request, response) => {
// If license doesn't allow access agreement we shouldn't handle request.
if (!license.getFeatures().allowAccessAgreement) {
logger.warn(`Attempted to acknowledge access agreement when license doesn allow it.`);
return response.notFound();
logger.warn(`Attempted to acknowledge access agreement when license doesn't allow it.`);
return response.forbidden({
body: { message: `Current license doesn't support access agreement.` },
});
}

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ describe('Access agreement view routes', () => {
await routeHandler(mockContext, request, responseFactory);

expect(responseFactory.renderCoreApp).not.toHaveBeenCalledWith();
expect(responseFactory.notFound).toHaveBeenCalledTimes(1);
expect(responseFactory.forbidden).toHaveBeenCalledTimes(1);
});

it('renders view.', async () => {
Expand Down Expand Up @@ -108,17 +108,17 @@ describe('Access agreement view routes', () => {
expect(routeConfig.validate).toBe(false);
});

it('returns `Not Found` if current license does not allow access agreement.', async () => {
it('returns `403` if current license does not allow access agreement.', async () => {
const request = httpServerMock.createKibanaRequest();

license.getFeatures.mockReturnValue({
allowAccessAgreement: false,
} as SecurityLicenseFeatures);

await expect(routeHandler(mockContext, request, kibanaResponseFactory)).resolves.toEqual({
status: 404,
payload: 'Not Found',
options: {},
status: 403,
payload: { message: `Current license doesn't support access agreement.` },
options: { body: { message: `Current license doesn't support access agreement.` } },
});
});

Expand Down
10 changes: 8 additions & 2 deletions x-pack/plugins/security/server/routes/views/access_agreement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,21 @@ export function defineAccessAgreementRoutes({
httpResources.register(
{ path: '/security/access_agreement', validate: false },
createLicensedRouteHandler(async (context, request, response) =>
canHandleRequest() ? response.renderCoreApp() : response.notFound()
canHandleRequest()
? response.renderCoreApp()
: response.forbidden({
body: { message: `Current license doesn't support access agreement.` },
})
)
);

router.get(
{ path: '/internal/security/access_agreement/state', validate: false },
createLicensedRouteHandler(async (context, request, response) => {
if (!canHandleRequest()) {
return response.notFound();
return response.forbidden({
body: { message: `Current license doesn't support access agreement.` },
});
}

// It's not guaranteed that we'll have session for the authenticated user (e.g. when user is
Expand Down

0 comments on commit 3c7cf49

Please sign in to comment.