Skip to content

Commit

Permalink
Address PR feedback - isSuperUser check
Browse files Browse the repository at this point in the history
  • Loading branch information
cee-chen committed Jul 6, 2020
1 parent 9d5731d commit ca3daf1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
24 changes: 20 additions & 4 deletions x-pack/plugins/enterprise_search/server/lib/check_access.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ describe('checkAccess', () => {
hasAllRequested: false,
}),
}),
actions: {
ui: {
get: () => null,
},
},
},
};
const mockDependencies = {
Expand Down Expand Up @@ -60,19 +65,30 @@ describe('checkAccess', () => {
});
});

it("falls back to assuming a non-superuser role if a user's roles cannot be accessed", async () => {
it('falls back to assuming a non-superuser role if auth credentials are missing', async () => {
const security = {
...mockSecurity,
authz: {
mode: { useRbacForRequest: () => true },
checkPrivilegesWithRequest: undefined,
...mockSecurity.authz,
checkPrivilegesWithRequest: () => ({
globally: () => Promise.reject({ statusCode: 403 }),
}),
},
};
expect(await checkAccess({ ...mockDependencies, security })).toEqual({
hasAppSearchAccess: false,
hasWorkplaceSearchAccess: false,
});
});

it('throws other authz errors', async () => {
const security = {
authz: {
...mockSecurity.authz,
checkPrivilegesWithRequest: undefined,
},
};
await expect(checkAccess({ ...mockDependencies, security })).rejects.toThrow();
});
});

describe('when the user is a non-superuser', () => {
Expand Down
5 changes: 4 additions & 1 deletion x-pack/plugins/enterprise_search/server/lib/check_access.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ export const checkAccess = async ({
.globally(security.authz.actions.ui.get('enterprise_search', 'app_search'));
return hasAllRequested;
} catch (err) {
return false;
if (err.statusCode === 401 || err.statusCode === 403) {
return false;
}
throw err;
}
};
if (await isSuperUser()) {
Expand Down

0 comments on commit ca3daf1

Please sign in to comment.