예제 #1
0
        /// <summary>
        /// Does the scrub.
        /// </summary>
        /// <param name="inputString">The input string.</param>
        /// <returns>System.String.</returns>
        protected override string DoScrub(string inputString)
        {
            string scrubbedString = JsonScrubber.ScrubJsonFieldsByName(inputString, this._scrubFields, this._scrubMask);

            scrubbedString = JsonScrubber.ScrubJsonFieldsByPaths(scrubbedString, this._scrubPaths, this._scrubMask);
            return(scrubbedString);
        }
예제 #2
0
        /// <summary>
        /// Scrubs the payload.
        /// </summary>
        /// <param name="payload">The payload.</param>
        /// <param name="scrubFields">The scrub fields.</param>
        /// <returns>System.String.</returns>
        internal static string ScrubPayload(string payload, IEnumerable <string> scrubFields)
        {
            var jObj         = JsonScrubber.CreateJsonObject(payload);
            var dataProperty = JsonScrubber.GetChildPropertyByName(jObj, "data");

            JsonScrubber.ScrubJson(dataProperty, scrubFields);
            var scrubbedPayload = jObj.ToString();

            return(scrubbedPayload);
        }
예제 #3
0
        /// <summary>
        /// Scrubs the payload.
        /// </summary>
        /// <param name="payload">The payload.</param>
        /// <returns>System.String.</returns>
        public string ScrubPayload(string payload)
        {
            var jObj         = JsonScrubber.CreateJsonObject(payload);
            var dataProperty = JsonScrubber.GetChildPropertyByName(jObj, "data");

            if (this._payloadFieldPaths != null && this._payloadFieldPaths.LongLength > 0)
            {
                JsonScrubber.ScrubJsonFieldsByPaths(jObj, this._payloadFieldPaths, scrubMask);
            }

            if (this._payloadFieldNames != null && this._payloadFieldNames.LongLength > 0)
            {
                JsonScrubber.ScrubJsonFieldsByName(dataProperty, this._payloadFieldNames, scrubMask);
            }

            var scrubbedPayload = jObj.ToString();

            return(scrubbedPayload);
        }
예제 #4
0
        public void DataFieldFilteringTest()
        {
            string[] criticalDataFields = new string[]
            {
                "access_token",
                "headers",
            };

            string[] scrubFields = new string[]
            {
                "one",
                "Access_token",
                "access_token",
                "headers",
                "two",
            };

            string[] expectedFields = new string[]
            {
                "one",
                "Access_token",
                "two",
            };

            var result = JsonScrubber.FilterOutCriticalFields(scrubFields, criticalDataFields);

            Assert.AreEqual(expectedFields.Count(), result.Count());

            int i = 0;

            while (i < expectedFields.Count())
            {
                Assert.AreEqual(expectedFields[i], result.ElementAt(i));
                i++;
            }
        }
예제 #5
0
        public void BasicScrubbingTest()
        {
            var jsonString = @"{'results' : [
              {
                 'address_components' : 'abc' ,
                 'formatted_address' : 'eedfdfdfdfdfdfdf',
                 'geometry' : {
                    'bounds' : {
                       'northeast' : {
                          'lat' : 56.88225340,
                          'lng' : 7.34169940
                       },
                       'southwest' : {
                          'lat' : 2.4792219750,
                          'lng' : 6.85382840
                       }}}},
              {
                 'address_components' : 'abc1' ,
                 'formatted_address' : 'ffdfdfdfdfdfdfdf',
                 'geometry' : {
                    'bounds' : {
                       'northeast' : {
                          'lat' : 6.88225340,
                          'lng' : 17.34169940
                       },
                       'southwest' : {
                          'lat' : 22.4792219750,
                          'lng' : 16.85382840
                       }}}}

               ]}";

            string[] scrubFields = new string[] {
                //"lng",
                "lat",
                "southwest",
            };

            string scrubbedJsonString = JsonScrubber.ScrubJson(jsonString, scrubFields);

            var expectedResult = @"{'results' : [
              {
                 'address_components' : 'abc' ,
                 'formatted_address' : 'eedfdfdfdfdfdfdf',
                 'geometry' : {
                    'bounds' : {
                       'northeast' : {
                          'lat' : '***',
                          'lng' : 7.34169940
                       },
                       'southwest' : '***'
              }}},
              {
                 'address_components' : 'abc1' ,
                 'formatted_address' : 'ffdfdfdfdfdfdfdf',
                 'geometry' : {
                    'bounds' : {
                       'northeast' : {
                          'lat' : '***',
                          'lng' : 17.34169940
                       },
                       'southwest' : '***'
               }}}
               ]}";

            Assert.AreEqual(JObject.Parse(expectedResult).ToString(), JObject.Parse(scrubbedJsonString).ToString());

            scrubFields = new string[] {
                "lng",
                "lat",
                "southwest",
            };

            scrubbedJsonString = JsonScrubber.ScrubJson(jsonString, scrubFields);

            Assert.AreNotEqual(JObject.Parse(expectedResult).ToString(), JObject.Parse(scrubbedJsonString).ToString());
        }
        public void CustomDottedDataScrubByPathTest()
        {
            var jsonString = @"{'results' : [
            {
                'address_components' : 'abc' ,
                'formatted_address' : 'eedfdfdfdfdfdfdf',
                'geometry' : {
                'bounds' : {
                    'northeast' : {
                        'lat.x' : 56.88225340,
                        'lng.y' : 7.34169940
                    },
                    'southwest' : {
                        'lat.x' : 2.4792219750,
                        'lng.y' : 6.85382840
                    }}}},
            {
                'address_components' : 'abc1' ,
                'formatted_address' : 'ffdfdfdfdfdfdfdf',
                'geometry' : {
                'bounds' : {
                    'northeast' : {
                        'lat.x' : 6.88225340,
                        'lng.y' : 17.34169940
                    },
                    'southwest' : {
                        'lat.x' : 22.4792219750,
                        'lng.y' : 16.85382840
                    }}}}

            ]}";

            string[] scrubFields = new string[] {
                //"lng",
                "results[0].geometry.bounds.northeast.lat.x",
                "results[0].geometry.bounds.northeast.lng.y",
                "results[1].geometry.bounds.northeast.lng.y",
                "results[1].geometry.bounds.southwest.lat.x",
            };

            var expectedResult = @"{'results' : [
            {
                'address_components' : 'abc' ,
                'formatted_address' : 'eedfdfdfdfdfdfdf',
                'geometry' : {
                'bounds' : {
                    'northeast' : {
                        'lat.x' : '***',
                        'lng.y' : '***'
                    },
                    'southwest' : {
                        'lat.x' : 2.4792219750,
                        'lng.y' : 6.85382840
                    }}}},
            {
                'address_components' : 'abc1' ,
                'formatted_address' : 'ffdfdfdfdfdfdfdf',
                'geometry' : {
                'bounds' : {
                    'northeast' : {
                        'lat.x' : 6.88225340,
                        'lng.y' : '***'
                    },
                    'southwest' : {
                        'lat.x' : '***',
                        'lng.y' : 16.85382840
                    }}}}

            ]}";

            var scrubbedJsonString = JsonScrubber.ScrubJsonFieldsByPaths(jsonString, scrubFields, "***");

            Assert.AreEqual(JObject.Parse(expectedResult).ToString(), JObject.Parse(scrubbedJsonString).ToString());
        }
        public void CustomDottedDataScrubByNameTest()
        {
            var jsonString = @"{'results' : [
              {
                 'address_components' : 'abc' ,
                 'formatted_address' : 'eedfdfdfdfdfdfdf',
                 'geometry' : {
                    'bounds' : {
                       'northeast.n' : {
                          'lat' : 56.88225340,
                          'lng' : 7.34169940
                       },
                       'southwest' : {
                          'lat' : 2.4792219750,
                          'lng' : 6.85382840
                       }}}},
              {
                 'address_components' : 'abc1' ,
                 'formatted_address' : 'ffdfdfdfdfdfdfdf',
                 'geometry' : {
                    'bounds' : {
                       'northeast' : {
                          'lat' : 6.88225340,
                          'lng.y' : 17.34169940
                       },
                       'southwest' : {
                          'lat' : 22.4792219750,
                          'lng.y' : 16.85382840
                       }}}}
               ]}";

            string[] scrubFields = new string[] {
                "northeast.n",
                "lng.y",
            };

            string scrubbedJsonString = JsonScrubber.ScrubJsonFieldsByName(jsonString, scrubFields, "***");

            var expectedResult = @"{'results' : [
              {
                 'address_components' : 'abc' ,
                 'formatted_address' : 'eedfdfdfdfdfdfdf',
                 'geometry' : {
                    'bounds' : {
                       'northeast.n' : '***',
                       'southwest' : {
                          'lat' : 2.4792219750,
                          'lng' : 6.85382840
                       }}}},
              {
                 'address_components' : 'abc1' ,
                 'formatted_address' : 'ffdfdfdfdfdfdfdf',
                 'geometry' : {
                    'bounds' : {
                       'northeast' : {
                          'lat' : 6.88225340,
                          'lng.y' : '***'
                       },
                       'southwest' : {
                          'lat' : 22.4792219750,
                          'lng.y' : '***'
                       }}}}
               ]}";

            string expected = JObject.Parse(expectedResult).ToString();

            Console.WriteLine("EXPECTED:");
            Console.WriteLine(expected);
            Console.WriteLine(string.Empty);

            string actual = JObject.Parse(scrubbedJsonString).ToString();

            Console.WriteLine("ACTUAL:");
            Console.WriteLine(actual);
            Console.WriteLine(string.Empty);

            Assert.AreEqual(expected, JObject.Parse(scrubbedJsonString).ToString());
        }