OppoClientTest.java 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. package com.adx.tencent.oppo.client;
  2. import org.junit.jupiter.api.Test;
  3. import java.util.Map;
  4. import static org.junit.jupiter.api.Assertions.assertEquals;
  5. import static org.junit.jupiter.api.Assertions.assertTrue;
  6. class OppoClientTest {
  7. private static final String KEY = "XGAXicVG5GMBsx5bueOe4w==";
  8. @Test
  9. void calculatesDocumentedSignature() throws Exception {
  10. String body = "{\"payAmount\":100,\"adId\":101097648,\"appType\":1,\"clientIp\":\"127.0.0.1\",\"dataType\":1,\"ascribeType\":1,\"channel\":1,\"imei\":\"XJMyaLt8fDlv4a9b8/0RNQ==\",\"type\":1,\"pkg\":\"com.oppo.test\",\"mac\":\"TEViR6jSgD/lECBl3Ah70eNy2gUQrQlekHkWqEGkZsU=\",\"timestamp\":1571995483916}";
  11. assertEquals("ce14fcc22abd7461e860263a8da983eb",
  12. OppoClient.md5(body + "1571995483916" + "e0u6fnlag06lc3pl"));
  13. }
  14. @Test
  15. void encryptsDeviceValuesWithDocumentedAes() throws Exception {
  16. OppoClient client = new OppoClient(null, "", KEY, (String) null, new com.fasterxml.jackson.databind.ObjectMapper());
  17. assertEquals("XJMyaLt8fDlv4a9b8/0RNQ==", client.encrypt("868123039927020"));
  18. }
  19. @Test
  20. void exposesStableRequestFields() {
  21. assertEquals("https://api.ads.heytapmobi.com/api/uploadActiveData", OppoClient.DEFAULT_ENDPOINT);
  22. Map<String, Object> body = Map.of("dataType", 1);
  23. assertEquals(1, body.get("dataType"));
  24. }
  25. @Test
  26. void tokenPayloadUsesDocumentedShape() {
  27. String payload = "owner,api,123,signature";
  28. assertTrue(java.util.Base64.getEncoder().encodeToString(payload.getBytes()).length() > payload.length());
  29. }
  30. }