Skip to content

[Entitlements] Test ScopeResolver based on TestBuildInfo (parser + resolver) #127719

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

ldematte
Copy link
Contributor

@ldematte ldematte commented May 5, 2025

This PR introduces a test-specific ScopeResolver to use with PolicyManager for checking entitlements within test code running in a test runner (unit tests and integ tests, where code is running withing the same JVM).
The information for resolving component and module names is derived from the file created in #127486

Some parts are still WIP (e.g. where to place the code that looks for all test-build-info files, or code to read server-specific test-build-info); these are clearly marked with a TODO and possibly will be dealt with in a follow-up PR.

@ldematte ldematte added >test Issues or PRs that are addressing/adding tests WIP :Core/Infra/Entitlements Entitlements infrastructure labels May 5, 2025
@ldematte ldematte changed the title [Entitlements] A ScopeResolver based on TestBuildInfo for tests (parser + resolver) [Entitlements] Test ScopeResolver based on TestBuildInfo (parser + resolver) May 6, 2025
@ldematte ldematte added auto-backport Automatically create backport pull requests when merged v8.19.0 v8.18.2 v9.0.2 labels May 6, 2025
@ldematte ldematte marked this pull request as ready for review May 6, 2025 12:24
Copy link
Contributor

@jdconrad jdconrad left a comment

Choose a reason for hiding this comment

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

LGTM! Just one question.

try {
scopeMap.put(
getCodeSource(codeSource, location.className()),
PolicyManager.PolicyScope.plugin(pluginBuildInfo.componentName(), location.moduleName())
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if there is no policy for this specific module? This will just end up with an empty policy?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Reading policies and parsing them will happen separately - I still have to do that. It will work like in production code, a policy can be missing and we just have the default.
Here it is about the resolver, mapping classes and locations to a scope.
But that's a good question on the build infos - what happens if there is no build info for a specific module or plugin? I assumed that build infos will be for all plugins and modules and server, and they will cover all modules; if we miss something, that will fall back to the "unknown" case - similar to what we do in prod code - and that will likely lead to a NotEntitledException.
I think this is correct, but if we feel that should never happen in tests maybe we should have an early assert?
I'm going to add additional logging, but let me know if we should add an assert too.

@ldematte
Copy link
Contributor Author

ldematte commented May 9, 2025

Note: this should be merged after #127486, in case the JSON file formats or locations are changed meanwhile.

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 >test Issues or PRs that are addressing/adding tests v8.18.2 v8.19.0 v9.0.2 v9.1.0 WIP
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants