Skip to content

Commit

Permalink
Rubicon: fix NPE caused by null deal bid price (#1395)
Browse files Browse the repository at this point in the history
  • Loading branch information
And1sS authored and nickluck8 committed Aug 10, 2021
1 parent 3fce093 commit b8e6c4b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1289,7 +1289,6 @@ private List<BidderBid> bidsFromResponse(BidRequest prebidRequest,
.filter(Objects::nonNull)
.flatMap(Collection::stream)
.map(bid -> updateBid(bid, idToImp.get(bid.getImpid()), cpmOverrideFromRequest, bidResponse))
.filter(RubiconBidder::validatePrice)
.map(bid -> BidderBid.of(bid, bidType, bidResponse.getCur()))
.collect(Collectors.toList());
}
Expand Down Expand Up @@ -1341,11 +1340,6 @@ private ExtPrebid<ExtBidPrebid, ObjectNode> getExtPrebid(ObjectNode bidExt, Stri
}
}

private static boolean validatePrice(Bid bid) {
final BigDecimal price = bid.getPrice();
return bid.getDealid() != null ? price.compareTo(BigDecimal.ZERO) >= 0 : price.compareTo(BigDecimal.ZERO) > 0;
}

private Bid updateBid(Bid bid, Imp imp, Float cpmOverrideFromRequest, RubiconBidResponse bidResponse) {
String bidId = bid.getId();
if (generateBidId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@

import static java.math.BigDecimal.ONE;
import static java.math.BigDecimal.TEN;
import static java.math.BigDecimal.ZERO;
import static java.util.Arrays.asList;
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
Expand Down Expand Up @@ -2803,48 +2802,6 @@ public void makeBidsShouldNotReduceBidderAmountForBidsWithSameImpId() throws Jso
.containsExactlyInAnyOrder("firstBidId", "secondBidId");
}

@Test
public void makeBidsShouldNotReturnImpIfNonDealBidPriceLessThanZero() throws JsonProcessingException {
// given
final HttpCall<BidRequest> httpCall = givenHttpCall(givenBidRequest(identity()),
givenBidResponse(BigDecimal.valueOf(-1)));

// when
final Result<List<BidderBid>> result = rubiconBidder.makeBids(httpCall, givenBidRequest(identity()));

// then
assertThat(result.getErrors()).isEmpty();
assertThat(result.getValue()).isEmpty();
}

@Test
public void makeBidsShouldNotReturnImpIfNonDealBidPriceEqualToZero() throws JsonProcessingException {
// given
final HttpCall<BidRequest> httpCall = givenHttpCall(givenBidRequest(identity()),
givenBidResponse(ZERO));

// when
final Result<List<BidderBid>> result = rubiconBidder.makeBids(httpCall, givenBidRequest(identity()));

// then
assertThat(result.getErrors()).isEmpty();
assertThat(result.getValue()).isEmpty();
}

@Test
public void makeBidsShouldNotReturnImpIfDealBidPriceLessThanZero() throws JsonProcessingException {
// given
final HttpCall<BidRequest> httpCall = givenHttpCall(givenBidRequest(identity()),
givenBidResponse(BigDecimal.valueOf(-1)));

// when
final Result<List<BidderBid>> result = rubiconBidder.makeBids(httpCall, givenBidRequest(identity()));

// then
assertThat(result.getErrors()).isEmpty();
assertThat(result.getValue()).isEmpty();
}

@Test
public void makeBidsShouldReturnBidWithOverriddenCpmFromRequest() throws JsonProcessingException {
// given
Expand Down Expand Up @@ -3069,7 +3026,7 @@ private static BidRequest givenBidRequest(Function<BidRequestBuilder, BidRequest
Function<ImpBuilder, ImpBuilder> impCustomizer,
Function<ExtImpRubiconBuilder, ExtImpRubiconBuilder> extCustomizer) {
return bidRequestCustomizer.apply(BidRequest.builder()
.imp(singletonList(givenImp(impCustomizer, extCustomizer))))
.imp(singletonList(givenImp(impCustomizer, extCustomizer))))
.build();
}

Expand All @@ -3085,7 +3042,8 @@ private static BidRequest givenBidRequest(Function<ImpBuilder, ImpBuilder> impCu
private static Imp givenImp(Function<ImpBuilder, ImpBuilder> impCustomizer,
Function<ExtImpRubiconBuilder, ExtImpRubiconBuilder> extCustomizer) {
return impCustomizer.apply(Imp.builder()
.ext(mapper.valueToTree(ExtPrebid.of(null, extCustomizer.apply(ExtImpRubicon.builder()).build()))))
.ext(mapper.valueToTree(ExtPrebid.of(
null, extCustomizer.apply(ExtImpRubicon.builder()).build()))))
.build();
}

Expand Down

0 comments on commit b8e6c4b

Please sign in to comment.