74 lines
2.5 KiB
Python
74 lines
2.5 KiB
Python
import json
|
|
import re
|
|
import unittest
|
|
|
|
from core.enc_data import load_kwsg_10400_tables
|
|
from core.reward_request import (
|
|
REWARD_SDK,
|
|
build_reward_body,
|
|
build_reward_str_e,
|
|
)
|
|
from core.sig3 import Kwsg10418State
|
|
|
|
|
|
class RewardRequestTests(unittest.TestCase):
|
|
def test_build_reward_str_e_uses_current_account_and_device(self):
|
|
payload = build_reward_str_e(
|
|
kind="normal",
|
|
cookie_dict={
|
|
"userId": "1579452490",
|
|
"did": "ANDROID_12aff820da1056f9",
|
|
},
|
|
api_params={
|
|
"appver": "14.5.50.11631",
|
|
"sys": "ANDROID_16",
|
|
"sw": "1080",
|
|
"sh": "2376",
|
|
"sbh": "120",
|
|
"net": "5G",
|
|
},
|
|
oaid="OAID_TEST",
|
|
scene=(11101, 100026367, 24067),
|
|
business_id=672,
|
|
neo_params="NEO_PARAMS",
|
|
now_ms=1783759468345,
|
|
network_ip="172.31.230.147",
|
|
ipdx_ip="106.178.190.155",
|
|
)
|
|
|
|
data = json.loads(payload.decode("utf-8"))
|
|
imp = data["impInfo"][0]
|
|
imp_ext = json.loads(imp["impExtData"])
|
|
session = json.loads(imp["session"])
|
|
|
|
self.assertEqual(data["userInfo"]["userId"], "1579452490")
|
|
self.assertEqual(data["deviceInfo"]["deviceId"], "ANDROID_12aff820da1056f9")
|
|
self.assertEqual(data["deviceInfo"]["oaid"], "OAID_TEST")
|
|
self.assertEqual(data["deviceInfo"]["screenSize"], {"width": 1080, "height": 2208})
|
|
self.assertEqual(data["networkInfo"], {"ip": "172.31.230.147", "connectionType": 5})
|
|
self.assertEqual((imp["pageId"], imp["subPageId"], imp["requestSceneType"]), (11101, 100026367, 1))
|
|
self.assertEqual(imp_ext["neoParams"], "NEO_PARAMS")
|
|
self.assertEqual(session["id"], "adNeo-1579452490-100026367-1783759468345")
|
|
|
|
def test_build_reward_body_generates_enc_data_and_body_sign(self):
|
|
t1, t2 = load_kwsg_10400_tables()
|
|
state = Kwsg10418State.from_digest("dacbbe98b4eae3c18093919051c3bf2a163dd9e28f838d9b")
|
|
|
|
body = build_reward_body(
|
|
b'{"hello":"world"}',
|
|
state,
|
|
t1=t1,
|
|
t2=t2,
|
|
unix_time=1783759468,
|
|
enc_epoch_seconds=1783759468,
|
|
)
|
|
|
|
self.assertGreater(len(body.enc_data), 40)
|
|
self.assertRegex(body.sign, r"^5a54eecde4d4ea61[0-9a-f]{48}$")
|
|
self.assertEqual(body.sdk_id, REWARD_SDK)
|
|
self.assertEqual(state.counter, body.sign_counter)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|