Skip to content

Commit

Permalink
Fixing mocha tests and broken password change status codes
Browse files Browse the repository at this point in the history
  • Loading branch information
kobelb committed Nov 14, 2019
1 parent 2516f94 commit edade4f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('Authentication routes', () => {

initAuthenticateApi({
authc: { login: loginStub, logout: logoutStub },
config: { authc: { providers: ['basic'] } },
__legacyCompat: { config: { authc: { providers: ['basic'] } } },
}, serverStub);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('User routes', () => {
clusterStub = sinon.stub({ callWithRequest() {} });
sandbox.stub(ClientShield, 'getClient').returns(clusterStub);

initUsersApi({ authc: { login: loginStub }, config: { authc: { providers: ['basic'] } } }, serverStub);
initUsersApi({ authc: { login: loginStub }, __legacyCompat: { config: { authc: { providers: ['basic'] } } } }, serverStub);
});

afterEach(() => sandbox.restore());
Expand Down Expand Up @@ -90,7 +90,7 @@ describe('User routes', () => {
expect(response.isBoom).to.be(true);
expect(response.output.payload).to.eql({
statusCode: 403,
error: 'Unauthorized',
error: 'Forbidden',
message: 'Something went wrong.'
});
});
Expand Down
20 changes: 8 additions & 12 deletions x-pack/legacy/plugins/security/server/routes/api/v1/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,15 @@ export function initUsersApi({ authc: { login }, __legacyCompat: { config } }, s
// If user tries to change own password, let's check if old password is valid first by trying
// to login.
if (isCurrentUser) {
try {
const authenticationResult = await login(KibanaRequest.from(request), {
provider: providerToLoginWith,
value: { username, password },
// We shouldn't alter authentication state just yet.
stateless: true,
});
const authenticationResult = await login(KibanaRequest.from(request), {
provider: providerToLoginWith,
value: { username, password },
// We shouldn't alter authentication state just yet.
stateless: true,
});

if (!authenticationResult.succeeded()) {
return Boom.unauthorized(authenticationResult.error);
}
} catch(err) {
throw Boom.forbidden(err);
if (!authenticationResult.succeeded()) {
return Boom.forbidden(authenticationResult.error);
}
}

Expand Down

0 comments on commit edade4f

Please sign in to comment.