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

[SECURITY] Remove flakiness around edit user #117558

Merged
merged 13 commits into from
Nov 8, 2021

Conversation

XavierM
Copy link
Contributor

@XavierM XavierM commented Nov 4, 2021

Summary

Resolves: #115473

Checklist

@XavierM XavierM added chore Team:Security Team focused on: Auth, Users, Roles, Spaces, Audit Logging, and more! v8.0.0 v7.16.0 v8.1.0 labels Nov 4, 2021
@XavierM
Copy link
Contributor Author

XavierM commented Nov 4, 2021

@XavierM
Copy link
Contributor Author

XavierM commented Nov 4, 2021

@elasticmachine merge upstream

@XavierM XavierM marked this pull request as ready for review November 4, 2021 20:29
@XavierM XavierM requested a review from a team as a code owner November 4, 2021 20:29
@elasticmachine
Copy link
Contributor

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

@jportner jportner self-requested a review November 4, 2021 20:42
@jportner jportner added the release_note:skip Skip the PR/issue when compiling release notes label Nov 4, 2021
Copy link
Contributor

@jportner jportner left a comment

Choose a reason for hiding this comment

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

Some small nits and a question below, otherwise this is looking great, really nice job!

x-pack/test/functional/apps/security/users.ts Outdated Show resolved Hide resolved
x-pack/test/functional/apps/security/users.ts Outdated Show resolved Hide resolved
Comment on lines 172 to 173
username: 'test_user',
password: 'changeme',
Copy link
Contributor

Choose a reason for hiding this comment

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

I did some digging to see exactly where this user's credentials are defined. It's here:

const TEST_USER_NAME = 'test_user';
const TEST_USER_PASSWORD = 'changeme';

Docs: https://www.elastic.co/guide/en/kibana/8.0/development-tests.html#_using_the_test_user_service

However, we have a different adminTestUser that is used in our security API integration tests:

These are defined by the @kbn/test package, they can apparently be changed with environment variables and may be different for Cloud testing:

const env = process.env;
export const kibanaTestUser = {
username: env.TEST_KIBANA_USER || 'elastic',
password: env.TEST_KIBANA_PASS || 'changeme',
};
export const kibanaServerTestUser = {
username: env.TEST_KIBANA_SERVER_USER || 'kibana',
password: env.TEST_KIBANA_SERVER_PASS || 'changeme',
};
export const adminTestUser = {
username: env.TEST_ES_USER || 'elastic',
password: env.TEST_ES_PASS || 'changeme',
};


All that said, using the hardcoded test_user / changeme in this file makes me a bit nervous because 1. I'm not sure if the tests will always be executed with the user defined in test_user.ts, and 2. even so, if that user changes, then this test will fail.

So, maybe we should just export the test username/password from that file so it can be used here, and just call it a day. But I want to know what @azasypkin thinks, in case I'm missing anything else RE: Cloud testing.

Copy link
Member

@azasypkin azasypkin Nov 5, 2021

Choose a reason for hiding this comment

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

All that said, using the hardcoded test_user / changeme in this file makes me a bit nervous

Yeah, I share the same concern, but mostly because I treat service test users as immutable to avoid any side effects for the following tests. Is there any reason why we cannot do something like this (semi pseudo-code)?

const user = {
  username: 'throw-away-user',
  password: 'changeme',
  new_password: 'changeme',
  confirm_password: 'changeme',
  roles: ['kibana_admin'],
};

// The API integration tests service to create through API, not UI
await security.user.create(user.username, {
  password: user.password,
  roles: user.roles,
  full_name: 'Admin',
});

// Re-login (should be pretty stable)
await PageObjects.security.forceLogout();
// OR `PageObjects.security.login` that's even simpler to use
await PageObjects.security.loginSelector.login('basic', 'basic', { 
  username: user.username, password: user.password
});

await PageObjects.security.updateUserPassword(user, true);

// Make sure new password works.
await PageObjects.security.forceLogout();
await PageObjects.security.loginSelector.login('basic', 'basic', { 
  username: user.username, password: user.new_password
});

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was just trying to be lazy here :) since I was not changing the password, but if everyone is concerned about it, I will just login using optionalUser. Not a problem

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah my main concern is that we might break Cloud tests. If we do that, we don't find out until after the fact, and it's just a whole thing. Safer to do what Oleg suggested.

Copy link
Contributor Author

@XavierM XavierM Nov 5, 2021

Choose a reason for hiding this comment

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

Also I am not going to test if the new password works, I am assuming that we should have API integration for that. What I want to test here that when I am logging as a current user and I am changing my password, and I will have a text field asking for my current password and then I can change my password. We do not want to do too much in one test.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed, that makes sense to me

Copy link
Member

Choose a reason for hiding this comment

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

What I want to test here that when I am logging as a current user and I am changing my password, and I will have a text field asking for my current password and then I can change my password. We do not want to do too much in one test.

Sounds good to me as well. Would you mind keeping this comment in the test as well? It'd help future readers to understand what we want to test exactly here.

@XavierM
Copy link
Contributor Author

XavierM commented Nov 5, 2021

Since I changed some of the functional test, I am re-running flaky suite test
https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/171#493c935d-a88a-4815-8bce-6c4e4d246423

We are good here 🟢

@XavierM XavierM requested review from jportner and azasypkin November 5, 2021 17:23
@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
security 487.1KB 487.3KB +194.0B

History

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

@XavierM XavierM merged commit 923df65 into elastic:main Nov 8, 2021
@XavierM XavierM added the auto-backport Deprecated - use backport:version if exact versions are needed label Nov 8, 2021
kibanamachine added a commit to kibanamachine/kibana that referenced this pull request Nov 8, 2021
* wip

* convert flaky jest test to functional test

* improvement from review

* fix

* fix i18n

Co-authored-by: Kibana Machine <[email protected]>
@kibanamachine
Copy link
Contributor

💔 Backport failed

Status Branch Result
8.0
7.16 Commit could not be cherrypicked due to conflicts

Successful backport PRs will be merged automatically after passing CI.

To backport manually run:
node scripts/backport --pr 117558

kibanamachine added a commit that referenced this pull request Nov 8, 2021
* wip

* convert flaky jest test to functional test

* improvement from review

* fix

* fix i18n

Co-authored-by: Kibana Machine <[email protected]>

Co-authored-by: Xavier Mouligneau <[email protected]>
XavierM added a commit to XavierM/kibana that referenced this pull request Nov 11, 2021
* wip

* convert flaky jest test to functional test

* improvement from review

* fix

* fix i18n

Co-authored-by: Kibana Machine <[email protected]>
XavierM added a commit that referenced this pull request Nov 12, 2021
* [SECURITY] Remove flakiness around edit user (#117558)

* wip

* convert flaky jest test to functional test

* improvement from review

* fix

* fix i18n

Co-authored-by: Kibana Machine <[email protected]>

* wrong file type

* fix merged

Co-authored-by: Kibana Machine <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Deprecated - use backport:version if exact versions are needed chore release_note:skip Skip the PR/issue when compiling release notes Team:Security Team focused on: Auth, Users, Roles, Spaces, Audit Logging, and more! v7.16.0 v8.0.0 v8.1.0
Projects
None yet
5 participants