More logging, scrub phone numbers from file logs (#1357)
Phone number are still logged in TTY for development. // FREEBIE
This commit is contained in:
parent
1433ee2655
commit
2ab6955967
|
@ -42,7 +42,7 @@ PODS:
|
|||
- CocoaLumberjack (~> 2.0)
|
||||
- ProtocolBuffers (1.9.11)
|
||||
- Reachability (3.2)
|
||||
- SAMKeychain (1.5.1)
|
||||
- SAMKeychain (1.5.2)
|
||||
- SCWaveformView (1.0.0)
|
||||
- SignalServiceKit (0.2.0):
|
||||
- '25519'
|
||||
|
@ -130,7 +130,7 @@ EXTERNAL SOURCES:
|
|||
|
||||
CHECKOUT OPTIONS:
|
||||
SignalServiceKit:
|
||||
:commit: 1098bc203e4ca2d7ae444b5a6e913b123455c5da
|
||||
:commit: 06538f6b46fae7ec8a73deab4c186bfde28bbb49
|
||||
:git: https://github.com/WhisperSystems/SignalServiceKit.git
|
||||
SocketRocket:
|
||||
:commit: 8096fef47d582bff8ae3758c9ae7af1d55ea53d6
|
||||
|
@ -152,7 +152,7 @@ SPEC CHECKSUMS:
|
|||
PastelogKit: 7b475be4cf577713506a943dd940bcc0499c8bca
|
||||
ProtocolBuffers: d509225eb2ea43d9582a59e94348fcf86e2abd65
|
||||
Reachability: 33e18b67625424e47b6cde6d202dce689ad7af96
|
||||
SAMKeychain: 6b04852a20684167aea97bdf8ba12c95d3616376
|
||||
SAMKeychain: 1865333198217411f35327e8da61b43de79b635b
|
||||
SCWaveformView: 52a96750255d817e300565a80c81fb643e233e07
|
||||
SignalServiceKit: 4e7a552635e10f4d94f0a047fc6554e932340b30
|
||||
SocketRocket: 3f77ec2104cc113add553f817ad90a77114f5d43
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
453D28B71D32BA5F00D523F0 /* OWSDisplayedMessage.m in Sources */ = {isa = PBXBuildFile; fileRef = 453D28B61D32BA5F00D523F0 /* OWSDisplayedMessage.m */; };
|
||||
453D28BA1D332DB100D523F0 /* OWSMessagesBubblesSizeCalculator.m in Sources */ = {isa = PBXBuildFile; fileRef = 453D28B91D332DB100D523F0 /* OWSMessagesBubblesSizeCalculator.m */; };
|
||||
453D28BB1D332DB100D523F0 /* OWSMessagesBubblesSizeCalculator.m in Sources */ = {isa = PBXBuildFile; fileRef = 453D28B91D332DB100D523F0 /* OWSMessagesBubblesSizeCalculator.m */; };
|
||||
45666F561D9B2827008FE134 /* OWSScrubbingLogFormatter.m in Sources */ = {isa = PBXBuildFile; fileRef = 45666F551D9B2827008FE134 /* OWSScrubbingLogFormatter.m */; };
|
||||
45666F581D9B2880008FE134 /* OWSScrubbingLogFormatterTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 45666F571D9B2880008FE134 /* OWSScrubbingLogFormatterTest.m */; };
|
||||
45843D1F1D2236B30013E85A /* OWSContactsSearcher.m in Sources */ = {isa = PBXBuildFile; fileRef = 45843D1E1D2236B30013E85A /* OWSContactsSearcher.m */; };
|
||||
45843D201D2236B30013E85A /* OWSContactsSearcher.m in Sources */ = {isa = PBXBuildFile; fileRef = 45843D1E1D2236B30013E85A /* OWSContactsSearcher.m */; };
|
||||
45843D221D223BA10013E85A /* OWSContactsSearcherTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 45843D211D223BA10013E85A /* OWSContactsSearcherTest.m */; };
|
||||
|
@ -524,6 +526,9 @@
|
|||
453D28B81D332DB100D523F0 /* OWSMessagesBubblesSizeCalculator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSMessagesBubblesSizeCalculator.h; sourceTree = "<group>"; };
|
||||
453D28B91D332DB100D523F0 /* OWSMessagesBubblesSizeCalculator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSMessagesBubblesSizeCalculator.m; sourceTree = "<group>"; };
|
||||
454B35071D08EED80026D658 /* mk */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = mk; path = translations/mk.lproj/Localizable.strings; sourceTree = "<group>"; };
|
||||
45666F541D9B2827008FE134 /* OWSScrubbingLogFormatter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSScrubbingLogFormatter.h; sourceTree = "<group>"; };
|
||||
45666F551D9B2827008FE134 /* OWSScrubbingLogFormatter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSScrubbingLogFormatter.m; sourceTree = "<group>"; };
|
||||
45666F571D9B2880008FE134 /* OWSScrubbingLogFormatterTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSScrubbingLogFormatterTest.m; sourceTree = "<group>"; };
|
||||
45843D1D1D2236B30013E85A /* OWSContactsSearcher.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OWSContactsSearcher.h; sourceTree = "<group>"; };
|
||||
45843D1E1D2236B30013E85A /* OWSContactsSearcher.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSContactsSearcher.m; sourceTree = "<group>"; };
|
||||
45843D211D223BA10013E85A /* OWSContactsSearcherTest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OWSContactsSearcherTest.m; sourceTree = "<group>"; };
|
||||
|
@ -1666,6 +1671,8 @@
|
|||
FCC81A971A44558300DFEC7D /* UIDevice+TSHardwareVersion.m */,
|
||||
B62F5E0E1C2980B4000D370C /* NSData+ows_StripToken.h */,
|
||||
B62F5E0F1C2980B4000D370C /* NSData+ows_StripToken.m */,
|
||||
45666F541D9B2827008FE134 /* OWSScrubbingLogFormatter.h */,
|
||||
45666F551D9B2827008FE134 /* OWSScrubbingLogFormatter.m */,
|
||||
);
|
||||
path = util;
|
||||
sourceTree = "<group>";
|
||||
|
@ -2050,6 +2057,7 @@
|
|||
B660F6B21C29868000687D6E /* QueueTest.m */,
|
||||
B660F6B31C29868000687D6E /* UtilTest.h */,
|
||||
B660F6B41C29868000687D6E /* UtilTest.m */,
|
||||
45666F571D9B2880008FE134 /* OWSScrubbingLogFormatterTest.m */,
|
||||
);
|
||||
path = util;
|
||||
sourceTree = "<group>";
|
||||
|
@ -2730,6 +2738,7 @@
|
|||
76EB05E418170B33006006FC /* UdpSocket.m in Sources */,
|
||||
76EB058218170B33006006FC /* Environment.m in Sources */,
|
||||
76EB064418170B33006006FC /* ThreadManager.m in Sources */,
|
||||
45666F561D9B2827008FE134 /* OWSScrubbingLogFormatter.m in Sources */,
|
||||
45C681C61D305C9E0050903A /* OWSDisplayedMessageCollectionViewCell.m in Sources */,
|
||||
E197B61E18BBEC6D00F073E5 /* AudioRouter.m in Sources */,
|
||||
E197B60D18BBEC1A00F073E5 /* AudioSocket.m in Sources */,
|
||||
|
@ -2982,6 +2991,7 @@
|
|||
B660F77C1C29988E00687D6E /* Conversions.m in Sources */,
|
||||
B660F77D1C29988E00687D6E /* Crc32.m in Sources */,
|
||||
B660F77E1C29988E00687D6E /* DataUtil.m in Sources */,
|
||||
45666F581D9B2880008FE134 /* OWSScrubbingLogFormatterTest.m in Sources */,
|
||||
B660F77F1C29988E00687D6E /* DateUtil.m in Sources */,
|
||||
B660F7801C29988E00687D6E /* DictionaryUtil.m in Sources */,
|
||||
B660F7811C29988E00687D6E /* FunctionalUtil.m in Sources */,
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
#ifdef DEBUG
|
||||
static const NSUInteger ddLogLevel = DDLogLevelAll;
|
||||
#else
|
||||
static const NSUInteger ddLogLevel = DDLogLevelWarning;
|
||||
static const NSUInteger ddLogLevel = DDLogLevelInfo;
|
||||
#endif
|
||||
|
||||
#import "iOSVersions.h"
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
//
|
||||
|
||||
#import "DebugLogger.h"
|
||||
#import "OWSScrubbingLogFormatter.h"
|
||||
|
||||
#pragma mark Logging - Production logging wants us to write some logs to a file in case we need it for debugging.
|
||||
|
||||
|
@ -33,6 +34,8 @@
|
|||
init]; // Logging to file, because it's in the Cache folder, they are not uploaded in iTunes/iCloud backups.
|
||||
self.fileLogger.rollingFrequency = 60 * 60 * 24; // 24 hour rolling.
|
||||
self.fileLogger.logFileManager.maximumNumberOfLogFiles = 3; // Keep three days of logs.
|
||||
self.fileLogger.logFormatter = [OWSScrubbingLogFormatter new];
|
||||
|
||||
[DDLog addLogger:self.fileLogger];
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
// Created by Michael Kirk on 9/27/16.
|
||||
// Copyright © 2016 Open Whisper Systems. All rights reserved.
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface OWSScrubbingLogFormatter : DDLogFileFormatterDefault
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
|
@ -0,0 +1,27 @@
|
|||
// Created by Michael Kirk on 9/27/16.
|
||||
// Copyright © 2016 Open Whisper Systems. All rights reserved.
|
||||
|
||||
#import "OWSScrubbingLogFormatter.h"
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@implementation OWSScrubbingLogFormatter
|
||||
|
||||
- (NSString *)formatLogMessage:(DDLogMessage *)logMessage
|
||||
{
|
||||
NSString *string = [super formatLogMessage:logMessage];
|
||||
NSRegularExpression *phoneRegex =
|
||||
[NSRegularExpression regularExpressionWithPattern:@"\\+\\d{7,12}(\\d{3})"
|
||||
options:NSRegularExpressionCaseInsensitive
|
||||
error:nil];
|
||||
NSString *filteredString = [phoneRegex stringByReplacingMatchesInString:string
|
||||
options:0
|
||||
range:NSMakeRange(0, [string length])
|
||||
withTemplate:@"[ REDACTED_PHONE_NUMBER ]"];
|
||||
|
||||
return filteredString;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
|
@ -0,0 +1,63 @@
|
|||
// Created by Michael Kirk on 9/27/16.
|
||||
// Copyright © 2016 Open Whisper Systems. All rights reserved.
|
||||
|
||||
#import "OWSScrubbingLogFormatter.h"
|
||||
#import <XCTest/XCTest.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface OWSScrubbingLogFormatterTest : XCTestCase
|
||||
|
||||
@end
|
||||
|
||||
@implementation OWSScrubbingLogFormatterTest
|
||||
|
||||
- (DDLogMessage *)messageWithString:(NSString *)string
|
||||
{
|
||||
return [[DDLogMessage alloc] initWithMessage:string
|
||||
level:DDLogLevelInfo
|
||||
flag:0
|
||||
context:0
|
||||
file:nil
|
||||
function:nil
|
||||
line:0
|
||||
tag:nil
|
||||
options:0
|
||||
timestamp:[NSDate new]];
|
||||
}
|
||||
|
||||
- (void)testPhoneNumbersScrubbed
|
||||
{
|
||||
NSArray<NSString *> *phoneStrings = @[
|
||||
@"+13331231234 ",
|
||||
@"+4113331231234",
|
||||
@"+13331231234 something something +13331231234",
|
||||
];
|
||||
|
||||
for (NSString *phoneString in phoneStrings) {
|
||||
OWSScrubbingLogFormatter *formatter = [OWSScrubbingLogFormatter new];
|
||||
NSString *actual = [formatter
|
||||
formatLogMessage:[self
|
||||
messageWithString:[NSString stringWithFormat:@"My phone number is %@", phoneString]]];
|
||||
|
||||
NSRange redactedRange = [actual rangeOfString:@"My phone number is [ REDACTED_PHONE_NUMBER ]"];
|
||||
XCTAssertNotEqual(NSNotFound, redactedRange.location, "Failed to redact phone string: %@", phoneString);
|
||||
|
||||
NSRange phoneNumberRange = [actual rangeOfString:phoneString];
|
||||
XCTAssertEqual(NSNotFound, phoneNumberRange.location, "Failed to redact phone string: %@", phoneString);
|
||||
}
|
||||
}
|
||||
|
||||
- (void)testNonPhonenumberNotScrubbed
|
||||
{
|
||||
OWSScrubbingLogFormatter *formatter = [OWSScrubbingLogFormatter new];
|
||||
NSString *actual =
|
||||
[formatter formatLogMessage:[self messageWithString:[NSString stringWithFormat:@"Some unfiltered string"]]];
|
||||
|
||||
NSRange redactedRange = [actual rangeOfString:@"Some unfiltered string"];
|
||||
XCTAssertNotEqual(NSNotFound, redactedRange.location, "Shouldn't touch non phone string.");
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
Loading…
Reference in New Issue