Skip to content

Commit 6f2fd73

Browse files
authored
Fix NPE. (#3593)
1 parent 9a1f926 commit 6f2fd73

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

src/main/java/org/prebid/server/hooks/execution/HookStageExecutor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,7 @@ private Timeout createTimeout(Long timeout) {
500500
}
501501

502502
private static ObjectNode accountConfigFor(Account account, HookId hookId) {
503-
final AccountHooksConfiguration accountHooksConfiguration = account.getHooks();
503+
final AccountHooksConfiguration accountHooksConfiguration = account != null ? account.getHooks() : null;
504504
final Map<String, ObjectNode> modulesConfiguration =
505505
accountHooksConfiguration != null ? accountHooksConfiguration.getModules() : Collections.emptyMap();
506506

src/test/java/org/prebid/server/hooks/execution/HookStageExecutorTest.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2903,6 +2903,48 @@ null, singletonMap("module-alpha", mapper.createObjectNode()), null))
29032903
}));
29042904
}
29052905

2906+
@Test
2907+
public void shouldExecuteAuctionResponseHooksAndTolerateNullAccount(VertxTestContext context) {
2908+
// given
2909+
final AuctionResponseHookImpl hookImpl = spy(
2910+
AuctionResponseHookImpl.of(immediateHook(InvocationResultUtils.succeeded(identity()))));
2911+
given(hookCatalog.hookById(eqHook("module-alpha", "hook-a"), eq(StageWithHookType.AUCTION_RESPONSE)))
2912+
.willReturn(hookImpl);
2913+
2914+
final HookStageExecutor executor = createExecutor(
2915+
executionPlan(singletonMap(
2916+
Endpoint.openrtb2_auction,
2917+
EndpointExecutionPlan.of(singletonMap(
2918+
Stage.auction_response, execPlanOneGroupOneHook("module-alpha", "hook-a"))))));
2919+
2920+
final HookExecutionContext hookExecutionContext = HookExecutionContext.of(Endpoint.openrtb2_auction);
2921+
2922+
// when
2923+
final Future<HookStageExecutionResult<AuctionResponsePayload>> future = executor.executeAuctionResponseStage(
2924+
BidResponse.builder().build(),
2925+
AuctionContext.builder()
2926+
.bidRequest(BidRequest.builder().build())
2927+
.account(null)
2928+
.hookExecutionContext(hookExecutionContext)
2929+
.debugContext(DebugContext.empty())
2930+
.build());
2931+
2932+
// then
2933+
future.onComplete(context.succeeding(result -> {
2934+
final ArgumentCaptor<AuctionInvocationContext> invocationContextCaptor =
2935+
ArgumentCaptor.forClass(AuctionInvocationContext.class);
2936+
verify(hookImpl).call(any(), invocationContextCaptor.capture());
2937+
2938+
assertThat(invocationContextCaptor.getValue()).satisfies(invocationContext -> {
2939+
assertThat(invocationContext.endpoint()).isNotNull();
2940+
assertThat(invocationContext.timeout()).isNotNull();
2941+
assertThat(invocationContext.accountConfig()).isNull();
2942+
});
2943+
2944+
context.completeNow();
2945+
}));
2946+
}
2947+
29062948
@Test
29072949
public void shouldExecuteAuctionResponseHooksAndIgnoreRejection(VertxTestContext context) {
29082950
// given

0 commit comments

Comments
 (0)