Skip to content

Commit

Permalink
Switch Kerberos authentication provider to a dedicated _kerberos gr…
Browse files Browse the repository at this point in the history
…ant. Introduce `Tokens` for common access/refresh token tasks.
  • Loading branch information
azasypkin committed Jun 21, 2019
1 parent 2f029e6 commit 5fdd55b
Show file tree
Hide file tree
Showing 16 changed files with 925 additions and 859 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { DeauthenticationResult } from './deauthentication_result';
import { Session } from './session';
import { LoginAttempt } from './login_attempt';
import { AuthenticationProviderSpecificOptions } from './providers/base';
import { Tokens } from './tokens';

interface ProviderSession {
provider: string;
Expand Down Expand Up @@ -56,11 +57,14 @@ function assertRequest(request: Legacy.Request) {
*/
function getProviderOptions(server: Legacy.Server) {
const config = server.config();
const client = getClient(server);
const log = server.log.bind(server);

return {
client: getClient(server),
log: server.log.bind(server),
client,
log,
basePath: config.get<string>('server.basePath'),
tokens: new Tokens({ client, log }),
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,21 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { stub } from 'sinon';
import { stub, createStubInstance } from 'sinon';
import { Tokens } from '../tokens';
import { AuthenticationProviderOptions } from './base';

export function mockAuthenticationProviderOptions(
providerOptions: Partial<AuthenticationProviderOptions> = {}
providerOptions: Partial<Pick<AuthenticationProviderOptions, 'basePath'>> = {}
) {
const client = { callWithRequest: stub(), callWithInternalUser: stub() };
const log = stub();

return {
client: { callWithRequest: stub(), callWithInternalUser: stub() },
log: stub(),
client,
log,
basePath: '/base-path',
tokens: createStubInstance(Tokens),
...providerOptions,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Legacy } from 'kibana';
import { AuthenticationResult } from '../authentication_result';
import { DeauthenticationResult } from '../deauthentication_result';
import { LoginAttempt } from '../login_attempt';
import { Tokens } from '../tokens';

/**
* Describes a request complemented with `loginAttempt` method.
Expand All @@ -23,6 +24,7 @@ export interface AuthenticationProviderOptions {
basePath: string;
client: Legacy.Plugins.elasticsearch.Cluster;
log: (tags: string[], message: string) => void;
tokens: PublicMethodsOf<Tokens>;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('BasicAuthenticationProvider', () => {
let callWithRequest: sinon.SinonStub;
beforeEach(() => {
const providerOptions = mockAuthenticationProviderOptions();
callWithRequest = providerOptions.client.callWithRequest as sinon.SinonStub;
callWithRequest = providerOptions.client.callWithRequest;
provider = new BasicAuthenticationProvider(providerOptions);
});

Expand Down
Loading

0 comments on commit 5fdd55b

Please sign in to comment.