Пример #1
0
        public async Task MaskingService_MaskAsync_WorksWithDifferentRecords()
        {
            LogRecord       lrecord = new LogRecord("test", "test", "test", "test", "test");
            IPAddressRecord irecord = new IPAddressRecord("test");

            LogRecord lrecordMasked = (LogRecord)await _maskingService.MaskAsync(lrecord, false).ConfigureAwait(false);

            IPAddressRecord irecordMasked = (IPAddressRecord)await _maskingService.MaskAsync(irecord, false).ConfigureAwait(false);

            Assert.IsTrue(lrecordMasked.IsMasked());
            Assert.IsTrue(irecordMasked.IsMasked());

            try
            {
                await _mapDAO.DeleteByIdsAsync(new List <string>() { _maskingService.MaskString("test") }).ConfigureAwait(false);
            }
            catch
            { }
        }
        public async Task FlatFileLoggingService_LogToFlatFileAsync_CsvProtection(string timestamp, string operation, string identifier,
                                                                                  string ipAddress, string errorType)
        {
            LogRecord rec = new LogRecord(timestamp.Split(' ')[0] + " " + timestamp.Split(' ')[1], operation, identifier, ipAddress, errorType);

            LogRecord logRecord = (LogRecord)await _maskingService.MaskAsync(rec, false).ConfigureAwait(false);

            try
            {
                File.Delete(_logDirectory + $@"\{timestamp.Split(' ')[2]}{Constants.LogFileType}");
            }
            catch
            { }

            try
            {
                await _ffLog.LogToFlatFileAsync(timestamp, operation, identifier, ipAddress, errorType, Constants.LogFolder, Constants.LogFileType).ConfigureAwait(false);

                bool result = false;

                string lineInput = "";

                using (StreamReader reader = new StreamReader(_logDirectory + $@"\{timestamp.Split(' ')[2]}{Constants.LogFileType}"))
                {
                    // Construct the line to delete
                    string lineToFind = "";

                    for (int i = 0; i < logRecord.Fields.Count; i++)
                    {
                        string field = logRecord.Fields[i];

                        string startsWith = field.Substring(0, 1);

                        // If the field starts with a csv vulnerability, re-add the padding to the beginning.
                        if (Constants.CsvVulnerabilities.Contains(startsWith))
                        {
                            lineToFind += $"{Constants.CsvProtection}{field},";
                        }
                        else
                        {
                            lineToFind += $"{field},";
                        }
                    }

                    // Get rid of last comma.
                    lineToFind = lineToFind.Substring(0, lineToFind.Length - 1);

                    while ((lineInput = await reader.ReadLineAsync().ConfigureAwait(false)) != null)
                    {
                        if (lineInput.Equals(lineToFind))
                        {
                            result = true;
                        }
                    }
                }

                Assert.IsTrue(result);
            }
            catch
            {
                Assert.Fail();
            }
        }