Skip to content

Commit

Permalink
Fix NPE. (prebid#3593)
Browse files Browse the repository at this point in the history
  • Loading branch information
CTMBNara authored and sergseven committed Dec 23, 2024
1 parent 9d560dc commit d1ecc15
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ private Timeout createTimeout(Long timeout) {
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2903,6 +2903,48 @@ null, singletonMap("module-alpha", mapper.createObjectNode()), null))
}));
}

@Test
public void shouldExecuteAuctionResponseHooksAndTolerateNullAccount(VertxTestContext context) {
// given
final AuctionResponseHookImpl hookImpl = spy(
AuctionResponseHookImpl.of(immediateHook(InvocationResultUtils.succeeded(identity()))));
given(hookCatalog.hookById(eqHook("module-alpha", "hook-a"), eq(StageWithHookType.AUCTION_RESPONSE)))
.willReturn(hookImpl);

final HookStageExecutor executor = createExecutor(
executionPlan(singletonMap(
Endpoint.openrtb2_auction,
EndpointExecutionPlan.of(singletonMap(
Stage.auction_response, execPlanOneGroupOneHook("module-alpha", "hook-a"))))));

final HookExecutionContext hookExecutionContext = HookExecutionContext.of(Endpoint.openrtb2_auction);

// when
final Future<HookStageExecutionResult<AuctionResponsePayload>> future = executor.executeAuctionResponseStage(
BidResponse.builder().build(),
AuctionContext.builder()
.bidRequest(BidRequest.builder().build())
.account(null)
.hookExecutionContext(hookExecutionContext)
.debugContext(DebugContext.empty())
.build());

// then
future.onComplete(context.succeeding(result -> {
final ArgumentCaptor<AuctionInvocationContext> invocationContextCaptor =
ArgumentCaptor.forClass(AuctionInvocationContext.class);
verify(hookImpl).call(any(), invocationContextCaptor.capture());

assertThat(invocationContextCaptor.getValue()).satisfies(invocationContext -> {
assertThat(invocationContext.endpoint()).isNotNull();
assertThat(invocationContext.timeout()).isNotNull();
assertThat(invocationContext.accountConfig()).isNull();
});

context.completeNow();
}));
}

@Test
public void shouldExecuteAuctionResponseHooksAndIgnoreRejection(VertxTestContext context) {
// given
Expand Down

0 comments on commit d1ecc15

Please sign in to comment.