Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions src/main/java/org/prebid/server/bidder/floxis/FloxisBidder.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ public Result<List<BidderBid>> makeBids(BidderCall<BidRequest> httpCall, BidRequ
try {
final BidResponse bidResponse = mapper.decodeValue(httpCall.getResponse().getBody(), BidResponse.class);
final List<BidderError> errors = new ArrayList<>();
final List<BidderBid> bidderBids = extractBids(bidResponse, bidRequest.getImp(), errors);
final List<Imp> imps = httpCall.getRequest().getPayload().getImp();
final List<BidderBid> bidderBids = extractBids(bidResponse, imps, errors);
return Result.of(bidderBids, errors);
} catch (DecodeException e) {
return Result.withError(BidderError.badServerResponse(e.getMessage()));
Expand Down Expand Up @@ -150,6 +151,12 @@ private static BidderBid makeBidderBid(Bid bid, List<Imp> imps, String currency,
}

private static BidType getMediaTypeForBid(List<Imp> imps, Bid bid) {
final Imp imp = imps.stream()
.filter(currentImp -> Objects.equals(currentImp.getId(), bid.getImpid()))
.findFirst()
.orElseThrow(() -> new PreBidException(
"unable to find impression %s for bid".formatted(bid.getImpid())));

final Integer mtype = bid.getMtype();
if (mtype != null && mtype != 0) {
return switch (mtype) {
Expand All @@ -162,12 +169,6 @@ private static BidType getMediaTypeForBid(List<Imp> imps, Bid bid) {
};
}

final Imp imp = imps.stream()
.filter(currentImp -> Objects.equals(currentImp.getId(), bid.getImpid()))
.findFirst()
.orElseThrow(() -> new PreBidException(
"unable to find impression %s for bid".formatted(bid.getImpid())));

if (countFormats(imp) != 1) {
throw new PreBidException(
"unable to resolve a single media type for impression %s; set bid.mtype"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,80 @@ public void makeBidsShouldReturnErrorWhenBidImpIdNotFound() throws Exception {
"unable to find impression no-such-imp for bid"));
}

@Test
public void makeBidsShouldRejectUnknownImpWhenMTypePresent() throws Exception {
// given
final BidRequest bidRequest = givenBidRequest(identity());
final BidResponse bidResponse = givenBidResponse(Bid.builder().impid("unknown").mtype(1).build());
final BidderCall<BidRequest> httpCall = givenHttpCall(bidRequest, mapper.writeValueAsString(bidResponse));

// when
final Result<List<BidderBid>> result = target.makeBids(httpCall, bidRequest);

// then
assertThat(result.getValue()).isEmpty();
assertThat(result.getErrors()).containsExactly(
BidderError.badServerResponse("unable to find impression unknown for bid"));
}

@Test
public void makeBidsShouldRejectUnknownImpWhenMTypeZero() throws Exception {
// given
final BidRequest bidRequest = givenBidRequest(identity());
final BidResponse bidResponse = givenBidResponse(Bid.builder().impid("unknown").mtype(0).build());
final BidderCall<BidRequest> httpCall = givenHttpCall(bidRequest, mapper.writeValueAsString(bidResponse));

// when
final Result<List<BidderBid>> result = target.makeBids(httpCall, bidRequest);

// then
assertThat(result.getValue()).isEmpty();
assertThat(result.getErrors()).containsExactly(
BidderError.badServerResponse("unable to find impression unknown for bid"));
}

@Test
public void makeBidsShouldRejectOtherSeatImpWhenMTypePresent() throws Exception {
assertBidsMatchOutboundRequest(1);
}

@Test
public void makeBidsShouldRejectOtherSeatImpWhenMTypeZero() throws Exception {
assertBidsMatchOutboundRequest(0);
}

private void assertBidsMatchOutboundRequest(int mtype) throws Exception {
// given
final BidRequest bidRequest = BidRequest.builder()
.imp(asList(
givenImp(imp -> imp.id("imp-1").ext(givenImpExt("seat-1", "eu"))),
givenImp(imp -> imp.id("imp-2").ext(givenImpExt("seat-2", "eu")))))
.build();
final List<HttpRequest<BidRequest>> httpRequests = target.makeHttpRequests(bidRequest).getValue();
assertThat(httpRequests).hasSize(2);
assertThat(httpRequests.getFirst().getPayload().getImp()).extracting(Imp::getId)
.containsExactly("imp-1");
final BidResponse bidResponse = BidResponse.builder()
.cur("USD")
.seatbid(singletonList(SeatBid.builder()
.bid(asList(
Bid.builder().impid("imp-1").mtype(mtype).build(),
Bid.builder().impid("imp-2").mtype(mtype).build()))
.build()))
.build();
final BidderCall<BidRequest> httpCall = BidderCall.succeededHttp(
httpRequests.getFirst(), HttpResponse.of(200, null, mapper.writeValueAsString(bidResponse)), null);

// when
final Result<List<BidderBid>> result = target.makeBids(httpCall, bidRequest);

// then
assertThat(result.getValue()).extracting(bidderBid -> bidderBid.getBid().getImpid())
.containsExactly("imp-1");
assertThat(result.getErrors()).containsExactly(
BidderError.badServerResponse("unable to find impression imp-2 for bid"));
}

private static BidRequest givenBidRequest(UnaryOperator<Imp.ImpBuilder> impCustomizer) {
return BidRequest.builder()
.id("req-1")
Expand Down