@@ -105,27 +105,88 @@ class SensitiveParamsManagerTest : FacebookPowerMockTestCase() {
105
105
@Test
106
106
fun `test fetched sensitive params list is not null from the server and no params need to be filtered` () {
107
107
initMockFetchedAppSettings(mockSensitiveParamsFromServer)
108
+
109
+ var mockInputParamsWithoutSensitiveParams = HashMap <String , String ?>()
110
+ mockInputParamsWithoutSensitiveParams[mockNonSensitiveParam] = mockNonSensitiveParamValue
111
+
108
112
enable()
109
- processFilterSensitiveParams(mockInputParams , mockEventNameWithoutSensitiveParams)
113
+ processFilterSensitiveParams(mockInputParamsWithoutSensitiveParams , mockEventNameWithoutSensitiveParams)
110
114
111
- Assertions .assertThat(mockInputParams.containsKey(filteredParamsKey)).isFalse
112
- Assertions .assertThat(mockInputParams).isEqualTo(expectedFinalParamsWithoutChange)
115
+ var expectedFinalParamsWithoutChange = mockInputParamsWithoutSensitiveParams.toMap()
116
+
117
+ Assertions .assertThat(mockInputParamsWithoutSensitiveParams.containsKey(filteredParamsKey)).isFalse
118
+ Assertions .assertThat(mockInputParamsWithoutSensitiveParams).isEqualTo(expectedFinalParamsWithoutChange)
119
+ }
120
+
121
+ @Test
122
+ fun `test fetched sensitive params list has only default sensitive params from the server and need to filter the params` () {
123
+ initMockFetchedAppSettings(mockSensitiveParamsFromServerDefaultOnly)
124
+ enable()
125
+ processFilterSensitiveParams(mockInputParams, mockEventWithSensitiveParam)
126
+
127
+ var expectedParams = HashMap <String , String ?>()
128
+ var filteredParams = JSONArray ()
129
+ filteredParams.put(mockSensitiveParam3)
130
+ expectedParams[filteredParamsKey] = filteredParams.toString()
131
+ expectedParams[mockNonSensitiveParam] = mockNonSensitiveParamValue
132
+ expectedParams[mockSensitiveParam1] = null
133
+ expectedParams[mockSensitiveParam2] = null
134
+
135
+ Assertions .assertThat(mockInputParams.containsKey(filteredParamsKey)).isTrue
136
+ Assertions .assertThat(mockInputParams).isEqualTo(expectedParams)
113
137
}
114
138
115
139
@Test
116
140
fun `test fetched sensitive params list is not null from the server and filter the params` () {
117
141
initMockFetchedAppSettings(mockSensitiveParamsFromServer)
142
+ enable()
143
+ processFilterSensitiveParams(mockInputParams, mockEventWithSensitiveParam)
144
+
145
+ var expectedParams = HashMap <String , String ?>()
146
+ var filteredParams = JSONArray ()
147
+ filteredParams.put(mockSensitiveParam3) /* default sensitive param */
148
+ filteredParams.put(mockSensitiveParam1) /* specific sensitive params */
149
+ filteredParams.put(mockSensitiveParam2) /* specific sensitive params */
150
+ expectedParams[filteredParamsKey] = filteredParams.toString()
151
+ expectedParams[mockNonSensitiveParam] = mockNonSensitiveParamValue
152
+
153
+ Assertions .assertThat(mockInputParams.containsKey(filteredParamsKey)).isTrue
154
+ Assertions .assertThat(mockInputParams).isEqualTo(expectedParams)
155
+ }
156
+
157
+ @Test
158
+ fun `test fetched sensitive params list default only from the server and filter the params` () {
159
+ initMockFetchedAppSettings(mockSensitiveParamsFromServerDefaultOnly)
160
+ enable()
161
+ processFilterSensitiveParams(mockInputParams, mockEventWithSensitiveParam)
118
162
119
163
var expectedParams = HashMap <String , String ?>()
120
164
var filteredParams = JSONArray ()
121
- filteredParams.put(mockSensitiveParam1)
122
- filteredParams.put(mockSensitiveParam2)
165
+ filteredParams.put(mockSensitiveParam3) /* default sensitive param */
123
166
expectedParams[filteredParamsKey] = filteredParams.toString()
124
167
expectedParams[mockNonSensitiveParam] = mockNonSensitiveParamValue
168
+ expectedParams[mockSensitiveParam1] = null
169
+ expectedParams[mockSensitiveParam2] = null
170
+
171
+ Assertions .assertThat(mockInputParams.containsKey(filteredParamsKey)).isTrue
172
+ Assertions .assertThat(mockInputParams).isEqualTo(expectedParams)
173
+ }
125
174
175
+ @Test
176
+ fun `test fetched sensitive params list specific only from the server and filter the params` () {
177
+ initMockFetchedAppSettings(mockSensitiveParamsFromServerWithoutDefault)
126
178
enable()
127
179
processFilterSensitiveParams(mockInputParams, mockEventWithSensitiveParam)
128
180
181
+ var expectedParams = HashMap <String , String ?>()
182
+ var filteredParams = JSONArray ()
183
+ filteredParams.put(mockSensitiveParam1) /* specific sensitive params */
184
+ filteredParams.put(mockSensitiveParam2) /* specific sensitive params */
185
+
186
+ expectedParams[filteredParamsKey] = filteredParams.toString()
187
+ expectedParams[mockNonSensitiveParam] = mockNonSensitiveParamValue
188
+ expectedParams[mockSensitiveParam3] = null
189
+
129
190
Assertions .assertThat(mockInputParams.containsKey(filteredParamsKey)).isTrue
130
191
Assertions .assertThat(mockInputParams).isEqualTo(expectedParams)
131
192
}
@@ -135,22 +196,28 @@ class SensitiveParamsManagerTest : FacebookPowerMockTestCase() {
135
196
136
197
private const val configKey = " key"
137
198
private const val configValue = " value"
199
+
138
200
private const val filteredParamsKey = " _filteredKey"
201
+ private const val defaultSensitiveParametersKey = " _MTSDK_Default_"
139
202
140
203
private const val mockEventNameWithoutSensitiveParams = " install_app"
141
204
private const val mockEventWithSensitiveParam = " sensitive_event_1"
142
205
private const val mockSensitiveParam1 = " sensitive_param_1"
143
206
private const val mockSensitiveParam2 = " sensitive_param_2"
207
+ private const val mockSensitiveParam3 = " sensitive_param_3"
144
208
private const val mockNonSensitiveParam = " non_sensitive_param"
145
209
private const val mockNonSensitiveParamValue = " param_value"
146
210
147
211
private lateinit var emptyJSONArray: JSONArray
148
212
149
213
/* mock sensitive params with event name */
150
- private lateinit var mockSpecificSensitiveParams: JSONObject
214
+ private lateinit var mockDefaultSensitiveParams: JSONObject /* default sensitive params */
215
+ private lateinit var mockSpecificSensitiveParams: JSONObject /* non default sensitive params */
151
216
152
217
/* mock config fetched from server */
153
- private lateinit var mockSensitiveParamsFromServer: JSONArray
218
+ private lateinit var mockSensitiveParamsFromServerDefaultOnly: JSONArray /* default only */
219
+ private lateinit var mockSensitiveParamsFromServerWithoutDefault: JSONArray /* specific sensitive params only */
220
+ private lateinit var mockSensitiveParamsFromServer: JSONArray /* specific sensitive params and default */
154
221
155
222
private lateinit var mockInputParams: HashMap <String , String ?>
156
223
private lateinit var expectedFinalParamsWithoutChange: Map <String , String ?>
@@ -165,12 +232,26 @@ class SensitiveParamsManagerTest : FacebookPowerMockTestCase() {
165
232
put(configKey, mockEventWithSensitiveParam)
166
233
put(configValue, sensitiveParams)
167
234
}
235
+ mockSensitiveParamsFromServerWithoutDefault = JSONArray ()
236
+ mockSensitiveParamsFromServerWithoutDefault.put(mockSpecificSensitiveParams)
237
+
238
+ sensitiveParams = JSONArray ()
239
+ sensitiveParams.put(mockSensitiveParam3)
240
+ mockDefaultSensitiveParams = JSONObject ().apply {
241
+ put(" key" , defaultSensitiveParametersKey)
242
+ put(" value" , sensitiveParams)
243
+ }
244
+ mockSensitiveParamsFromServerDefaultOnly = JSONArray ()
245
+ mockSensitiveParamsFromServerDefaultOnly.put(mockDefaultSensitiveParams)
246
+
168
247
mockSensitiveParamsFromServer = JSONArray ()
169
248
mockSensitiveParamsFromServer.put(mockSpecificSensitiveParams)
249
+ mockSensitiveParamsFromServer.put(mockDefaultSensitiveParams)
170
250
171
251
mockInputParams = HashMap ()
172
252
mockInputParams[mockSensitiveParam1] = null
173
253
mockInputParams[mockSensitiveParam2] = null
254
+ mockInputParams[mockSensitiveParam3] = null
174
255
mockInputParams[mockNonSensitiveParam] = mockNonSensitiveParamValue
175
256
176
257
expectedFinalParamsWithoutChange = mockInputParams.toMap()
0 commit comments