Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes session idle timeout API test #153303

Merged

Conversation

jeramysoucy
Copy link
Contributor

@jeramysoucy jeramysoucy commented Mar 20, 2023

Closes #152260
Closes #121482
Closes #136688

Description

  • Adds security index refresh to getSessionInfo to ensure each query is running on updated data
  • Triggers the cleanup routine just before checking idle session timeouts to increase determinism (same methodology used in concurrent sessions tests)
  • Adds a short static delay when testing session extend to ensure the original session time has somewhat elapsed (when this was failing it was only by a few milliseconds)

Tests

x-pack/test/security_api_integration/session_idle.config.ts...

  • 'should properly clean up session expired because of idle timeout'
  • 'should properly clean up session expired because of idle timeout when providers override global session config'
  • 'should extend the session'

Flaky Test Runner

https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/2031

@jeramysoucy jeramysoucy marked this pull request as ready for review March 20, 2023 20:33
@jeramysoucy jeramysoucy requested a review from a team as a code owner March 20, 2023 20:33
@jeramysoucy jeramysoucy added v8.8.0 Team:Security Team focused on: Auth, Users, Roles, Spaces, Audit Logging, and more! labels Mar 20, 2023
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-security (Team:Security)

@jeramysoucy jeramysoucy added test-failure-flaky release_note:skip Skip the PR/issue when compiling release notes labels Mar 20, 2023
@azasypkin
Copy link
Member

ACK: will review later today or tomorrow!

@azasypkin azasypkin self-requested a review March 22, 2023 10:35
Copy link
Member

@azasypkin azasypkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, just left a few questions, thanks!

@@ -32,6 +33,7 @@ export default function ({ getService }: FtrProviderContext) {
provider: AuthenticationProvider
) {
log.debug(`Verifying session cookie for ${username}.`);
await es.indices.refresh({ index: '.kibana_security_session*' });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: If I understand correctly the refresh doesn't affect the /internal/security/me call that goes after it, since it retrieves session by ID. Shouldn't we instead call the refresh inside runCleanupTaskSoon, where we need to make sure that the search operation that cleanup does relies on the latest data?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. I don't think we even need it in runCleanupTaskSoon though either because we have such long wait times anyhow. We're on the second iteration of the cleanup task by the time the session expires.

@@ -93,6 +99,7 @@ export default function ({ getService }: FtrProviderContext) {
it('should extend the session', async () => {
// browsers will follow the redirect and return the new session info, but this testing framework does not
// we simulate that behavior in this test by sending another GET request
await setTimeoutAsync(200); // wait a bit
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: maybe it'd make more sense to have this delay right before we try to extend session and add a comment in the code to explain why we have it (what you mentioned in the issue description does a great job explaining why we need this delay).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! We will have to move the first getSessionInfo call with it, otherwise we'll end up with the same issue as before. But I agree, bringing this all to one block with a better comment is a great idea.

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Unknown metric groups

ESLint disabled line counts

id before after diff
securitySolution 433 436 +3

Total ESLint disabled count

id before after diff
securitySolution 513 516 +3

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@jeramysoucy
Copy link
Contributor Author

@azasypkin Thanks for the suggestions! I've made some updates and re-ran the flaky test runner (see link in desc). All looks good if you are ready to approve.

@jeramysoucy jeramysoucy requested a review from azasypkin March 23, 2023 18:56
Copy link
Member

@azasypkin azasypkin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thank you!

@jeramysoucy jeramysoucy merged commit fb67e5a into elastic:main Mar 23, 2023
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Mar 23, 2023
jennypavlova pushed a commit to jennypavlova/kibana that referenced this pull request Mar 24, 2023
Closes elastic#152260
Closes elastic#121482
Closes elastic#136688

## Description
- Adds security index refresh to `getSessionInfo` to ensure each query
is running on updated data
- Triggers the cleanup routine just before checking idle session
timeouts to increase determinism (same methodology used in concurrent
sessions tests)
- Adds a short static delay when testing session extend to ensure the
original session time has somewhat elapsed (when this was failing it was
only by a few milliseconds)

### Tests
x-pack/test/security_api_integration/session_idle.config.ts...
- 'should properly clean up session expired because of idle timeout'
- 'should properly clean up session expired because of idle timeout when
providers override global session config'
- 'should extend the session'

### Flaky Test Runner
https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/2031
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment