File tree Expand file tree Collapse file tree 2 files changed +49
-1
lines changed
Sources/WireLogging/Network
Tests/WireLogging/Network Expand file tree Collapse file tree 2 files changed +49
-1
lines changed Original file line number Diff line number Diff line change @@ -79,8 +79,38 @@ struct RequestLog: Codable {
7979}
8080
8181public extension URL {
82+
8283 var endpointRemoteLogDescription : String {
83- absoluteString
84+ var components = URLComponents ( string: absoluteString)
85+ let searchContactPath = " /search/contacts "
86+
87+ let path = components? . path ?? " "
88+ guard path. contains ( searchContactPath) else {
89+ return absoluteString
90+ }
91+
92+ // redact query param
93+ var queryComponents = components? . queryItems ?? [ ]
94+ queryComponents. enumerated ( ) . forEach { item in
95+ var redactedItem = item. element
96+ if redactedItem. name == " q " {
97+ redactedItem. value = " *** "
98+ }
99+ queryComponents [ item. offset] = redactedItem
100+ }
101+
102+ components? . queryItems = queryComponents
103+
104+ var endpoint = [
105+ " \( components? . scheme ?? " " ) :/ " ,
106+ components? . host,
107+ path. trimmingCharacters ( in: CharacterSet ( charactersIn: " / " ) )
108+ ]
109+ . compactMap ( \. self)
110+ . filter { !$0. isEmpty }
111+ . joined ( separator: " / " )
112+ endpoint. append ( components? . query? . isEmpty == false ? " ? \( components!. query!) " : " " )
113+ return endpoint
84114 }
85115}
86116
Original file line number Diff line number Diff line change @@ -50,6 +50,24 @@ class RequestLogTests: XCTestCase {
5050 )
5151 }
5252
53+ func testParsingEndpointWithSearchContactsRedactedQueryParams( ) throws {
54+ let request =
55+ NSURLRequest (
56+ url: URL (
57+ string: " https://prod-nginz-https.wire.com/v13/search/contacts?q=test&size=10 "
58+ ) !
59+ )
60+ guard let sut: RequestLog = . init( request) else {
61+ XCTFail ( " could not create RequestLog " )
62+ return
63+ }
64+
65+ XCTAssertEqual (
66+ sut. endpoint,
67+ " https://prod-nginz-https.wire.com/v13/search/contacts?q=***&size=10 "
68+ )
69+ }
70+
5371 func testAuthorizationHeaderValueIsRedacted( ) throws {
5472 let request = NSMutableURLRequest ( url: URL ( string: " https://prod-nginz-https.wire.com/push/tokens " ) !)
5573 request. addValue ( " Bearer wertrtetetr42343242432456789p " , forHTTPHeaderField: " Authorization " )
You can’t perform that action at this time.
0 commit comments