-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #235 from wordpress-mobile/release/1.8.10
Merge Release/1.8.10 into master
- Loading branch information
Showing
10 changed files
with
110 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
int WPSharedGetLoggingLevel(void); | ||
void WPSharedSetLoggingLevel(int level); | ||
@import CocoaLumberjack; | ||
|
||
DDLogLevel WPSharedGetLoggingLevel(void); | ||
void WPSharedSetLoggingLevel(DDLogLevel level); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
#import "WPSharedLogging.h" | ||
#import "WPSharedLoggingPrivate.h" | ||
|
||
int WPSharedGetLoggingLevel() { | ||
DDLogLevel WPSharedGetLoggingLevel() { | ||
return ddLogLevel; | ||
} | ||
|
||
void WPSharedSetLoggingLevel(int level) { | ||
void WPSharedSetLoggingLevel(DDLogLevel level) { | ||
ddLogLevel = level; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import Foundation | ||
|
||
/// Wraps a value that contains sensitive information to prevent accidental logging | ||
/// | ||
/// Usage example | ||
/// | ||
/// ``` | ||
/// let password = Secret("my secret password") | ||
/// print(password) // Prints "--redacted--" | ||
/// print(password.secretValue) // Prints "my secret password" | ||
/// ``` | ||
/// | ||
public struct Secret<T> { | ||
public let secretValue: T | ||
|
||
public init(_ secretValue: T) { | ||
self.secretValue = secretValue | ||
} | ||
} | ||
|
||
extension Secret: RawRepresentable { | ||
public typealias RawValue = T | ||
|
||
public init?(rawValue: Self.RawValue) { | ||
self.init(rawValue) | ||
} | ||
|
||
public var rawValue: T { | ||
return secretValue | ||
} | ||
} | ||
|
||
extension Secret: CustomStringConvertible, CustomDebugStringConvertible, CustomReflectable { | ||
private static var redacted: String { | ||
return "--redacted--" | ||
} | ||
|
||
public var description: String { | ||
return Secret.redacted | ||
} | ||
|
||
public var debugDescription: String { | ||
return Secret.redacted | ||
} | ||
|
||
public var customMirror: Mirror { | ||
return Mirror(reflecting: Secret.redacted) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
@import CocoaLumberjack; | ||
extern int ddLogLevel; | ||
extern DDLogLevel ddLogLevel; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
#import "WPSharedLoggingPrivate.h" | ||
int ddLogLevel = DDLogLevelWarning; | ||
DDLogLevel ddLogLevel = DDLogLevelWarning; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import WordPressShared | ||
import XCTest | ||
|
||
class SecretTests: XCTestCase { | ||
func testSecretDescription() { | ||
let secret = Secret("my secret") | ||
XCTAssertEqual("--redacted--", secret.description, "Description should be redacted") | ||
} | ||
|
||
func testSecretDebugDescription() { | ||
let secret = Secret("my secret") | ||
XCTAssertEqual("--redacted--", secret.debugDescription, "Debug description should be redacted") | ||
} | ||
|
||
func testSecretMirror() { | ||
let secret = Secret("my secret") | ||
XCTAssertEqual("--redacted--", String(reflecting: secret), "Mirror should be redacted") | ||
} | ||
|
||
func testSecretUnwrapsValue() { | ||
let secret = Secret("my secret") | ||
XCTAssertEqual("my secret", secret.secretValue, "secretValue should not be redacted") | ||
} | ||
} |