From 2085aac7e68eff4532843921c19c61fd781f118e Mon Sep 17 00:00:00 2001 From: Aleix Date: Tue, 12 Nov 2019 14:55:20 +0100 Subject: [PATCH] more requested changes --- adapters/tappx/tappx.go | 42 +++++++------------ adapters/tappx/tappx_test.go | 5 ++- .../banner-impression-badhost.json | 39 +++++++++++++++++ 3 files changed, 58 insertions(+), 28 deletions(-) create mode 100644 adapters/tappx/tappxtest/supplemental/banner-impression-badhost.json diff --git a/adapters/tappx/tappx.go b/adapters/tappx/tappx.go index cc9d305829f..69000c335e0 100644 --- a/adapters/tappx/tappx.go +++ b/adapters/tappx/tappx.go @@ -28,7 +28,7 @@ func NewTappxBidder(client *http.Client, endpointTemplate string) *TappxAdapter a := &adapters.HTTPAdapter{Client: client} template, err := template.New("endpointTemplate").Parse(endpointTemplate) if err != nil { - glog.Fatal("Unable to parse endpoint url template") + glog.Fatal("Unable to parse endpoint url template: " + err.Error()) return nil } return &TappxAdapter{ @@ -98,43 +98,39 @@ func (a *TappxAdapter) MakeRequests(request *openrtb.BidRequest, reqInfo *adapte // Builds enpoint url based on adapter-specific pub settings from imp.ext func (a *TappxAdapter) buildEndpointURL(params *openrtb_ext.ExtImpTappx, test int) (string, error) { - reqHost, reqKey, reqEndpoint := "", "", "" - if params.Host != "" { - reqHost = params.Host - } - if params.Endpoint != "" { - reqEndpoint = params.Endpoint - } - if params.TappxKey != "" { - reqKey = params.TappxKey - } - if reqHost == "" { + if params.Host == "" { return "", &errortypes.BadInput{ Message: "Tappx host undefined", } } - endpointParams := macros.EndpointTemplateParams{Host: reqHost} - host, err := macros.ResolveMacros(a.endpointTemplate, endpointParams) + if params.Endpoint == "" { + return "", &errortypes.BadInput{ + Message: "Tappx endpoint undefined", + } + } - if err != nil { + if params.TappxKey == "" { return "", &errortypes.BadInput{ - Message: "Unable to parse endpoint url template", + Message: "Tappx key undefined", } } - thisURI, err := url.Parse(host) + endpointParams := macros.EndpointTemplateParams{Host: params.Host} + host, err := macros.ResolveMacros(a.endpointTemplate, endpointParams) if err != nil { return "", &errortypes.BadInput{ - Message: "Malformed URL: check host parameter", + Message: "Unable to parse endpoint url template: " + err.Error(), } } - if reqEndpoint == "" { + thisURI, err := url.Parse(host) + + if err != nil { return "", &errortypes.BadInput{ - Message: "Tappx endpoint undefined", + Message: "Malformed URL: " + err.Error(), } } @@ -142,12 +138,6 @@ func (a *TappxAdapter) buildEndpointURL(params *openrtb_ext.ExtImpTappx, test in queryParams := url.Values{} - if reqKey == "" { - return "", &errortypes.BadInput{ - Message: "Tappx key undefined", - } - } - queryParams.Add("tappxkey", params.TappxKey) if test == 0 { diff --git a/adapters/tappx/tappx_test.go b/adapters/tappx/tappx_test.go index 8d0c121b034..bc195b5978f 100644 --- a/adapters/tappx/tappx_test.go +++ b/adapters/tappx/tappx_test.go @@ -24,9 +24,10 @@ func TestTsValue(t *testing.T) { url, err := adapter.buildEndpointURL(&tappxExt, test) - match, err := regexp.MatchString(`&ts=[0-9]{13}`, url) + match, err := regexp.MatchString(`https://example\.host\.tappx\.com/DUMMYENDPOINT\?tappxkey=dummy-tappx-key&ts=[0-9]{13}&type_cnn=prebid&v=1\.1`, url) if err != nil { - //something happened during regex validation + t.Errorf("Error while running regex validation: %s", err.Error()) + return } assert.True(t, match) } diff --git a/adapters/tappx/tappxtest/supplemental/banner-impression-badhost.json b/adapters/tappx/tappxtest/supplemental/banner-impression-badhost.json new file mode 100644 index 00000000000..811f34f3348 --- /dev/null +++ b/adapters/tappx/tappxtest/supplemental/banner-impression-badhost.json @@ -0,0 +1,39 @@ +{ + "mockBidRequest": { + "id": "0000000000001", + "imp": [ + { + "id": "adunit-1", + "banner": { + "w": 300, + "h": 250 + }, + "ext": { + "bidder": { + "host": "example.ho%st.tappx.com", + "endpoint": "PREBIDTEMPLATE", + "tappxkey": "pub-12345-android-9876" + } + } + } + ], + "app": { + "id": "app_001", + "bundle": "com.rovio.angrybirds", + "publisher": { + "id": "2" + } + }, + "user": { + "buyeruid": "A-38327932832" + } + }, + + "expectedMakeRequestsErrors": [ + { + "value": "Malformed URL: parse https://example.ho%st.tappx.com: invalid URL escape \"%st\"", + "comparison": "literal" + } + ] + +} \ No newline at end of file