Skip to content

Commit

Permalink
Trimming publisher ID before passing
Browse files Browse the repository at this point in the history
  • Loading branch information
sachin-pubmatic committed Feb 1, 2021
1 parent ef06fac commit d3e4822
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion adapters/pubmatic/pubmatic.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ func parseImpressionObject(imp *openrtb.Imp, wrapExt *string, pubID *string) err
}

if *pubID == "" {
*pubID = pubmaticExt.PublisherId
*pubID = strings.TrimSpace(pubmaticExt.PublisherId)
}

// Parse Wrapper Extension only once per request
Expand Down
35 changes: 35 additions & 0 deletions adapters/pubmatic/pubmatic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import (
"github.com/prebid/prebid-server/openrtb_ext"
"github.com/prebid/prebid-server/pbs"
"github.com/prebid/prebid-server/usersync"

"github.com/stretchr/testify/assert"
)

func TestJsonSamples(t *testing.T) {
Expand Down Expand Up @@ -728,3 +730,36 @@ func TestGetBidTypeForUnsupportedCode(t *testing.T) {
t.Errorf("Expected Bid Type value was: %v, actual value is: %v", openrtb_ext.BidTypeBanner, actualBidTypeValue)
}
}

func TestMakeRequestsTrimsPubID(t *testing.T) {
var a PubmaticAdapter
a.URI = "http://test.com/openrtb2"

var bidderExt adapters.ExtImpBidder
extImpPubMatic := openrtb_ext.ExtImpPubmatic{}
extImpPubMatic.PublisherId = " 5890 "
bidderExt.Bidder, _ = json.Marshal(extImpPubMatic)
extRaw, _ := json.Marshal(bidderExt)

var w, h uint64
w = 300
h = 250
var impression = openrtb.Imp{
Banner: &openrtb.Banner{
W: &w,
H: &h,
},
Ext: extRaw,
}
request := &openrtb.BidRequest{
Imp: []openrtb.Imp{impression},
Site: &openrtb.Site{
Publisher: &openrtb.Publisher{},
},
}
a.MakeRequests(request, nil)

updatedPubID := request.Site.Publisher.ID

assert.Equal(t, "5890", updatedPubID, "Publisher.ID field should be trimmed")
}

0 comments on commit d3e4822

Please sign in to comment.