-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Performance Test service and config refactor (#128258)
* add build id, job id and execution id to playwright config * change apm configs (serverUrl, secretToken) * refactor single user journeys to break "test" concept around them * Authentication service and Login Journey * move test steps to runUserJourney as argument Co-authored-by: Kibana Machine <[email protected]>
- Loading branch information
1 parent
67ef4f7
commit cbf0cea
Showing
11 changed files
with
423 additions
and
293 deletions.
There are no files selected for viewing
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,62 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import axios, { AxiosResponse } from 'axios'; | ||
import Url from 'url'; | ||
import { FtrService, FtrProviderContext } from '../ftr_provider_context'; | ||
|
||
export interface Credentials { | ||
username: string; | ||
password: string; | ||
} | ||
|
||
function extractCookieValue(authResponse: AxiosResponse) { | ||
return authResponse.headers['set-cookie'][0].toString().split(';')[0].split('sid=')[1] as string; | ||
} | ||
export class AuthService extends FtrService { | ||
private readonly kibanaServer = this.ctx.getService('kibanaServer'); | ||
private readonly config = this.ctx.getService('config'); | ||
|
||
constructor(ctx: FtrProviderContext) { | ||
super(ctx); | ||
} | ||
|
||
public async login({ username, password }: Credentials) { | ||
const headers = { | ||
'content-type': 'application/json', | ||
'kbn-version': await this.kibanaServer.version.get(), | ||
'sec-fetch-mode': 'cors', | ||
'sec-fetch-site': 'same-origin', | ||
}; | ||
|
||
const baseUrl = Url.format({ | ||
protocol: this.config.get('servers.kibana.protocol'), | ||
hostname: this.config.get('servers.kibana.hostname'), | ||
port: this.config.get('servers.kibana.port'), | ||
}); | ||
|
||
const loginUrl = baseUrl + '/internal/security/login'; | ||
const provider = baseUrl.includes('localhost') ? 'basic' : 'cloud-basic'; | ||
|
||
const authBody = { | ||
providerType: 'basic', | ||
providerName: provider, | ||
currentURL: `${baseUrl}/login?next=%2F`, | ||
params: { username, password }, | ||
}; | ||
|
||
const authResponse = await axios.post(loginUrl, authBody, { headers }); | ||
|
||
return { | ||
name: 'sid', | ||
value: extractCookieValue(authResponse), | ||
url: baseUrl, | ||
}; | ||
} | ||
} | ||
|
||
export const AuthProvider = (ctx: FtrProviderContext) => new AuthService(ctx); |
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
Oops, something went wrong.