This repository has been archived by the owner on May 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 448
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #6277 Detect unknown unicode in sign message requests and some im…
…provement for misleading message (#6300)
- Loading branch information
Showing
3 changed files
with
206 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Copyright 2022 The Brave Authors. All rights reserved. | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
import XCTest | ||
@testable import BraveWallet | ||
|
||
import Foundation | ||
|
||
class WalletStringExtensionTests: XCTestCase { | ||
func testHasUnknownUnicode() { | ||
let stringHasOnlyKnownUnicode = "hello this is message is in ascii chars only" | ||
XCTAssertFalse(stringHasOnlyKnownUnicode.hasUnknownUnicode) | ||
|
||
let stringsHasUnknownUnicode = "\u{202E} EVIL" | ||
XCTAssertTrue(stringsHasUnknownUnicode.hasUnknownUnicode) | ||
} | ||
|
||
func testHasConsecutiveNewlines() { | ||
let stringHasNoNewlines = "Here is one sentence." | ||
XCTAssertFalse(stringHasNoNewlines.hasConsecutiveNewLines) | ||
|
||
let stringsHasNewlineButNoConsecutiveNewlines = "Here is one sentence.\nAnd here is another." | ||
XCTAssertFalse(stringsHasNewlineButNoConsecutiveNewlines.hasConsecutiveNewLines) | ||
|
||
let stringHasConsecutiveNewlines = "Main Message\n\n\n\n\nEvil payload is below" | ||
XCTAssertTrue(stringHasConsecutiveNewlines.hasConsecutiveNewLines) | ||
} | ||
|
||
func testPrintableWithUnknownUnicode() { | ||
let string = "Main Message\nEvil payload is below \n¶\npaylod still loooks good\nNew Line\n¶\n\u{202E} EVIL" | ||
let printable = "Main Message\nEvil payload is below \n\\u{00B6}\npaylod still loooks good\nNew Line\n\\u{00B6}\n\\u{202E} EVIL" | ||
XCTAssertEqual(string.printableWithUnknownUnicode, printable) | ||
} | ||
} |