Skip to content

Commit

Permalink
Fix broken unit tests
Browse files Browse the repository at this point in the history
These unit tests were not using mocks correctly, so they passed when
they should not have:
 * '#find returns empty result if user is unauthorized in any space'
 * '#openPointInTimeForType throws error if if user is unauthorized in any space'

The previous refactor fixed the mocks, which caused these two tests to
start failing. In this commit, I have fixed the code so the tests pass
as written.
  • Loading branch information
jportner committed Aug 24, 2021
1 parent 0b30d72 commit e6588b7
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export class SpacesSavedObjectsClient implements SavedObjectsClientContract {
try {
namespaces = await this.getSearchableSpaces(options.namespaces);
} catch (err) {
if (Boom.isBoom(err) && err.output.payload.statusCode === 403) {
if (Boom.isBoom(err) && err.output.payload.statusCode === 401) {
// return empty response, since the user is unauthorized in any space, but we don't return forbidden errors for `find` operations
return SavedObjectsUtils.createEmptyFindResponse<T, A>(options);
}
Expand Down Expand Up @@ -383,7 +383,16 @@ export class SpacesSavedObjectsClient implements SavedObjectsClientContract {
type: string | string[],
options: SavedObjectsOpenPointInTimeOptions = {}
) {
const namespaces = await this.getSearchableSpaces(options.namespaces);
let namespaces: string[];
try {
namespaces = await this.getSearchableSpaces(options.namespaces);
} catch (err) {
if (Boom.isBoom(err) && err.output.payload.statusCode === 401) {
// throw bad request since the user is unauthorized in any space
throw SavedObjectsErrorHelpers.createBadRequestError();
}
throw err;
}
if (namespaces.length === 0) {
// throw bad request if no valid spaces were found.
throw SavedObjectsErrorHelpers.createBadRequestError();
Expand Down

0 comments on commit e6588b7

Please sign in to comment.