Skip to content

Commit

Permalink
Silvermob: host validation (us, eu, apac) (#3110)
Browse files Browse the repository at this point in the history
  • Loading branch information
freemmy authored Sep 26, 2023
1 parent b9c2614 commit a91e40c
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 2 deletions.
14 changes: 12 additions & 2 deletions adapters/silvermob/silvermob.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ type SilverMobAdapter struct {
endpoint *template.Template
}

func isValidHost(host string) bool {
return host == "eu" || host == "us" || host == "apac"
}

// Builder builds a new instance of the SilverMob adapter for the given bidder with the given config.
func Builder(bidderName openrtb_ext.BidderName, config config.Adapter, server config.Server) (adapters.Bidder, error) {
template, err := template.New("endpointTemplate").Parse(config.Endpoint)
Expand Down Expand Up @@ -121,8 +125,14 @@ func (a *SilverMobAdapter) getImpressionExt(imp *openrtb2.Imp) (*openrtb_ext.Ext
}

func (a *SilverMobAdapter) buildEndpointURL(params *openrtb_ext.ExtSilverMob) (string, error) {
endpointParams := macros.EndpointTemplateParams{ZoneID: params.ZoneID, Host: params.Host}
return macros.ResolveMacros(a.endpoint, endpointParams)
if isValidHost(params.Host) {
endpointParams := macros.EndpointTemplateParams{ZoneID: params.ZoneID, Host: params.Host}
return macros.ResolveMacros(a.endpoint, endpointParams)
} else {
return "", &errortypes.BadInput{
Message: fmt.Sprintf("invalid host %s", params.Host),
}
}
}

func (a *SilverMobAdapter) MakeBids(
Expand Down
53 changes: 53 additions & 0 deletions adapters/silvermob/silvermobtest/supplemental/invalid-host.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"mockBidRequest": {
"id": "some-request-id",
"device": {
"ua": "test-user-agent",
"ip": "123.123.123.123",
"language": "en",
"dnt": 0
},
"tmax": 1000,
"user": {
"buyeruid": "awesome-user"
},
"app": {
"publisher": {
"id": "123456789"
},
"cat": [
"IAB22-1"
],
"bundle": "com.app.awesome",
"name": "Awesome App",
"domain": "awesomeapp.com",
"id": "123456789"
},
"imp": [
{
"id": "some-impression-id",
"tagid": "ogTAGID",
"banner": {
"w":320,
"h":50
},
"ext": {
"bidder": {
"host": "some_host",
"zoneid": "0"
}
}
}
]
},
"httpCalls": [
],
"expectedBidResponses": [
],
"expectedMakeRequestsErrors": [
{
"value": "invalid host some_host",
"comparison": "literal"
}
]
}

0 comments on commit a91e40c

Please sign in to comment.