Skip to content

Entitle com.unboundid.ldap.listener as test package #130706

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

Merged
merged 3 commits into from
Jul 8, 2025

Conversation

mosche
Copy link
Contributor

@mosche mosche commented Jul 7, 2025

This removes inbound_network from x-pack core and instead configures com.unboundid.ldap.listener as test package for LDAP and related test cases that start an LDAP server listening for requests.

Relates to ES-12128

@mosche mosche requested a review from a team July 7, 2025 10:04
@mosche mosche added >non-issue :Core/Infra/Entitlements Entitlements infrastructure labels Jul 7, 2025
@elasticsearchmachine elasticsearchmachine added Team:Core/Infra Meta label for core/infra team v9.2.0 labels Jul 7, 2025
@elasticsearchmachine
Copy link
Collaborator

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

Copy link
Contributor

@prdoyle prdoyle left a comment

Choose a reason for hiding this comment

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

Did you consider simply adding com.unboundid.ldap.listener to the existing list?

}
return false;
idx = -idx - 2; // candidate package (insertion point - 1)
return idx >= 0 && idx < entitledTestPackages.length && packageName.startsWith(entitledTestPackages[idx]);
Copy link
Contributor

Choose a reason for hiding this comment

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

This could probably use a unit test, given the opportunity for off-by-one errors.

It inherits an existing bug where org.example.pack will be viewed as a prefix of org.example.package even though the two packages are unrelated. We somewhat got away with this before because it was a fixed set of packages known not to have this problem, but now that the API can add them dynamically, it becomes a possibility.

(We've overdue for writing a proper string prefix trie. 😅)

Also, I think our experience with FileAccessTree shows that this will fail for looking up org.example.foo if the array already contains org.example and org.example.bar. In this case, the binary search will land on org.example.bar which is not a prefix. In FileAccessTree we deal with this by removing entries that have a prefix already in the list.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @prdoyle! I've added respective tests and fixed the issues mentioned above. Forbidding adding redundant entries here, which I think is sufficient for the use case.

if (TestEntitlementBootstrap.isEnabledForTest()) {
TestEntitlementBootstrap.setActive(false == withoutEntitlements);
TestEntitlementBootstrap.setTriviallyAllowingTestCode(false == withEntitlementsOnTestCode);
if (entitledPackages != null) {
assert withEntitlementsOnTestCode == false : "Cannot use @WithEntitlementsOnTestCode together with @EntitledTestPackages";
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

these contradict each other

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm. Why is that? I can imagine a case where we want entitlements enforced on test code, but also want to grant certain test packages.

@prdoyle
Copy link
Contributor

prdoyle commented Jul 7, 2025

Also I think we're still backporting to 8.19?

@mosche
Copy link
Contributor Author

mosche commented Jul 7, 2025

Did you consider simply adding com.unboundid.ldap.listener to the existing list?

I did, but this (aka having to entitle more test packages) has come up multiple times now and in this case the required package is highly specific, so I'd rather extend the list of packages for specific tests only.

@mosche mosche added auto-backport Automatically create backport pull requests when merged v9.1.0 v8.19.1 labels Jul 7, 2025
}

private static boolean isNotPrefixMatch(String name, String prefix, boolean discardExactMatch) {
assert prefix.endsWith(".") == false : "Invalid package prefix ending with '.' [" + prefix + "]";
Copy link
Contributor

Choose a reason for hiding this comment

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

Some ideas:

Another approach might be to make the period at the end mandatory. Then a simple prefix match would work.

A third approach would be to add the period automatically to all prefixes. Again the simple prefix match would work.

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 thought about it. In either case, it shouldn't be lenient. So I either have to check the final dot is not there OR always require it to be there. Not much of a difference imho.

@prdoyle
Copy link
Contributor

prdoyle commented Jul 8, 2025

in this case the required package is highly specific, so I'd rather extend the list of packages for specific tests only.

That makes a lot of sense. I bet most of the packages in the existing list could be moved into this annotation instead, and the list would then just have truly universal packages.

@mosche mosche merged commit fda7e56 into elastic:main Jul 8, 2025
33 checks passed
@mosche
Copy link
Contributor Author

mosche commented Jul 8, 2025

Thx @prdoyle

@elasticsearchmachine
Copy link
Collaborator

💚 Backport successful

Status Branch Result
9.1
8.19

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 >non-issue Team:Core/Infra Meta label for core/infra team v8.19.1 v9.1.0 v9.2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants