-
Notifications
You must be signed in to change notification settings - Fork 25.6k
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -517,16 +517,30 @@ protected void afterIfSuccessful() throws Exception {} | |
| public @interface WithEntitlementsOnTestCode { | ||
| } | ||
|
|
||
| @Retention(RetentionPolicy.RUNTIME) | ||
| @Target(ElementType.TYPE) | ||
| @Inherited | ||
| public @interface EntitledTestPackages { | ||
| String[] value(); | ||
| } | ||
|
|
||
| @BeforeClass | ||
| public static void setupEntitlementsForClass() { | ||
| boolean withoutEntitlements = getTestClass().isAnnotationPresent(WithoutEntitlements.class); | ||
| boolean withEntitlementsOnTestCode = getTestClass().isAnnotationPresent(WithEntitlementsOnTestCode.class); | ||
| EntitledTestPackages entitledPackages = getTestClass().getAnnotation(EntitledTestPackages.class); | ||
|
|
||
| if (TestEntitlementBootstrap.isEnabledForTest()) { | ||
| TestEntitlementBootstrap.setActive(false == withoutEntitlements); | ||
| TestEntitlementBootstrap.setTriviallyAllowingTestCode(false == withEntitlementsOnTestCode); | ||
| if (entitledPackages != null) { | ||
| assert withEntitlementsOnTestCode == false : "Cannot use @WithEntitlementsOnTestCode together with @EntitledTestPackages"; | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these contradict each other There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| assert entitledPackages.value().length > 0 : "No test packages specified in @EntitledTestPackages"; | ||
| TestEntitlementBootstrap.addEntitledTestPackages(entitledPackages.value()); | ||
| } | ||
| } else if (withEntitlementsOnTestCode) { | ||
| throw new AssertionError( | ||
| "Cannot use WithEntitlementsOnTestCode on tests that are not configured to use entitlements for testing" | ||
| "Cannot use @WithEntitlementsOnTestCode on tests that are not configured to use entitlements for testing" | ||
| ); | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
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.packwill be viewed as a prefix oforg.example.packageeven 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
FileAccessTreeshows that this will fail for looking uporg.example.fooif the array already containsorg.exampleandorg.example.bar. In this case, the binary search will land onorg.example.barwhich is not a prefix. InFileAccessTreewe deal with this by removing entries that have a prefix already in the list.There was a problem hiding this comment.
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.