Skip to content

Conversation

@ldematte
Copy link
Contributor

@ldematte ldematte commented Mar 8, 2025

Writing tests for #123861, turns out that #124195 is not enough.
We really need new IT test cases for "always allowed" actions: in order to be sure they are allowed, we need to setup the plugin with no policy.
This PR adds test cases for that, plus the support for writing test functions that accept one Environment parameter: many test paths we test and allow/deny are relative to paths in Environment, so it's useful to have access to it (see readAccessConfigDirectory as an example)

@ldematte ldematte added >test Issues or PRs that are addressing/adding tests auto-backport Automatically create backport pull requests when merged v8.18.1 v8.19.0 v9.0.1 v9.1.0 :Core/Infra/Entitlements Entitlements infrastructure labels Mar 8, 2025
@ldematte ldematte requested a review from a team as a code owner March 8, 2025 21:48
@elasticsearchmachine elasticsearchmachine added the Team:Core/Infra Meta label for core/infra team label Mar 8, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra (Team:Core/Infra)

return entries.stream();
}

private static CheckedConsumer<Environment, Exception> createConsumerForMethod(Method method) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is pretty neat. Your own tiny DI framework!

}
if (parameters.length == 1 && parameters[0].equals(Environment.class)) {
return env -> method.invoke(null, env);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

(If we ever acquire a second injectable parameter here, I'd probably change this to loop over the parameters, building the argument list based on the parameter types, much like a real DI framework would.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

++
But for now all the "extra" info we use is in the environment (e.g. dirs).
But yes, if we need to add more, we can either do that or have "fixed" patterns (either arg-less, or all the additional args in the right order).

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't really see the value in forcing the args to be in a certain order. Like, what if I want to inject A and C? Do I need to declare B for no reason just so I have the right args in the right order? Also, why is (A, C) ok but (C, A) is not?

It will not surprise you that I'd prefer just to have DI. 😂

@ldematte ldematte enabled auto-merge (squash) March 12, 2025 07:40
@ldematte ldematte merged commit 37a3630 into elastic:main Mar 12, 2025
17 checks passed
ldematte added a commit to ldematte/elasticsearch that referenced this pull request Mar 12, 2025
…ke 2) (elastic#124429)

Writing tests for elastic#123861, turns out that elastic#124195 is not enough.
We really need new IT test cases for "always allowed" actions: in order to be sure they are allowed, we need to setup the plugin with no policy.
This PR adds test cases for that, plus the support for writing test functions that accept one Environment parameter: many test paths we test and allow/deny are relative to paths in Environment, so it's useful to have access to it (see readAccessConfigDirectory as an example)
@elasticsearchmachine
Copy link
Collaborator

💔 Backport failed

Status Branch Result
8.18 Commit could not be cherrypicked due to conflicts
8.x Commit could not be cherrypicked due to conflicts
9.0

You can use sqren/backport to manually backport by running backport --upstream elastic/elasticsearch --pr 124429

elasticsearchmachine pushed a commit that referenced this pull request Mar 12, 2025
…ke 2) (#124429) (#124627)

Writing tests for #123861, turns out that #124195 is not enough.
We really need new IT test cases for "always allowed" actions: in order to be sure they are allowed, we need to setup the plugin with no policy.
This PR adds test cases for that, plus the support for writing test functions that accept one Environment parameter: many test paths we test and allow/deny are relative to paths in Environment, so it's useful to have access to it (see readAccessConfigDirectory as an example)
@ldematte ldematte deleted the entitlements/test-always-allowed-actions-2 branch March 13, 2025 08:50
ldematte added a commit to ldematte/elasticsearch that referenced this pull request Mar 13, 2025
…ke 2) (elastic#124429)

Writing tests for elastic#123861, turns out that elastic#124195 is not enough.
We really need new IT test cases for "always allowed" actions: in order to be sure they are allowed, we need to setup the plugin with no policy.
This PR adds test cases for that, plus the support for writing test functions that accept one Environment parameter: many test paths we test and allow/deny are relative to paths in Environment, so it's useful to have access to it (see readAccessConfigDirectory as an example)
ldematte added a commit to ldematte/elasticsearch that referenced this pull request Mar 13, 2025
…ke 2) (elastic#124429)

Writing tests for elastic#123861, turns out that elastic#124195 is not enough.
We really need new IT test cases for "always allowed" actions: in order to be sure they are allowed, we need to setup the plugin with no policy.
This PR adds test cases for that, plus the support for writing test functions that accept one Environment parameter: many test paths we test and allow/deny are relative to paths in Environment, so it's useful to have access to it (see readAccessConfigDirectory as an example)
elasticsearchmachine pushed a commit that referenced this pull request Mar 13, 2025
…ke 2) (#124429) (#124703)

Writing tests for #123861, turns out that #124195 is not enough.
We really need new IT test cases for "always allowed" actions: in order to be sure they are allowed, we need to setup the plugin with no policy.
This PR adds test cases for that, plus the support for writing test functions that accept one Environment parameter: many test paths we test and allow/deny are relative to paths in Environment, so it's useful to have access to it (see readAccessConfigDirectory as an example)
elasticsearchmachine pushed a commit that referenced this pull request Mar 13, 2025
…ke 2) (#124429) (#124704)

Writing tests for #123861, turns out that #124195 is not enough.
We really need new IT test cases for "always allowed" actions: in order to be sure they are allowed, we need to setup the plugin with no policy.
This PR adds test cases for that, plus the support for writing test functions that accept one Environment parameter: many test paths we test and allow/deny are relative to paths in Environment, so it's useful to have access to it (see readAccessConfigDirectory as an example)
albertzaharovits pushed a commit to albertzaharovits/elasticsearch that referenced this pull request Mar 13, 2025
…ke 2) (elastic#124429)

Writing tests for elastic#123861, turns out that elastic#124195 is not enough.
We really need new IT test cases for "always allowed" actions: in order to be sure they are allowed, we need to setup the plugin with no policy.
This PR adds test cases for that, plus the support for writing test functions that accept one Environment parameter: many test paths we test and allow/deny are relative to paths in Environment, so it's useful to have access to it (see readAccessConfigDirectory as an example)
jfreden pushed a commit to jfreden/elasticsearch that referenced this pull request Mar 13, 2025
…ke 2) (elastic#124429)

Writing tests for elastic#123861, turns out that elastic#124195 is not enough.
We really need new IT test cases for "always allowed" actions: in order to be sure they are allowed, we need to setup the plugin with no policy.
This PR adds test cases for that, plus the support for writing test functions that accept one Environment parameter: many test paths we test and allow/deny are relative to paths in Environment, so it's useful to have access to it (see readAccessConfigDirectory as an example)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

auto-backport Automatically create backport pull requests when merged :Core/Infra/Entitlements Entitlements infrastructure Team:Core/Infra Meta label for core/infra team >test Issues or PRs that are addressing/adding tests v8.18.1 v8.19.0 v9.0.1 v9.1.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants