diff --git a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/AdUnit.java b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/AdUnit.java index fae031209..55954d6dc 100644 --- a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/AdUnit.java +++ b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/AdUnit.java @@ -432,12 +432,12 @@ public void setGpid(@Nullable String gpid) { } @Nullable - public String getOrtbConfig() { - return configuration.getOrtbConfig(); + public String getImpOrtbConfig() { + return configuration.getImpOrtbConfig(); } - public void setOrtbConfig(@Nullable String ortbConfig) { - configuration.setOrtbConfig(ortbConfig); + public void setImpOrtbConfig(@Nullable String ortbConfig) { + configuration.setImpOrtbConfig(ortbConfig); } protected BidRequesterListener createBidListener(OnCompleteListener originalListener) { diff --git a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/BannerAdUnit.java b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/BannerAdUnit.java index 32a319f57..255dcf480 100644 --- a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/BannerAdUnit.java +++ b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/BannerAdUnit.java @@ -69,12 +69,12 @@ HashSet getSizes() { } @Nullable - public String getOrtbConfig() { - return configuration.getOrtbConfig(); + public String getImpOrtbConfig() { + return configuration.getImpOrtbConfig(); } - public void setOrtbConfig(@Nullable String ortbConfig) { - configuration.setOrtbConfig(ortbConfig); + public void setImpOrtbConfig(@Nullable String ortbConfig) { + configuration.setImpOrtbConfig(ortbConfig); } } diff --git a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/BannerBaseAdUnit.java b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/BannerBaseAdUnit.java index 3b09d1bd3..dae7daeb0 100644 --- a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/BannerBaseAdUnit.java +++ b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/BannerBaseAdUnit.java @@ -80,12 +80,12 @@ public Parameters getParameters() { } @Nullable - public String getOrtbConfig() { - return configuration.getOrtbConfig(); + public String getImpOrtbConfig() { + return configuration.getImpOrtbConfig(); } - public void setOrtbConfig(@Nullable String ortbConfig) { - configuration.setOrtbConfig(ortbConfig); + public void setImpOrtbConfig(@Nullable String ortbConfig) { + configuration.setImpOrtbConfig(ortbConfig); } /** diff --git a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/InterstitialAdUnit.java b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/InterstitialAdUnit.java index 64b7e6102..e2061b9e8 100644 --- a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/InterstitialAdUnit.java +++ b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/InterstitialAdUnit.java @@ -71,12 +71,12 @@ public void setMinSizePercentage( } @Nullable - public String getOrtbConfig() { - return configuration.getOrtbConfig(); + public String getImpOrtbConfig() { + return configuration.getImpOrtbConfig(); } - public void setOrtbConfig(@Nullable String ortbConfig) { - configuration.setOrtbConfig(ortbConfig); + public void setImpOrtbConfig(@Nullable String ortbConfig) { + configuration.setImpOrtbConfig(ortbConfig); } } diff --git a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/NativeAdUnit.java b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/NativeAdUnit.java index f2295545c..1ca894d67 100644 --- a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/NativeAdUnit.java +++ b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/NativeAdUnit.java @@ -230,9 +230,9 @@ public NativeAdUnitConfiguration getNativeConfiguration() { } @Nullable - public String getOrtbConfig() {return configuration.getOrtbConfig();} + public String getImpOrtbConfig() {return configuration.getImpOrtbConfig();} - public void setOrtbConfig(@Nullable String ortbConfig) {configuration.setOrtbConfig(ortbConfig);} + public void setImpOrtbConfig(@Nullable String ortbConfig) {configuration.setImpOrtbConfig(ortbConfig);} } diff --git a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/OpenRtbMerger.java b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/OpenRtbMerger.java new file mode 100644 index 000000000..b76c4c55c --- /dev/null +++ b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/OpenRtbMerger.java @@ -0,0 +1,178 @@ +package org.prebid.mobile; + +import android.os.Build; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import org.jetbrains.annotations.NotNull; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + +import java.util.Iterator; + +/** + * The OpenRtbMerger class provides functionality to merge a given JSON request object + * with an OpenRTB string representation. + */ +public class OpenRtbMerger { + + private static final String TAG = "OpenRtbMerger"; + + private OpenRtbMerger() { + } + + /** + * It merges the SDK originalRequest and OpenRTB string. + * + * @param originalRequest original request + * @param openRtb OpenRTB string + * @return merged JSON object + */ + @NonNull + public static JSONObject globalMerge(@NonNull JSONObject originalRequest, String openRtb) { + if (openRtb == null || openRtb.isEmpty()) { + return originalRequest; + } + + try { + JSONObject openRtbJson = new JSONObject(openRtb); + removeSensitiveData(openRtbJson); + return merge(originalRequest, openRtbJson); + } catch (Exception e) { + LogUtil.error(TAG, "Can't merge OpenRTB config: " + e.getMessage()); + } + + return originalRequest; + } + + @NonNull + private static JSONObject merge(JSONObject requestJsonRoot, JSONObject openRtbJsonRoot) throws JSONException { + for (Iterator it = openRtbJsonRoot.keys(); it.hasNext(); ) { + String openRtbKey = it.next(); + Object openRtbValue = openRtbJsonRoot.opt(openRtbKey); + + boolean newFieldForRequest = !requestJsonRoot.has(openRtbKey); + if (newFieldForRequest) { + requestJsonRoot.put(openRtbKey, openRtbValue); + continue; + } + + Object requestValue = requestJsonRoot.opt(openRtbKey); + if (openRtbValue instanceof JSONObject openRtbJson && requestValue instanceof JSONObject requestJson) { + merge(requestJson, openRtbJson); + continue; + } + + if (openRtbValue instanceof JSONArray openRtbJsonArray && requestValue instanceof JSONArray requestJsonArray) { + merge(requestJsonArray, openRtbJsonArray, openRtbKey, requestJsonRoot); + continue; + } + + requestJsonRoot.put(openRtbKey, openRtbValue); + } + return requestJsonRoot; + } + + private static void merge(JSONArray requestJsonArray, JSONArray openRtbJsonArray, String key, JSONObject parentJson) throws JSONException { + if (openRtbJsonArray.length() == 0) { + return; + } + + if (requestJsonArray.length() == 0) { + for (int i = 0; i < openRtbJsonArray.length(); i++) { + requestJsonArray.put(i, openRtbJsonArray.get(i)); + } + return; + } + + boolean differentItemTypes = requestJsonArray.opt(0).getClass() != openRtbJsonArray.opt(0).getClass(); + if (differentItemTypes) { + LogUtil.verbose(TAG, "JSON arrays of different types. Rewriting with OpenRTB values..."); + parentJson.put(key, openRtbJsonArray); + return; + } + + for (int i = 0; i < openRtbJsonArray.length(); i++) { + Object openRtbValue = openRtbJsonArray.get(i); + requestJsonArray.put(openRtbValue); + } + } + + private static void removeSensitiveData(@NonNull JSONObject openRtbJson) { + JSONObject userJson = openRtbJson.optJSONObject("user"); + JSONObject extJson = userJson != null ? userJson.optJSONObject("ext") : null; + removeFields(extJson, FIELDS_USER_EXT); + + removeFields(openRtbJson.optJSONObject("regs"), FIELDS_REGS); + removeFields(openRtbJson.optJSONObject("geo"), FIELDS_GEO); + removeFields(openRtbJson.optJSONObject("device"), FIELDS_DEVICE); + } + + private static void removeFields(@Nullable JSONObject json, String... fields) { + if (json == null) return; + + for (String field : fields) { + json.remove(field); + } + } + + + private static final String[] FIELDS_USER_EXT = { + "consent" + }; + + private static final String[] FIELDS_REGS = { + "gdpr", + "us_privacy", + "coppa" + }; + + private static final String[] FIELDS_GEO = { + "lat", + "lon", + "type", + "accuracy", + "lastfix", + "country", + "region", + "regionfips104", + "metro", + "city", + "zip", + "utcoffset" + }; + + private static final String[] FIELDS_DEVICE = { + "ua", + "dnt", + "lmt", + "ip", + "ipv6", + "devicetype", + "make", + "model", + "os", + "osv", + "hwv", + "flashver", + "language", + "carrier", + "mccmnc", + "ifa", + "didsha1", + "didmd5", + "dpidsha1", + "dpidmd5", + "h", + "w", + "ppi", + "js", + "connectiontype", + "pxratio", + "geo", + "ext" + }; + +} diff --git a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/TargetingParams.java b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/TargetingParams.java index 69095b7e0..e72f089fc 100644 --- a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/TargetingParams.java +++ b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/TargetingParams.java @@ -57,6 +57,8 @@ public class TargetingParams { private static String omidPartnerName; private static String omidPartnerVersion; private static String userCustomData; + @Nullable + private static String openRtbConfig; private static Pair userLatLon; private static Ext userExt; private static JSONArray extendedUserIds; @@ -795,6 +797,18 @@ public static Boolean getDeviceAccessConsent() { return UserConsentUtils.tryToGetDeviceAccessConsent(); } + @Nullable + public static String getGlobalOrtbConfig() { + return openRtbConfig; + } + + /** + * Sets global OpenRTB JSON string for merging with the original request. + */ + public static void setGlobalOrtbConfig(String config) { + openRtbConfig = config; + } + /* -------------------- Ext -------------------- */ diff --git a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/VideoBaseAdUnit.java b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/VideoBaseAdUnit.java index b984a78e0..61c19708e 100644 --- a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/VideoBaseAdUnit.java +++ b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/VideoBaseAdUnit.java @@ -43,9 +43,9 @@ public void setVideoParameters(@Nullable VideoParameters parameters) { } @Nullable - public String getOrtbConfig() { return configuration.getOrtbConfig(); } + public String getImpOrtbConfig() { return configuration.getImpOrtbConfig(); } - public void setOrtbConfig(@Nullable String ortbConfig) { configuration.setOrtbConfig(ortbConfig);} + public void setImpOrtbConfig(@Nullable String ortbConfig) { configuration.setImpOrtbConfig(ortbConfig);} /** * @deprecated use `setVideoParameters()` diff --git a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/api/mediation/MediationBaseAdUnit.java b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/api/mediation/MediationBaseAdUnit.java index fd0ee6b27..7ac3f06ec 100644 --- a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/api/mediation/MediationBaseAdUnit.java +++ b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/api/mediation/MediationBaseAdUnit.java @@ -322,12 +322,12 @@ private void cancelRefresh() { } @Nullable - public String getOrtbConfig() { - return adUnitConfig.getOrtbConfig(); + public String getImpOrtbConfig() { + return adUnitConfig.getImpOrtbConfig(); } - public void setOrtbConfig(@Nullable String ortbConfig) { - adUnitConfig.setOrtbConfig(ortbConfig); + public void setImpOrtbConfig(@Nullable String ortbConfig) { + adUnitConfig.setImpOrtbConfig(ortbConfig); } } diff --git a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/api/rendering/BannerView.java b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/api/rendering/BannerView.java index b020e92a4..d49645246 100644 --- a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/api/rendering/BannerView.java +++ b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/api/rendering/BannerView.java @@ -688,12 +688,12 @@ public BidResponse getBidResponse() { } @Nullable - public String getOrtbConfig() { - return adUnitConfig.getOrtbConfig(); + public String getImpOrtbConfig() { + return adUnitConfig.getImpOrtbConfig(); } - public void setOrtbConfig(@Nullable String ortbConfig) { - adUnitConfig.setOrtbConfig(ortbConfig); + public void setImpOrtbConfig(@Nullable String ortbConfig) { + adUnitConfig.setImpOrtbConfig(ortbConfig); } //region ==================== HelperMethods for Unit Tests. Should be used only in tests diff --git a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/api/rendering/BaseInterstitialAdUnit.java b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/api/rendering/BaseInterstitialAdUnit.java index f5bb7bf99..d998069fa 100644 --- a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/api/rendering/BaseInterstitialAdUnit.java +++ b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/api/rendering/BaseInterstitialAdUnit.java @@ -282,12 +282,12 @@ public void clearUserData() { } @Nullable - public String getOrtbConfig() { - return adUnitConfig.getOrtbConfig(); + public String getImpOrtbConfig() { + return adUnitConfig.getImpOrtbConfig(); } - public void setOrtbConfig(@Nullable String ortbConfig) { - adUnitConfig.setOrtbConfig(ortbConfig); + public void setImpOrtbConfig(@Nullable String ortbConfig) { + adUnitConfig.setImpOrtbConfig(ortbConfig); } diff --git a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/api/rendering/DisplayView.java b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/api/rendering/DisplayView.java index fded8f015..94d831fde 100644 --- a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/api/rendering/DisplayView.java +++ b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/api/rendering/DisplayView.java @@ -92,11 +92,11 @@ public void destroy() { } @Nullable - public String getOrtbConfig() { - return adUnitConfiguration.getOrtbConfig(); + public String getImpOrtbConfig() { + return adUnitConfiguration.getImpOrtbConfig(); } - public void setOrtbConfig(@Nullable String ortbConfig) { - adUnitConfiguration.setOrtbConfig(ortbConfig); + public void setImpOrtbConfig(@Nullable String ortbConfig) { + adUnitConfiguration.setImpOrtbConfig(ortbConfig); } } diff --git a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/api/rendering/PrebidDisplayView.java b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/api/rendering/PrebidDisplayView.java index 2aecdd72c..74db9efc8 100644 --- a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/api/rendering/PrebidDisplayView.java +++ b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/api/rendering/PrebidDisplayView.java @@ -331,12 +331,12 @@ private static BidResponse getBidResponseFromCache(String id) throws AdException } @Nullable - public String getOrtbConfig() { - return adUnitConfiguration.getOrtbConfig(); + public String getImpOrtbConfig() { + return adUnitConfiguration.getImpOrtbConfig(); } - public void setOrtbConfig(@Nullable String ortbConfig) { - adUnitConfiguration.setOrtbConfig(ortbConfig); + public void setImpOrtbConfig(@Nullable String ortbConfig) { + adUnitConfiguration.setImpOrtbConfig(ortbConfig); } } diff --git a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/configuration/AdUnitConfiguration.java b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/configuration/AdUnitConfiguration.java index 3ca8c41b7..09782532f 100644 --- a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/configuration/AdUnitConfiguration.java +++ b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/configuration/AdUnitConfiguration.java @@ -58,7 +58,7 @@ public class AdUnitConfiguration { @Nullable private String gpid; @Nullable - private String ortbConfig; + private String impOrtbConfig; private Position closeButtonPosition = Position.TOP_RIGHT; private Position skipButtonPosition = Position.TOP_RIGHT; @@ -543,12 +543,12 @@ public void setGpid(@Nullable String gpid) { } @Nullable - public String getOrtbConfig() { - return ortbConfig; + public String getImpOrtbConfig() { + return impOrtbConfig; } - public void setOrtbConfig(@Nullable String ortbConfig) { - this.ortbConfig = ortbConfig; + public void setImpOrtbConfig(@Nullable String impOrtbConfig) { + this.impOrtbConfig = impOrtbConfig; } @Override diff --git a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/models/openrtb/BidRequest.java b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/models/openrtb/BidRequest.java index 5ee282ba3..0d9c8b936 100644 --- a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/models/openrtb/BidRequest.java +++ b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/models/openrtb/BidRequest.java @@ -23,13 +23,13 @@ import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; -import org.prebid.mobile.LogUtil; +import org.prebid.mobile.OpenRtbMerger; import org.prebid.mobile.PrebidMobile; +import org.prebid.mobile.TargetingParams; import org.prebid.mobile.rendering.models.openrtb.bidRequests.*; import org.prebid.mobile.rendering.models.openrtb.bidRequests.source.Source; import java.util.ArrayList; -import java.util.Iterator; public class BidRequest extends BaseBid { @@ -41,22 +41,19 @@ public class BidRequest extends BaseBid { private User user = null; private Source source = null; @Nullable - private JSONObject arbitraryJSONConfig; - @Nullable - private String ortbConfig; + private String impOrtbConfig; private Ext ext = null; public JSONObject getJsonObject() throws JSONException { JSONObject jsonObject = new JSONObject(); - if (arbitraryJSONConfig != null) { - deepMerge(arbitraryJSONConfig, jsonObject); - } if (imps != null && imps.size() > 0) { JSONArray jsonArray = new JSONArray(); for (Imp i : imps) { - jsonArray.put(i.getJsonObject()); + JSONObject impJson = i.getJsonObject(); + impJson = OpenRtbMerger.globalMerge(impJson, impOrtbConfig); + jsonArray.put(impJson); } toJSON(jsonObject, "imp", jsonArray); @@ -70,73 +67,10 @@ public JSONObject getJsonObject() throws JSONException { toJSON(jsonObject, "source", source != null ? source.getJsonObject() : null); toJSON(jsonObject, "ext", ext != null ? ext.getJsonObject() : null); toJSON(jsonObject, "test", PrebidMobile.getPbsDebug() ? 1 : null); - jsonObject = mergeOrtbConfig(jsonObject); + jsonObject = OpenRtbMerger.globalMerge(jsonObject, TargetingParams.getGlobalOrtbConfig()); return jsonObject; } - private JSONObject mergeOrtbConfig(JSONObject bidRequestJson) { - try { - if (ortbConfig == null) { - return bidRequestJson; - } - JSONObject ortbConfigObject = new JSONObject(ortbConfig); - //remove protected fields - if (ortbConfigObject.has("regs")) { - ortbConfigObject.remove("regs"); - } - if (ortbConfigObject.has("device")) { - ortbConfigObject.remove("device"); - } - if (ortbConfigObject.has("geo")) { - ortbConfigObject.remove("geo"); - } - if (ortbConfigObject.has("ext")) { - if (ortbConfigObject.get("ext") instanceof JSONObject) { - ortbConfigObject.getJSONObject("ext").remove("gdpr"); - ortbConfigObject.getJSONObject("ext").remove("us_privacy"); - ortbConfigObject.getJSONObject("ext").remove("consent"); - } - } - return deepMerge(ortbConfigObject, bidRequestJson); - } catch(Exception e) { - LogUtil.error("ORTBConfig is not valid JSON"); - return bidRequestJson; - } - } - - /** - * Merge "source" into "target". If fields have equal name, merge them recursively. - * @return the merged object (target). - */ - private static JSONObject deepMerge(JSONObject source, JSONObject target) throws JSONException { - for (Iterator it = source.keys(); it.hasNext(); ) { - String key = it.next(); - Object value = source.get(key); - if (!target.has(key)) { - // new value for "key": - target.put(key, value); - } else { - // existing value for "key" - recursively deep merge: - if (value instanceof JSONObject) { - JSONObject valueJson = (JSONObject) value; - deepMerge(valueJson, target.getJSONObject(key)); - } else if (value instanceof JSONArray) { - if (target.get(key) instanceof JSONArray) { - JSONArray sourceArray = (JSONArray) value; - for (int i = 0; i < sourceArray.length(); i++) { - target.getJSONArray(key).put(sourceArray.getJSONObject(i)); - } - } - } else { - target.put(key, value); - } - } - } - return target; - } - - // Accessors to prevent NPE while maintaining null if object is not set - // App public App getApp() { if (app == null) { @@ -227,20 +161,11 @@ public Ext getExt() { } @Nullable - public JSONObject getArbitraryConfig() { - return arbitraryJSONConfig; - } - - public void setArbitraryConfig(@Nullable JSONObject config) { - this.arbitraryJSONConfig = config; - } - - @Nullable - public String getOrtbConfig() { - return ortbConfig; + public String getImpOrtbConfig() { + return impOrtbConfig; } - public void setOrtbConfig(@Nullable String ortbConfig) { - this.ortbConfig = ortbConfig; + public void setImpOrtbConfig(@Nullable String impOrtbConfig) { + this.impOrtbConfig = impOrtbConfig; } } diff --git a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/models/openrtb/bidRequests/Device.java b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/models/openrtb/bidRequests/Device.java index b18d94d5d..24fa666d8 100644 --- a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/models/openrtb/bidRequests/Device.java +++ b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/models/openrtb/bidRequests/Device.java @@ -75,6 +75,9 @@ public class Device extends BaseBid { private Ext ext; + /** + * When you add a new field to this list, don't forget to add it to the {@link org.prebid.mobile.OpenRtbMerger}. + */ public JSONObject getJsonObject() throws JSONException { JSONObject jsonObject = new JSONObject(); diff --git a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/models/openrtb/bidRequests/Regs.java b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/models/openrtb/bidRequests/Regs.java index 779c5e0b3..aca2c6240 100644 --- a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/models/openrtb/bidRequests/Regs.java +++ b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/models/openrtb/bidRequests/Regs.java @@ -34,6 +34,9 @@ public class Regs extends BaseBid { @Nullable private JSONArray gppSid; + /** + * When you add a new field to this list, don't forget to add it to the {@link org.prebid.mobile.OpenRtbMerger}. + */ public JSONObject getJsonObject() throws JSONException { JSONObject jsonObject = new JSONObject(); diff --git a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/models/openrtb/bidRequests/geo/Geo.java b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/models/openrtb/bidRequests/geo/Geo.java index 7a1c1901f..bb5c1cfea 100644 --- a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/models/openrtb/bidRequests/geo/Geo.java +++ b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/models/openrtb/bidRequests/geo/Geo.java @@ -40,6 +40,9 @@ public class Geo extends BaseBid { public String zip = null; public Integer utcoffset = null; + /** + * When you add a new field to this list, don't forget to add it to the {@link org.prebid.mobile.OpenRtbMerger}. + */ public JSONObject getJsonObject() throws JSONException { JSONObject jsonObject = new JSONObject(); toJSON(jsonObject, "lat", this.lat); diff --git a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/networking/parameters/BasicParameterBuilder.java b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/networking/parameters/BasicParameterBuilder.java index 84ce89725..b8461b134 100644 --- a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/networking/parameters/BasicParameterBuilder.java +++ b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/networking/parameters/BasicParameterBuilder.java @@ -32,6 +32,7 @@ import org.prebid.mobile.BannerParameters; import org.prebid.mobile.DataObject; import org.prebid.mobile.ExternalUserId; +import org.prebid.mobile.OpenRtbMerger; import org.prebid.mobile.PrebidMobile; import org.prebid.mobile.Signals; import org.prebid.mobile.TargetingParams; @@ -140,7 +141,7 @@ private void configureImpObject(Imp imp, String uuid) { private void configureBidRequest(BidRequest bidRequest, String uuid) { bidRequest.setId(uuid); - bidRequest.setOrtbConfig(adConfiguration.getOrtbConfig()); + bidRequest.setImpOrtbConfig(adConfiguration.getImpOrtbConfig()); boolean isVideo = adConfiguration.isAdType(AdFormat.VAST); bidRequest.getExt().put("prebid", Prebid.getJsonObjectForBidRequest(PrebidMobile.getPrebidServerAccountId(), isVideo, adConfiguration)); //if coppaEnabled - set 1, else No coppa is sent diff --git a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/views/base/BaseAdView.java b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/views/base/BaseAdView.java index be5c8e2ff..130eff9b0 100644 --- a/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/views/base/BaseAdView.java +++ b/PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/rendering/views/base/BaseAdView.java @@ -138,12 +138,12 @@ public void destroy() { @Nullable - public String getOrtbConfig() { - return adViewManager.getAdConfiguration().getOrtbConfig(); + public String getImpOrtbConfig() { + return adViewManager.getAdConfiguration().getImpOrtbConfig(); } - public void setOrtbConfig(@Nullable String ortbConfig) { - adViewManager.getAdConfiguration().setOrtbConfig(ortbConfig); + public void setImpOrtbConfig(@Nullable String ortbConfig) { + adViewManager.getAdConfiguration().setImpOrtbConfig(ortbConfig); } } diff --git a/PrebidMobile/PrebidMobile-core/src/test/java/org/prebid/mobile/OpenRtbMergerTest.java b/PrebidMobile/PrebidMobile-core/src/test/java/org/prebid/mobile/OpenRtbMergerTest.java new file mode 100644 index 000000000..5ffffdb74 --- /dev/null +++ b/PrebidMobile/PrebidMobile-core/src/test/java/org/prebid/mobile/OpenRtbMergerTest.java @@ -0,0 +1,134 @@ +package org.prebid.mobile; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.github.fge.jsonpatch.diff.JsonDiff; + +import org.json.JSONException; +import org.json.JSONObject; +import org.junit.Test; +import org.prebid.mobile.test.utils.ResourceUtils; + +public class OpenRtbMergerTest { + + @Test + public void merge_emptyOpenRtb() throws JSONException { + String request = "{}"; + String openRtb = ""; + + JSONObject mergedJson = merge(request, openRtb); + + assertJsonEquals("{}", mergedJson.toString()); + } + + @Test + public void merge_wrongJson() throws JSONException { + String request = "{}"; + String openRtb = "not a json string"; + + JSONObject mergedJson = merge(request, openRtb); + + assertJsonEquals("{}", mergedJson.toString()); + } + + @Test + public void mergeSensitiveData_emptyRequest_emptyResult() throws JSONException { + String request = "{}"; + String openRtb = fromResources("sensitive_data_fake.json"); + + JSONObject mergedJson = merge(request, openRtb); + + assertJsonEquals(fromResources("sensitive_data_empty.json"), mergedJson.toString()); + } + + @Test + public void mergeSensitiveData_fullRequest_requestFieldsAreNotChanged() throws JSONException { + String request = fromResources("sensitive_data_real.json"); + String openRtb = fromResources("sensitive_data_fake.json"); + + JSONObject mergedJson = merge(request, openRtb); + + assertJsonEquals(request, mergedJson.toString()); + } + + @Test + public void merge_differentTypes() throws JSONException { + String request = "{}"; + String openRtb = fromResources("merge_all_types.json"); + + JSONObject mergedJson = merge(request, openRtb); + + assertJsonEquals(openRtb, mergedJson.toString()); + } + + @Test + public void mergeComplex_withReplace() throws JSONException { + String request = fromResources("merge_with_replace_request.json"); + String openRtb = fromResources("merge_with_replace_openrtb.json"); + + JSONObject mergedJson = merge(request, openRtb); + + String result = fromResources("merge_with_replace_result.json"); + assertJsonEquals(result, mergedJson.toString()); + } + + @Test + public void merge_replaceWithNewType() throws JSONException { + String request = fromResources("merge_replace_with_new_type_request.json"); + String openRtb = fromResources("merge_replace_with_new_type_openrtb.json"); + + JSONObject mergedJson = merge(request, openRtb); + + assertJsonEquals(openRtb, mergedJson.toString()); + } + + @Test + public void merge_arrayPrimitives() throws JSONException { + String request = fromResources("merge_arrays_primitives_request.json"); + String openRtb = fromResources("merge_arrays_primitives_openrtb.json"); + + JSONObject mergedJson = merge(request, openRtb); + + String result = fromResources("merge_arrays_primitives_result.json"); + assertJsonEquals(result, mergedJson.toString()); + } + + @Test + public void merge_arrayObjects() throws JSONException { + String request = fromResources("merge_arrays_objects_request.json"); + String openRtb = fromResources("merge_arrays_objects_openrtb.json"); + + JSONObject mergedJson = merge(request, openRtb); + + String result = fromResources("merge_arrays_objects_result.json"); + assertJsonEquals(result, mergedJson.toString()); + } + + private JSONObject merge(String request, String openRtb) throws JSONException { + JSONObject requestJson = new JSONObject(request); + return OpenRtbMerger.globalMerge(requestJson, openRtb); + } + + private String fromResources(String path) { + return ResourceUtils.convertResourceToString("OpenRtbMerger/" + path); + } + + private void assertJsonEquals(String json1, String json2) { + try { + ObjectMapper mapper = new ObjectMapper(); + JsonNode beforeNode = mapper.readTree(json1); + JsonNode afterNode = mapper.readTree(json2); + + String difference = JsonDiff.asJson(beforeNode, afterNode).toString(); + if (difference.equals("[]")) { + return; + } + + throw new AssertionError("Json values are different: " + difference); + } catch (JsonProcessingException e) { + throw new NullPointerException("Can't compare: " + e.getMessage()); + } + } + +} \ No newline at end of file diff --git a/PrebidMobile/PrebidMobile-core/src/test/java/org/prebid/mobile/PrebidNativeAdTest.java b/PrebidMobile/PrebidMobile-core/src/test/java/org/prebid/mobile/PrebidNativeAdTest.java index 7f2475834..b3941c190 100644 --- a/PrebidMobile/PrebidMobile-core/src/test/java/org/prebid/mobile/PrebidNativeAdTest.java +++ b/PrebidMobile/PrebidMobile-core/src/test/java/org/prebid/mobile/PrebidNativeAdTest.java @@ -108,13 +108,9 @@ public void nativeAdParser() { private PrebidNativeAd nativeAdFromFile(String path) { - try { - String resource = ResourceUtils.convertResourceToString(path); - String cacheId = CacheManager.save(resource); - return PrebidNativeAd.create(cacheId); - } catch (IOException e) { - throw new NullPointerException(e.getMessage()); - } + String resource = ResourceUtils.convertResourceToString(path); + String cacheId = CacheManager.save(resource); + return PrebidNativeAd.create(cacheId); } private View createViewMock() { diff --git a/PrebidMobile/PrebidMobile-core/src/test/java/org/prebid/mobile/rendering/networking/WinNotifierTest.java b/PrebidMobile/PrebidMobile-core/src/test/java/org/prebid/mobile/rendering/networking/WinNotifierTest.java index 592fc45bb..95bd8be0f 100644 --- a/PrebidMobile/PrebidMobile-core/src/test/java/org/prebid/mobile/rendering/networking/WinNotifierTest.java +++ b/PrebidMobile/PrebidMobile-core/src/test/java/org/prebid/mobile/rendering/networking/WinNotifierTest.java @@ -258,12 +258,7 @@ public MockResponse dispatch( String adMarkup = ""; switch (path) { case "/cache?uuid=id": - try { - adMarkup = ResourceUtils.convertResourceToString(PATH_BID_SHORT_JSON); - } - catch (IOException e) { - e.printStackTrace(); - } + adMarkup = ResourceUtils.convertResourceToString(PATH_BID_SHORT_JSON); break; case "/cache?uuid=nurl": case "/cache?uuid=uuid": diff --git a/PrebidMobile/PrebidMobile-core/src/test/java/org/prebid/mobile/rendering/networking/parameters/BasicParameterBuilderTest.java b/PrebidMobile/PrebidMobile-core/src/test/java/org/prebid/mobile/rendering/networking/parameters/BasicParameterBuilderTest.java index 4a3ae0bc7..791ccdafa 100644 --- a/PrebidMobile/PrebidMobile-core/src/test/java/org/prebid/mobile/rendering/networking/parameters/BasicParameterBuilderTest.java +++ b/PrebidMobile/PrebidMobile-core/src/test/java/org/prebid/mobile/rendering/networking/parameters/BasicParameterBuilderTest.java @@ -127,6 +127,7 @@ public void cleanup() throws Exception { TargetingParams.setYearOfBirth(0); TargetingParams.setOmidPartnerName(null); TargetingParams.setOmidPartnerVersion(null); + TargetingParams.setGlobalOrtbConfig(null); PrebidMobile.sendMraidSupportParams = true; PrebidMobile.useExternalBrowser = false; @@ -350,10 +351,10 @@ public void setGpid_gpidPresentInRequest() { } @Test - public void setOrtbConfig_configPresentInRequest() { + public void setImpOrtbConfig_configPresentInRequest() { AdUnitConfiguration adConfiguration = new AdUnitConfiguration(); String ortbConfig = "{\"arbitraryparamkey1\":\"arbitraryparamvalue1\",\"ext\":{\"otherExtParam\":\"otherParam\"}}"; - adConfiguration.setOrtbConfig(ortbConfig); + TargetingParams.setGlobalOrtbConfig(ortbConfig); BasicParameterBuilder builder = new BasicParameterBuilder( adConfiguration, @@ -373,10 +374,10 @@ public void setOrtbConfig_configPresentInRequest() { } @Test - public void setOrtbConfig_invalidJSONInRequest() { + public void setImpOrtbConfig_invalidJSONInRequest() { AdUnitConfiguration adConfiguration = new AdUnitConfiguration(); String ortbConfig = "\"arbitraryparamkey1\":\"arbitraryparamvalue1\"}"; - adConfiguration.setOrtbConfig(ortbConfig); + adConfiguration.setImpOrtbConfig(ortbConfig); BasicParameterBuilder builder = new BasicParameterBuilder( adConfiguration, @@ -395,10 +396,10 @@ public void setOrtbConfig_invalidJSONInRequest() { } @Test - public void setOrtbConfig_illegalParametersPresentInRequest() { + public void setImpOrtbConfig_illegalParametersPresentInRequest() { AdUnitConfiguration adConfiguration = new AdUnitConfiguration(); - String ortbConfig = "{\"arbitraryparamkey1\":\"arbitraryparamvalue1\", \"regs\": \"no regs here\", \"ext\":{\"gdpr\":\"no GDPR here\", \"otherExtParam\":\"otherParam\"}}"; - adConfiguration.setOrtbConfig(ortbConfig); + String ortbConfig = "{\"arbitraryparamkey1\":\"arbitraryparamvalue1\", \"ext\":{\"otherExtParam\":\"otherParam\"}}"; + TargetingParams.setGlobalOrtbConfig(ortbConfig); BasicParameterBuilder builder = new BasicParameterBuilder( adConfiguration, @@ -412,8 +413,6 @@ public void setOrtbConfig_illegalParametersPresentInRequest() { try { assertEquals("arbitraryparamvalue1", actualBidRequest.getJsonObject().getString("arbitraryparamkey1")); assertEquals("otherParam", actualBidRequest.getJsonObject().getJSONObject("ext").getString("otherExtParam")); - assertFalse(actualBidRequest.getJsonObject().getJSONObject("ext").has("gdpr")); - assertFalse(actualBidRequest.getJsonObject().has("regs")); } catch (Exception e) { fail(); } diff --git a/PrebidMobile/PrebidMobile-core/src/test/resources/OpenRtbMerger/merge_all_types.json b/PrebidMobile/PrebidMobile-core/src/test/resources/OpenRtbMerger/merge_all_types.json new file mode 100644 index 000000000..7d51a273c --- /dev/null +++ b/PrebidMobile/PrebidMobile-core/src/test/resources/OpenRtbMerger/merge_all_types.json @@ -0,0 +1,22 @@ +{ + "field_int": 1, + "field_string": "test", + "field_double": 2.5, + "field_boolean": true, + "object": { + "subfield_1": 3, + "subfield_2": "inner", + "sub_object": { + "subfield_3": true, + "subfield_4": [ + 1,2,3 + ] + } + }, + "array_int": [ + 1,2,3,4 + ], + "array_string": [ + "hello", "world" + ] +} \ No newline at end of file diff --git a/PrebidMobile/PrebidMobile-core/src/test/resources/OpenRtbMerger/merge_arrays_objects_openrtb.json b/PrebidMobile/PrebidMobile-core/src/test/resources/OpenRtbMerger/merge_arrays_objects_openrtb.json new file mode 100644 index 000000000..06de6e03f --- /dev/null +++ b/PrebidMobile/PrebidMobile-core/src/test/resources/OpenRtbMerger/merge_arrays_objects_openrtb.json @@ -0,0 +1,11 @@ +{ + "imp": [ + { + "number": 2, + "adm": "", + "sizes": [ + "320x50", "300x250" + ] + } + ] +} \ No newline at end of file diff --git a/PrebidMobile/PrebidMobile-core/src/test/resources/OpenRtbMerger/merge_arrays_objects_request.json b/PrebidMobile/PrebidMobile-core/src/test/resources/OpenRtbMerger/merge_arrays_objects_request.json new file mode 100644 index 000000000..6a9b25137 --- /dev/null +++ b/PrebidMobile/PrebidMobile-core/src/test/resources/OpenRtbMerger/merge_arrays_objects_request.json @@ -0,0 +1,8 @@ +{ + "imp": [ + { + "number": 1, + "adm": "" + } + ] +} \ No newline at end of file diff --git a/PrebidMobile/PrebidMobile-core/src/test/resources/OpenRtbMerger/merge_arrays_objects_result.json b/PrebidMobile/PrebidMobile-core/src/test/resources/OpenRtbMerger/merge_arrays_objects_result.json new file mode 100644 index 000000000..67222abca --- /dev/null +++ b/PrebidMobile/PrebidMobile-core/src/test/resources/OpenRtbMerger/merge_arrays_objects_result.json @@ -0,0 +1,15 @@ +{ + "imp": [ + { + "number": 1, + "adm": "" + }, + { + "number": 2, + "adm": "", + "sizes": [ + "320x50", "300x250" + ] + } + ] +} \ No newline at end of file diff --git a/PrebidMobile/PrebidMobile-core/src/test/resources/OpenRtbMerger/merge_arrays_primitives_openrtb.json b/PrebidMobile/PrebidMobile-core/src/test/resources/OpenRtbMerger/merge_arrays_primitives_openrtb.json new file mode 100644 index 000000000..0e5e50c59 --- /dev/null +++ b/PrebidMobile/PrebidMobile-core/src/test/resources/OpenRtbMerger/merge_arrays_primitives_openrtb.json @@ -0,0 +1,6 @@ +{ + "ints": [4, 5], + "strings": ["4", "5"], + "doubles": [0.4, 0.5], + "booleans": [false] +} \ No newline at end of file diff --git a/PrebidMobile/PrebidMobile-core/src/test/resources/OpenRtbMerger/merge_arrays_primitives_request.json b/PrebidMobile/PrebidMobile-core/src/test/resources/OpenRtbMerger/merge_arrays_primitives_request.json new file mode 100644 index 000000000..bcd9a58d5 --- /dev/null +++ b/PrebidMobile/PrebidMobile-core/src/test/resources/OpenRtbMerger/merge_arrays_primitives_request.json @@ -0,0 +1,6 @@ +{ + "ints": [1,2,3], + "strings": ["1", "2", "3"], + "doubles": [0.1, 0.2, 0.3], + "booleans": [true] +} \ No newline at end of file diff --git a/PrebidMobile/PrebidMobile-core/src/test/resources/OpenRtbMerger/merge_arrays_primitives_result.json b/PrebidMobile/PrebidMobile-core/src/test/resources/OpenRtbMerger/merge_arrays_primitives_result.json new file mode 100644 index 000000000..1a6acfd14 --- /dev/null +++ b/PrebidMobile/PrebidMobile-core/src/test/resources/OpenRtbMerger/merge_arrays_primitives_result.json @@ -0,0 +1,6 @@ +{ + "ints": [1,2,3,4, 5], + "strings": ["1", "2", "3","4", "5"], + "doubles": [0.1, 0.2, 0.3, 0.4, 0.5], + "booleans": [true, false] +} \ No newline at end of file diff --git a/PrebidMobile/PrebidMobile-core/src/test/resources/OpenRtbMerger/merge_replace_with_new_type_openrtb.json b/PrebidMobile/PrebidMobile-core/src/test/resources/OpenRtbMerger/merge_replace_with_new_type_openrtb.json new file mode 100644 index 000000000..a3e073e83 --- /dev/null +++ b/PrebidMobile/PrebidMobile-core/src/test/resources/OpenRtbMerger/merge_replace_with_new_type_openrtb.json @@ -0,0 +1,11 @@ +{ + "type_1": "str", + "type_2": 1, + "type_3": 0.5, + "type_4": true, + "type_5": [ + 1, + 2, + 3 + ] +} \ No newline at end of file diff --git a/PrebidMobile/PrebidMobile-core/src/test/resources/OpenRtbMerger/merge_replace_with_new_type_request.json b/PrebidMobile/PrebidMobile-core/src/test/resources/OpenRtbMerger/merge_replace_with_new_type_request.json new file mode 100644 index 000000000..be3115c73 --- /dev/null +++ b/PrebidMobile/PrebidMobile-core/src/test/resources/OpenRtbMerger/merge_replace_with_new_type_request.json @@ -0,0 +1,9 @@ +{ + "type_1": 1, + "type_2": 0.2, + "type_3": true, + "type_4": "str", + "type_5": { + "field": "test" + } +} \ No newline at end of file diff --git a/PrebidMobile/PrebidMobile-core/src/test/resources/OpenRtbMerger/merge_with_replace_openrtb.json b/PrebidMobile/PrebidMobile-core/src/test/resources/OpenRtbMerger/merge_with_replace_openrtb.json new file mode 100644 index 000000000..09521dea4 --- /dev/null +++ b/PrebidMobile/PrebidMobile-core/src/test/resources/OpenRtbMerger/merge_with_replace_openrtb.json @@ -0,0 +1,34 @@ +{ + "field_int": 2, + "field_string": "replaced", + "field_double": 3.5, + "field_boolean": false, + "field_simple": { + "subfield_1": "str", + "subfield_2": 11 + }, + "object": { + "subfield_1": 4, + "subfield_2": "inner_replaced", + "sub_object": { + "subfield_3": false, + "subfield_4": [ + 4, 5 + ] + } + }, + "array_int": [ + 1,2,3 + ], + "array_string": [ + "!" + ], + "new_field": "yes", + "new_object": { + "subobject": { + "ext": { + "type": "test" + } + } + } +} \ No newline at end of file diff --git a/PrebidMobile/PrebidMobile-core/src/test/resources/OpenRtbMerger/merge_with_replace_request.json b/PrebidMobile/PrebidMobile-core/src/test/resources/OpenRtbMerger/merge_with_replace_request.json new file mode 100644 index 000000000..6da8f3efe --- /dev/null +++ b/PrebidMobile/PrebidMobile-core/src/test/resources/OpenRtbMerger/merge_with_replace_request.json @@ -0,0 +1,21 @@ +{ + "field_int": 1, + "field_string": "test", + "field_double": 2.5, + "field_boolean": true, + "field_simple": 10, + "object": { + "subfield_1": 3, + "subfield_2": "inner", + "sub_object": { + "subfield_3": true, + "subfield_4": [ + 1,2,3 + ] + } + }, + "array_int": [], + "array_string": [ + "hello", "world" + ] +} \ No newline at end of file diff --git a/PrebidMobile/PrebidMobile-core/src/test/resources/OpenRtbMerger/merge_with_replace_result.json b/PrebidMobile/PrebidMobile-core/src/test/resources/OpenRtbMerger/merge_with_replace_result.json new file mode 100644 index 000000000..a8386cd6e --- /dev/null +++ b/PrebidMobile/PrebidMobile-core/src/test/resources/OpenRtbMerger/merge_with_replace_result.json @@ -0,0 +1,42 @@ +{ + "field_int": 2, + "array_string": [ + "hello", + "world", + "!" + ], + "field_double": 3.5, + "field_boolean": false, + "field_string": "replaced", + "field_simple": { + "subfield_1": "str", + "subfield_2": 11 + }, + "object": { + "sub_object": { + "subfield_3": false, + "subfield_4": [ + 1, + 2, + 3, + 4, + 5 + ] + }, + "subfield_1": 4, + "subfield_2": "inner_replaced" + }, + "array_int": [ + 1, + 2, + 3 + ], + "new_field": "yes", + "new_object": { + "subobject": { + "ext": { + "type": "test" + } + } + } +} \ No newline at end of file diff --git a/PrebidMobile/PrebidMobile-core/src/test/resources/OpenRtbMerger/sensitive_data_empty.json b/PrebidMobile/PrebidMobile-core/src/test/resources/OpenRtbMerger/sensitive_data_empty.json new file mode 100644 index 000000000..a7f1713c7 --- /dev/null +++ b/PrebidMobile/PrebidMobile-core/src/test/resources/OpenRtbMerger/sensitive_data_empty.json @@ -0,0 +1,12 @@ +{ + "user": { + "ext": { + } + }, + "regs": { + }, + "geo": { + }, + "device": { + } +} \ No newline at end of file diff --git a/PrebidMobile/PrebidMobile-core/src/test/resources/OpenRtbMerger/sensitive_data_fake.json b/PrebidMobile/PrebidMobile-core/src/test/resources/OpenRtbMerger/sensitive_data_fake.json new file mode 100644 index 000000000..7f43138f1 --- /dev/null +++ b/PrebidMobile/PrebidMobile-core/src/test/resources/OpenRtbMerger/sensitive_data_fake.json @@ -0,0 +1,58 @@ +{ + "user": { + "ext": { + "consent": "fake" + } + }, + "regs": { + "gdpr": "fake", + "us_privacy": "fake", + "coppa": "fake" + }, + "geo": { + "lat": "fake", + "lon": "fake", + "type": "fake", + "accuracy": "fake", + "lastfix": "fake", + "country": "fake", + "region": "fake", + "regionfips104": "fake", + "metro": "fake", + "city": "fake", + "zip": "fake", + "utcoffset": "fake" + }, + "device": { + "ua": 123, + "dnt": 123.45, + "lmt": { + "fake": "fake" + }, + "ip": "fake", + "ipv6": "fake", + "devicetype": "fake", + "make": "fake", + "model": "fake", + "os": "fake", + "osv": "fake", + "hwv": "fake", + "flashver": "fake", + "language": "fake", + "carrier": "fake", + "mccmnc": "fake", + "ifa": "fake", + "didsha1": "fake", + "didmd5": "fake", + "dpidsha1": "fake", + "dpidmd5": "fake", + "h": "fake", + "w": "fake", + "ppi": "fake", + "js": "fake", + "connectiontype": "fake", + "pxratio": "fake", + "geo": "fake", + "ext": "fake" + } +} \ No newline at end of file diff --git a/PrebidMobile/PrebidMobile-core/src/test/resources/OpenRtbMerger/sensitive_data_real.json b/PrebidMobile/PrebidMobile-core/src/test/resources/OpenRtbMerger/sensitive_data_real.json new file mode 100644 index 000000000..ca59c407b --- /dev/null +++ b/PrebidMobile/PrebidMobile-core/src/test/resources/OpenRtbMerger/sensitive_data_real.json @@ -0,0 +1,56 @@ +{ + "user": { + "ext": { + "consent": "real" + } + }, + "regs": { + "gdpr": "real", + "us_privacy": "real", + "coppa": "real" + }, + "geo": { + "lat": "real", + "lon": "real", + "type": "real", + "accuracy": "real", + "lastfix": "real", + "country": "real", + "region": "real", + "regionfips104": "real", + "metro": "real", + "city": "real", + "zip": "real", + "utcoffset": "real" + }, + "device": { + "ua": "real", + "dnt": "real", + "lmt": "real", + "ip": "real", + "ipv6": "real", + "devicetype": "real", + "make": "real", + "model": "real", + "os": "real", + "osv": "real", + "hwv": "real", + "flashver": "real", + "language": "real", + "carrier": "real", + "mccmnc": "real", + "ifa": "real", + "didsha1": "real", + "didmd5": "real", + "dpidsha1": "real", + "dpidmd5": "real", + "h": "real", + "w": "real", + "ppi": "real", + "js": "real", + "connectiontype": "real", + "pxratio": "real", + "geo": "real", + "ext": "real" + } +} \ No newline at end of file diff --git a/PrebidMobile/test-utils/src/main/java/org/prebid/mobile/test/utils/ResourceUtils.java b/PrebidMobile/test-utils/src/main/java/org/prebid/mobile/test/utils/ResourceUtils.java index 2f07ae59d..ca21b9bdd 100644 --- a/PrebidMobile/test-utils/src/main/java/org/prebid/mobile/test/utils/ResourceUtils.java +++ b/PrebidMobile/test-utils/src/main/java/org/prebid/mobile/test/utils/ResourceUtils.java @@ -31,11 +31,15 @@ public class ResourceUtils { public final static String ACCEPT_HEADER = "Accept"; public final static String ACCEPT_HEADER_VALUE = "application/x-www-form-urlencoded,text/plain,text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"; - public static String convertResourceToString(String fileName) throws IOException { - InputStream fileStream = ResourceUtils.class.getClassLoader().getResourceAsStream(fileName); - - java.util.Scanner s = new java.util.Scanner(fileStream).useDelimiter("\\A"); - return s.hasNext() ? s.next() : ""; + public static String convertResourceToString(String fileName) { + try { + InputStream fileStream = ResourceUtils.class.getClassLoader().getResourceAsStream(fileName); + + java.util.Scanner s = new java.util.Scanner(fileStream).useDelimiter("\\A"); + return s.hasNext() ? s.next() : ""; + } catch (Exception exception) { + throw new NullPointerException("Can't find resource file " + fileName); + } } public static void assertJsonEquals(JSONObject expected, JSONObject actual) { diff --git a/PrebidMobile/tests.gradle b/PrebidMobile/tests.gradle index 83facf650..1d991e5e5 100644 --- a/PrebidMobile/tests.gradle +++ b/PrebidMobile/tests.gradle @@ -8,6 +8,10 @@ dependencies { testImplementation 'androidx.test:runner:1.4.0' testImplementation 'androidx.test:rules:1.4.0' + // JSON comparators + testImplementation "com.fasterxml.jackson.core:jackson-databind:2.14.3" + testImplementation "org.apache.camel:camel-json-patch:3.22.2" + testImplementation libs.robolectric testImplementation libs.shadows.httpclient