Skip to content

Commit

Permalink
add test authorization, update test cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
w00522253 committed Aug 20, 2021
1 parent 41244a3 commit 2aec272
Show file tree
Hide file tree
Showing 26 changed files with 92 additions and 43 deletions.
23 changes: 12 additions & 11 deletions adapters/huaweiads/huaweiads.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,12 +270,12 @@ func (a *adapter) MakeRequests(openRTBRequest *openrtb2.BidRequest,
}

// our request header's Authorization is changing by time, cannot verify by a certain string,
// use isAddAuthorization = false only when run testcase
var isAddAuthorization = true
if huaweiAdsImpExt != nil && huaweiAdsImpExt.IsAddAuthorization == "false" {
isAddAuthorization = false
// use isTestAuthorization = true only when run testcase
var isTestAuthorization = false
if huaweiAdsImpExt != nil && huaweiAdsImpExt.IsTestAuthorization == "true" {
isTestAuthorization = true
}
header = getHeaders(huaweiAdsImpExt, openRTBRequest, isAddAuthorization)
header = getHeaders(huaweiAdsImpExt, openRTBRequest, isTestAuthorization)
bidRequest := &adapters.RequestData{
Method: http.MethodPost,
Uri: a.endpoint,
Expand Down Expand Up @@ -321,17 +321,14 @@ func Builder(bidderName openrtb_ext.BidderName, config config.Adapter) (adapters
}

// getHeaders: get request header, Authorization -> digest
func getHeaders(huaweiAdsImpExt *openrtb_ext.ExtImpHuaweiAds, request *openrtb2.BidRequest, isAddAuthorization bool) http.Header {
func getHeaders(huaweiAdsImpExt *openrtb_ext.ExtImpHuaweiAds, request *openrtb2.BidRequest, isTestAuthorization bool) http.Header {
headers := http.Header{}
headers.Add("Content-Type", "application/json;charset=utf-8")
headers.Add("Accept", "application/json")
if huaweiAdsImpExt == nil {
return headers
}

if isAddAuthorization {
headers.Add("Authorization", getDigestAuthorization(huaweiAdsImpExt))
}
headers.Add("Authorization", getDigestAuthorization(huaweiAdsImpExt, isTestAuthorization))

if request.Device != nil && len(request.Device.UA) > 0 {
headers.Add("User-Agent", request.Device.UA)
Expand Down Expand Up @@ -1281,8 +1278,12 @@ func computeHmacSha256(message string, signKey string) string {
}

// getDigestAuthorization: get digest authorization for request header
func getDigestAuthorization(huaweiAdsImpExt *openrtb_ext.ExtImpHuaweiAds) string {
func getDigestAuthorization(huaweiAdsImpExt *openrtb_ext.ExtImpHuaweiAds, isTestAuthorization bool) string {
var nonce = strconv.FormatInt(time.Now().UnixNano()/1e6, 10)
// this is for test case, time 2021/8/20 19:30
if isTestAuthorization {
nonce = "1629473330823"
}
var apiKey = huaweiAdsImpExt.PublisherId + ":ppsadx/getResult:" + huaweiAdsImpExt.SignKey
return "Digest username=" + huaweiAdsImpExt.PublisherId + "," +
"realm=ppsadx/getResult," +
Expand Down
5 changes: 4 additions & 1 deletion adapters/huaweiads/huaweiadstest/exemplary/banner1.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"publisherid": "123",
"signkey": "signkey",
"keyid": "41",
"isAddAuthorization": "false"
"isTestAuthorization": "true"
}
}
}
Expand Down Expand Up @@ -85,6 +85,9 @@
],
"User-Agent": [
"useragent"
],
"Authorization": [
"Digest username=123,realm=ppsadx/getResult,nonce=1629473330823,response=d1d61a13a83e1468aa4dff5c8a6cee0b8b381173ca3eb6fa9b313937684d87c0,algorithm=HmacSHA256,usertype=1,keyid=41"
]
},
"body": {
Expand Down
5 changes: 4 additions & 1 deletion adapters/huaweiads/huaweiadstest/exemplary/banner2.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"publisherid": "123",
"signkey": "signkey",
"keyid": "41",
"isAddAuthorization": "false"
"isTestAuthorization": "true"
}
}
}
Expand Down Expand Up @@ -109,6 +109,9 @@
],
"User-Agent": [
"ua"
],
"Authorization": [
"Digest username=123,realm=ppsadx/getResult,nonce=1629473330823,response=d1d61a13a83e1468aa4dff5c8a6cee0b8b381173ca3eb6fa9b313937684d87c0,algorithm=HmacSHA256,usertype=1,keyid=41"
]
},
"body": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"publisherid": "123",
"signkey": "signkey",
"keyid": "41",
"isAddAuthorization": "false"
"isTestAuthorization": "true"
}
}
}
Expand Down Expand Up @@ -75,6 +75,9 @@
],
"User-Agent": [
"useragent"
],
"Authorization": [
"Digest username=123,realm=ppsadx/getResult,nonce=1629473330823,response=d1d61a13a83e1468aa4dff5c8a6cee0b8b381173ca3eb6fa9b313937684d87c0,algorithm=HmacSHA256,usertype=1,keyid=41"
]
},
"body": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"publisherid": "123",
"signkey": "signkey",
"keyid": "41",
"isAddAuthorization": "false"
"isTestAuthorization": "true"
}
}
}
Expand Down Expand Up @@ -74,6 +74,9 @@
],
"User-Agent": [
"useragent"
],
"Authorization": [
"Digest username=123,realm=ppsadx/getResult,nonce=1629473330823,response=d1d61a13a83e1468aa4dff5c8a6cee0b8b381173ca3eb6fa9b313937684d87c0,algorithm=HmacSHA256,usertype=1,keyid=41"
]
},
"body": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"publisherid": "123",
"signkey": "signkey",
"keyid": "41",
"isAddAuthorization": "false"
"isTestAuthorization": "true"
}
}
}
Expand Down Expand Up @@ -73,6 +73,9 @@
],
"User-Agent": [
"useragent"
],
"Authorization": [
"Digest username=123,realm=ppsadx/getResult,nonce=1629473330823,response=d1d61a13a83e1468aa4dff5c8a6cee0b8b381173ca3eb6fa9b313937684d87c0,algorithm=HmacSHA256,usertype=1,keyid=41"
]
},
"body": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"publisherid": "123",
"signkey": "signkey",
"keyid": "41",
"isAddAuthorization": "false"
"isTestAuthorization": "true"
}
}
}
Expand Down Expand Up @@ -73,6 +73,9 @@
],
"User-Agent": [
"useragent"
],
"Authorization": [
"Digest username=123,realm=ppsadx/getResult,nonce=1629473330823,response=d1d61a13a83e1468aa4dff5c8a6cee0b8b381173ca3eb6fa9b313937684d87c0,algorithm=HmacSHA256,usertype=1,keyid=41"
]
},
"body": {
Expand Down
7 changes: 5 additions & 2 deletions adapters/huaweiads/huaweiadstest/exemplary/video.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
"bidder": {
"slotid": "m8x9x3roll",
"adtype": "roll",
"publisherid": "123",
"publisherid": "123123123",
"signkey": "signkey",
"keyid": "41",
"isAddAuthorization": "false"
"isTestAuthorization": "true"
}
}
}
Expand Down Expand Up @@ -84,6 +84,9 @@
],
"User-Agent": [
"useragent"
],
"Authorization": [
"Digest username=123123123,realm=ppsadx/getResult,nonce=1629473330823,response=6fdc975d3adac426cbe607eec736f40ad3db8413312457431e391580e1b475c4,algorithm=HmacSHA256,usertype=1,keyid=41"
]
},
"body": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"publisherid": "123",
"signkey": "signkey",
"keyid": "41",
"isAddAuthorization": "false"
"isTestAuthorization": "true"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"publisherid": "123",
"signkey": "signkey",
"keyid": "41",
"isAddAuthorization": "false"
"isTestAuthorization": "true"
}
}
}
Expand Down Expand Up @@ -79,6 +79,9 @@
],
"User-Agent": [
"useragent"
],
"Authorization": [
"Digest username=123,realm=ppsadx/getResult,nonce=1629473330823,response=d1d61a13a83e1468aa4dff5c8a6cee0b8b381173ca3eb6fa9b313937684d87c0,algorithm=HmacSHA256,usertype=1,keyid=41"
]
},
"body": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"publisherid": "123",
"signkey": "signkey",
"keyid": "41",
"isAddAuthorization": "false"
"isTestAuthorization": "true"
}
}
}
Expand Down Expand Up @@ -79,6 +79,9 @@
],
"User-Agent": [
"useragent"
],
"Authorization": [
"Digest username=123,realm=ppsadx/getResult,nonce=1629473330823,response=d1d61a13a83e1468aa4dff5c8a6cee0b8b381173ca3eb6fa9b313937684d87c0,algorithm=HmacSHA256,usertype=1,keyid=41"
]
},
"body": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"publisherid": "123",
"signkey": "signkey",
"keyid": "41",
"isAddAuthorization": "false"
"isTestAuthorization": "true"
}
}
}
Expand Down Expand Up @@ -79,6 +79,9 @@
],
"User-Agent": [
"useragent"
],
"Authorization": [
"Digest username=123,realm=ppsadx/getResult,nonce=1629473330823,response=d1d61a13a83e1468aa4dff5c8a6cee0b8b381173ca3eb6fa9b313937684d87c0,algorithm=HmacSHA256,usertype=1,keyid=41"
]
},
"body": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"publisherid": "123",
"signkey": "signkey",
"keyid": "41",
"isAddAuthorization": "false"
"isTestAuthorization": "true"
}
}
},
Expand All @@ -44,7 +44,7 @@
"publisherid": "123",
"signkey": "signkey",
"keyid": "41",
"isAddAuthorization": "false"
"isTestAuthorization": "true"
}
}
}
Expand Down Expand Up @@ -102,6 +102,9 @@
],
"User-Agent": [
"useragent"
],
"Authorization": [
"Digest username=123,realm=ppsadx/getResult,nonce=1629473330823,response=d1d61a13a83e1468aa4dff5c8a6cee0b8b381173ca3eb6fa9b313937684d87c0,algorithm=HmacSHA256,usertype=1,keyid=41"
]
},
"body": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"publisherid": "123",
"signkey": "signkey",
"keyid": "41",
"isAddAuthorization": "false"
"isTestAuthorization": "true"
}
}
}
Expand Down Expand Up @@ -73,6 +73,9 @@
],
"User-Agent": [
"useragent"
],
"Authorization": [
"Digest username=123,realm=ppsadx/getResult,nonce=1629473330823,response=d1d61a13a83e1468aa4dff5c8a6cee0b8b381173ca3eb6fa9b313937684d87c0,algorithm=HmacSHA256,usertype=1,keyid=41"
]
},
"body": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"publisherid": "123",
"signkey": "signkey",
"keyid": "41",
"isAddAuthorization": "false"
"isTestAuthorization": "true"
}
}
}
Expand Down Expand Up @@ -79,6 +79,9 @@
],
"User-Agent": [
"useragent"
],
"Authorization": [
"Digest username=123,realm=ppsadx/getResult,nonce=1629473330823,response=d1d61a13a83e1468aa4dff5c8a6cee0b8b381173ca3eb6fa9b313937684d87c0,algorithm=HmacSHA256,usertype=1,keyid=41"
]
},
"body": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"publisherid": "123",
"signkey": "signkey",
"keyid": "41",
"isAddAuthorization": "false"
"isTestAuthorization": "true"
}
}
}
Expand Down Expand Up @@ -79,6 +79,9 @@
],
"User-Agent": [
"useragent"
],
"Authorization": [
"Digest username=123,realm=ppsadx/getResult,nonce=1629473330823,response=d1d61a13a83e1468aa4dff5c8a6cee0b8b381173ca3eb6fa9b313937684d87c0,algorithm=HmacSHA256,usertype=1,keyid=41"
]
},
"body": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"publisherid": "123",
"signkey": "signkey",
"keyid": "41",
"isAddAuthorization": "false"
"isTestAuthorization": "true"
}
}
}
Expand Down Expand Up @@ -79,6 +79,9 @@
],
"User-Agent": [
"useragent"
],
"Authorization": [
"Digest username=123,realm=ppsadx/getResult,nonce=1629473330823,response=d1d61a13a83e1468aa4dff5c8a6cee0b8b381173ca3eb6fa9b313937684d87c0,algorithm=HmacSHA256,usertype=1,keyid=41"
]
},
"body": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"publisherid": "123",
"signkey": "signkey",
"keyid": "41",
"isAddAuthorization": "false"
"isTestAuthorization": "true"
}
}
}
Expand Down Expand Up @@ -79,6 +79,9 @@
],
"User-Agent": [
"useragent"
],
"Authorization": [
"Digest username=123,realm=ppsadx/getResult,nonce=1629473330823,response=d1d61a13a83e1468aa4dff5c8a6cee0b8b381173ca3eb6fa9b313937684d87c0,algorithm=HmacSHA256,usertype=1,keyid=41"
]
},
"body": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"signkey": "signkey",
"keyid": "12",
"clienttime": "2018-11-02 16:34:07.981+1300",
"isAddAuthorization": "false"
"isTestAuthorization": "true"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"publisherid": "123",
"signkey": "signkey",
"keyid": "41",
"isAddAuthorization": "false"
"isTestAuthorization": "true"
}
}
}
Expand Down
Loading

0 comments on commit 2aec272

Please sign in to comment.