github.com/prebid/prebid-server/v2@v2.18.0/.semgrep/adapter/type-bid-assignment.go (about) 1 /* 2 type-bid-assignment tests 3 https://semgrep.dev/docs/writing-rules/testing-rules 4 "ruleid" prefix in comment indicates patterns that should be flagged by semgrep 5 "ok" prefix in comment indidcates patterns that should not be flagged by the semgrep 6 */ 7 8 func (a *adapter) MakeBids(internalRequest *openrtb2.BidRequest, externalRequest *adapters.RequestData, response *adapters.ResponseData) (*adapters.BidderResponse, []error) { 9 var bidResp openrtb2.BidResponse 10 11 if err := json.Unmarshal(response.Body, &bidResp); err != nil { 12 return nil, []error{err} 13 } 14 15 for _, seatBid := range bidResp.SeatBid { 16 for _, sb := range seatBid.Bid { 17 bidType, err := getMediaTypeForImp(seatBid.Bid[i], internalRequest.Imp) 18 if err != nil { 19 errs = append(errs, err) 20 } else { 21 b := &adapters.TypedBid{ 22 // ruleid: type-bid-assignment-check 23 Bid: &sb, 24 BidType: bidType, 25 } 26 bidResponse.Bids = append(bidResponse.Bids, b) 27 } 28 } 29 } 30 } 31 32 func (a *adapter) MakeBids(internalRequest *openrtb2.BidRequest, externalRequest *adapters.RequestData, response *adapters.ResponseData) (*adapters.BidderResponse, []error) { 33 var bidResp openrtb2.BidResponse 34 35 if err := json.Unmarshal(response.Body, &bidResp); err != nil { 36 return nil, []error{err} 37 } 38 39 for _, seatBid := range bidResp.SeatBid { 40 for _, sb := range seatBid.Bid { 41 sbcopy := sb 42 bidType, err := getMediaTypeForImp(seatBid.Bid[i], internalRequest.Imp) 43 if err != nil { 44 errs = append(errs, err) 45 } else { 46 b := &adapters.TypedBid{ 47 // ok: type-bid-assignment-check 48 Bid: &sbcopy, 49 BidType: bidType, 50 } 51 bidResponse.Bids = append(bidResponse.Bids, b) 52 } 53 } 54 } 55 } 56 57 func (a *adapter) MakeBids(internalRequest *openrtb2.BidRequest, externalRequest *adapters.RequestData, response *adapters.ResponseData) (*adapters.BidderResponse, []error) { 58 var bidResp openrtb2.BidResponse 59 60 if err := json.Unmarshal(response.Body, &bidResp); err != nil { 61 return nil, []error{err} 62 } 63 64 for _, seatBid := range bidResp.SeatBid { 65 for _, sb := range seatBid.Bid { 66 bidType, err := getMediaTypeForImp(seatBid.Bid[i], internalRequest.Imp) 67 if err != nil { 68 return nil, err 69 } 70 bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{ 71 // ruleid: type-bid-assignment-check 72 Bid: &sb, 73 BidType: bidType, 74 }) 75 76 } 77 } 78 } 79 80 func (a *adapter) MakeBids(internalRequest *openrtb2.BidRequest, externalRequest *adapters.RequestData, response *adapters.ResponseData) (*adapters.BidderResponse, []error) { 81 var bidResp openrtb2.BidResponse 82 83 if err := json.Unmarshal(response.Body, &bidResp); err != nil { 84 return nil, []error{err} 85 } 86 87 for _, seatBid := range bidResp.SeatBid { 88 for _, sb := range seatBid.Bid { 89 bidType, err := getMediaTypeForImp(seatBid.Bid[i], internalRequest.Imp) 90 if err != nil { 91 return nil, err 92 } 93 // ruleid: type-bid-assignment-check 94 bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{Bid: &sb, BidType: bidType}) 95 } 96 } 97 } 98 99 func (a *adapter) MakeBids(internalRequest *openrtb2.BidRequest, externalRequest *adapters.RequestData, response *adapters.ResponseData) (*adapters.BidderResponse, []error) { 100 var bidResp openrtb2.BidResponse 101 102 if err := json.Unmarshal(response.Body, &bidResp); err != nil { 103 return nil, []error{err} 104 } 105 106 var errors []error 107 for _, seatBid := range bidResp.SeatBid { 108 for _, bid := range seatBid.Bid { 109 var t adapters.TypedBid 110 // ruleid: type-bid-assignment-check 111 t.Bid = &bid 112 bidResponse.Bids = append(bidResponse.Bids, &t) 113 } 114 } 115 return bidResponse, errors 116 } 117 118 func (a *adapter) MakeBids(internalRequest *openrtb2.BidRequest, externalRequest *adapters.RequestData, response *adapters.ResponseData) (*adapters.BidderResponse, []error) { 119 var bidResp openrtb2.BidResponse 120 121 if err := json.Unmarshal(response.Body, &bidResp); err != nil { 122 return nil, []error{err} 123 } 124 125 var errors []error 126 for _, seatBid := range bidResp.SeatBid { 127 for _, bid := range seatBid.Bid { 128 var t adapters.TypedBid 129 t = adapters.TypedBid{ 130 // ruleid: type-bid-assignment-check 131 Bid: &bid, 132 } 133 134 bidResponse.Bids = append(bidResponse.Bids, &t) 135 } 136 } 137 return bidResponse, errors 138 } 139 140 func (a *adapter) MakeBids(internalRequest *openrtb2.BidRequest, externalRequest *adapters.RequestData, response *adapters.ResponseData) (*adapters.BidderResponse, []error) { 141 var bidResp openrtb2.BidResponse 142 143 if err := json.Unmarshal(response.Body, &bidResp); err != nil { 144 return nil, []error{err} 145 } 146 147 for _, seatBid := range bidResp.SeatBid { 148 for idx, _ := range seatBid.Bid { 149 bidType, err := getMediaTypeForImp(seatBid.Bid[i], internalRequest.Imp) 150 if err != nil { 151 errs = append(errs, err) 152 } else { 153 b := &adapters.TypedBid{ 154 // ok: type-bid-assignment-check 155 Bid: &seatBid.Bid[idx], 156 BidType: bidType, 157 } 158 bidResponse.Bids = append(bidResponse.Bids, b) 159 } 160 } 161 } 162 } 163 164 func (a *adapter) MakeBids(internalRequest *openrtb2.BidRequest, externalRequest *adapters.RequestData, response *adapters.ResponseData) (*adapters.BidderResponse, []error) { 165 var bidResp openrtb2.BidResponse 166 167 if err := json.Unmarshal(response.Body, &bidResp); err != nil { 168 return nil, []error{err} 169 } 170 171 for _, seatBid := range bidResp.SeatBid { 172 for idx := range seatBid.Bid { 173 bidType, err := getMediaTypeForImp(seatBid.Bid[i], internalRequest.Imp) 174 if err != nil { 175 return nil, err 176 } 177 // ok: type-bid-assignment-check 178 bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{Bid: &seatBid.Bid[idx], BidType: bidType}) 179 } 180 } 181 }