-
Notifications
You must be signed in to change notification settings - Fork 24.6k
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
Watcher: Store username on watch execution #31873
Merged
Merged
Changes from 5 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
a5874e0
Watcher: Store username on watch execution
hub-cap 45ad8b7
Update executed_by to user
hub-cap 560111e
Merge remote-tracking branch 'upstream/master' into store_username
hub-cap db6d207
Move method and create test for the context
hub-cap 0edc33e
Merge remote-tracking branch 'upstream/master' into store_username
hub-cap c2c49d8
Merge remote-tracking branch 'upstream/master' into store_username
hub-cap dcd734d
Cleanup test
hub-cap 5a467d0
Fix docs test
hub-cap a1ea27d
Cleanup wording
hub-cap b49b2b5
Merge remote-tracking branch 'upstream/master' into store_username
hub-cap d54bcbe
Merge remote-tracking branch 'upstream/master' into store_username
hub-cap 0dc862f
Move username
hub-cap cf3d82e
Merge remote-tracking branch 'upstream/master' into store_username
hub-cap File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,9 @@ | |
import org.elasticsearch.index.get.GetResult; | ||
import org.elasticsearch.test.ESTestCase; | ||
import org.elasticsearch.threadpool.ThreadPool; | ||
import org.elasticsearch.xpack.core.security.authc.Authentication; | ||
import org.elasticsearch.xpack.core.security.authc.AuthenticationField; | ||
import org.elasticsearch.xpack.core.security.user.User; | ||
import org.elasticsearch.xpack.core.watcher.actions.Action; | ||
import org.elasticsearch.xpack.core.watcher.actions.ActionStatus; | ||
import org.elasticsearch.xpack.core.watcher.actions.ActionWrapper; | ||
|
@@ -76,6 +79,7 @@ | |
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
@@ -85,6 +89,7 @@ | |
import static java.util.Arrays.asList; | ||
import static java.util.Collections.singletonMap; | ||
import static org.elasticsearch.common.unit.TimeValue.timeValueSeconds; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.greaterThan; | ||
import static org.hamcrest.Matchers.hasSize; | ||
import static org.hamcrest.Matchers.instanceOf; | ||
|
@@ -1072,6 +1077,36 @@ public void testManualWatchExecutionContextGetsAlwaysExecuted() throws Exception | |
assertThat(watchRecord.state(), is(ExecutionState.EXECUTED)); | ||
} | ||
|
||
public void testLoadingWatchExecutionUser() throws Exception { | ||
DateTime now = now(UTC); | ||
Watch watch = mock(Watch.class); | ||
WatchStatus status = mock(WatchStatus.class); | ||
ScheduleTriggerEvent event = new ScheduleTriggerEvent("_id", now, now); | ||
Authentication authentication = new Authentication(new User("joe", "admin"), | ||
new Authentication.RealmRef("native_realm", "native", "node1"), null); | ||
String encoded = authentication.encode(); | ||
|
||
// Should be null | ||
TriggeredExecutionContext context = new TriggeredExecutionContext(watch.id(), now, event, timeValueSeconds(5)); | ||
context.ensureWatchExists(() -> watch); | ||
assertNull(context.getUser()); | ||
|
||
// Should still be null, header is not yet set | ||
when(watch.status()).thenReturn(status); | ||
context = new TriggeredExecutionContext(watch.id(), now, event, timeValueSeconds(5)); | ||
context.ensureWatchExists(() -> watch); | ||
assertNull(context.getUser()); | ||
|
||
Map<String, String> headers = new HashMap<>(); | ||
headers.put(AuthenticationField.AUTHENTICATION_KEY, encoded); | ||
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. you can use |
||
|
||
// Should no longer be null now that the proper header is set | ||
when(status.getHeaders()).thenReturn(headers); | ||
context = new TriggeredExecutionContext(watch.id(), now, event, timeValueSeconds(5)); | ||
context.ensureWatchExists(() -> watch); | ||
assertThat(context.getUser(), equalTo("joe")); | ||
} | ||
|
||
private WatchExecutionContext createMockWatchExecutionContext(String watchId, DateTime executionTime) { | ||
WatchExecutionContext ctx = mock(WatchExecutionContext.class); | ||
when(ctx.id()).thenReturn(new Wid(watchId, executionTime)); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
can you maybe move this up to where the node id gets written out? This way, one can see both at once when reading a watch history, otherwise one is at the top and the other at the bottom.
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.
Missed, will do this in another PR.
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.
oh nm, i can do it on this one! I thought i had merged already woop woop
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.
@spinscale can you eyeball 0dc862f just so im sure i did what u asked?