This repository has been archived by the owner on Mar 31, 2024. It is now read-only.
forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[server/uiSettings+shortUrl] surface errors from es
Backports PR elastic#9214 **Commit 1:** [server/uiSettings+shortUrl] surface errors from es * Original sha: 9c9b551 * Authored by spalger <[email protected]> on 2016-11-16T01:56:38Z **Commit 2:** [uiExports/replaceInjectedVars] update the uiSettings stub * Original sha: 65b1e0a * Authored by spalger <[email protected]> on 2016-11-23T23:38:04Z **Commit 3:** [uiSettings] correct test cases after moving from 401 -> 403 * Original sha: c2c7fdb * Authored by spalger <[email protected]> on 2016-11-23T23:41:08Z
- Loading branch information
spalger
committed
Nov 24, 2016
1 parent
253bde8
commit 818ebc7
Showing
17 changed files
with
358 additions
and
249 deletions.
There are no files selected for viewing
27 changes: 0 additions & 27 deletions
27
src/core_plugins/elasticsearch/lib/__tests__/get_basic_auth_realm.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,31 @@ | ||
import _ from 'lodash'; | ||
import Promise from 'bluebird'; | ||
import Boom from 'boom'; | ||
import getBasicAuthRealm from './get_basic_auth_realm'; | ||
import toPath from 'lodash/internal/toPath'; | ||
import filterHeaders from './filter_headers'; | ||
|
||
module.exports = (server, client) => { | ||
return (req, endpoint, params = {}) => { | ||
return (req, endpoint, clientParams = {}, options = {}) => { | ||
const wrap401Errors = options.wrap401Errors !== false; | ||
const filteredHeaders = filterHeaders(req.headers, server.config().get('elasticsearch.requestHeadersWhitelist')); | ||
_.set(params, 'headers', filteredHeaders); | ||
_.set(clientParams, 'headers', filteredHeaders); | ||
const path = toPath(endpoint); | ||
const api = _.get(client, path); | ||
let apiContext = _.get(client, path.slice(0, -1)); | ||
if (_.isEmpty(apiContext)) { | ||
apiContext = client; | ||
} | ||
if (!api) throw new Error(`callWithRequest called with an invalid endpoint: ${endpoint}`); | ||
return api.call(apiContext, params) | ||
return api.call(apiContext, clientParams) | ||
.catch((err) => { | ||
if (err.status === 401) { | ||
// TODO: The err.message is temporary until we have support for getting headers in the client. | ||
// Once we have that, we should be able to pass the contents of the WWW-Authenticate head to getRealm | ||
const realm = getBasicAuthRealm(err.message) || 'Authorization Required'; | ||
const options = { realm: realm }; | ||
return Promise.reject(Boom.unauthorized('Unauthorized', 'Basic', options)); | ||
if (!wrap401Errors || err.statusCode !== 401) { | ||
return Promise.reject(err); | ||
} | ||
return Promise.reject(err); | ||
|
||
const boomError = Boom.wrap(err, err.statusCode); | ||
const wwwAuthHeader = _.get(err, 'body.error.header[WWW-Authenticate]'); | ||
boomError.output.headers['WWW-Authenticate'] = wwwAuthHeader || 'Basic realm="Authorization Required"'; | ||
throw boomError; | ||
}); | ||
}; | ||
}; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import Boom from 'boom'; | ||
import expect from 'expect.js'; | ||
import _ from 'lodash'; | ||
import { handleShortUrlError } from '../short_url_error'; | ||
|
||
describe('handleShortUrlError()', () => { | ||
const caughtErrors = [{ | ||
status: 401 | ||
}, { | ||
status: 403 | ||
}, { | ||
status: 404 | ||
}]; | ||
|
||
const uncaughtErrors = [{ | ||
status: null | ||
}, { | ||
status: 500 | ||
}]; | ||
|
||
caughtErrors.forEach((err) => { | ||
it(`should handle ${err.status} errors`, function () { | ||
expect(_.get(handleShortUrlError(err), 'output.statusCode')).to.be(err.status); | ||
}); | ||
}); | ||
|
||
uncaughtErrors.forEach((err) => { | ||
it(`should not handle unknown errors`, function () { | ||
expect(_.get(handleShortUrlError(err), 'output.statusCode')).to.be(500); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import Boom from 'boom'; | ||
|
||
export function handleShortUrlError(err) { | ||
if (err.isBoom) return err; | ||
if (err.status === 401) return Boom.unauthorized(); | ||
if (err.status === 403) return Boom.forbidden(); | ||
if (err.status === 404) return Boom.notFound(); | ||
return Boom.badImplementation(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.