-
Notifications
You must be signed in to change notification settings - Fork 3k
Bugfix FXIOS-12033 [SEC] Fix check for {searchTerms}
in base URL
#26223
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,59 @@ import WebKit | |
import MozillaAppServices | ||
|
||
class ASSearchEngineUtilitiesTests: XCTestCase { | ||
private let leo_eng_deu_engine_no_search_params = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔥 thanks for adding tests! |
||
SearchEngineDefinition( | ||
aliases: [], | ||
charset: "UTF-8", | ||
classification: .unknown, | ||
identifier: "leo_ende_de", | ||
name: "LEO Eng-Deu", | ||
optional: false, | ||
partnerCode: "", | ||
telemetrySuffix: "", | ||
urls: SearchEngineUrls( | ||
search: SearchEngineUrl( | ||
base: "https://dict.leo.org/englisch-deutsch/{searchTerms}", | ||
method: "GET", | ||
params: [], | ||
searchTermParamName: nil | ||
), | ||
suggestions: nil, | ||
trending: nil, | ||
searchForm: nil | ||
), | ||
orderHint: nil, | ||
clickUrl: nil | ||
) | ||
private let leo_eng_deu_engine = | ||
SearchEngineDefinition( | ||
aliases: [], | ||
charset: "UTF-8", | ||
classification: .unknown, | ||
identifier: "leo_ende_de", | ||
name: "LEO Eng-Deu", | ||
optional: false, | ||
partnerCode: "", | ||
telemetrySuffix: "", | ||
urls: SearchEngineUrls( | ||
search: SearchEngineUrl( | ||
base: "https://dict.leo.org/englisch-deutsch/{searchTerms}", | ||
method: "GET", | ||
params: [SearchUrlParam( | ||
name: "foo", | ||
value: "bar", | ||
enterpriseValue: nil, | ||
experimentConfig: nil | ||
)], | ||
searchTermParamName: nil | ||
), | ||
suggestions: nil, | ||
trending: nil, | ||
searchForm: nil | ||
), | ||
orderHint: nil, | ||
clickUrl: nil | ||
) | ||
private let google_US_testEngine = | ||
SearchEngineDefinition( | ||
aliases: ["google"], | ||
|
@@ -89,4 +142,34 @@ class ASSearchEngineUtilitiesTests: XCTestCase { | |
let expected = "https://www.google.com/complete/search?client=firefox&q={searchTerms}" | ||
XCTAssertEqual(result, expected) | ||
} | ||
|
||
func testEmptyPartnerCodeSearchURL() { | ||
var engine = google_US_testEngine | ||
|
||
// Force an empty partnerCode string: | ||
engine.partnerCode = "" | ||
|
||
let result = ASSearchEngineUtilities.convertASSearchURLToOpenSearchURL(engine.urls.search, | ||
for: engine) | ||
let expected = "https://www.google.com/search?client=&q={searchTerms}" | ||
XCTAssertEqual(result, expected) | ||
} | ||
|
||
func testSearchTermIncludedInBaseURL() { | ||
let engine = leo_eng_deu_engine_no_search_params | ||
|
||
let result = ASSearchEngineUtilities.convertASSearchURLToOpenSearchURL(engine.urls.search, | ||
for: engine) | ||
let expected = "https://dict.leo.org/englisch-deutsch/{searchTerms}" | ||
XCTAssertEqual(result, expected) | ||
Comment on lines
+163
to
+164
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. curious, how come we include There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The additional parameters are for things besides the search parameters themselves (they're for additional arguments like the client or partner code identifier, etc.). So it's valid to have a search URL without them. |
||
} | ||
|
||
func testSearchTermIncludedInBaseURLAndParams() { | ||
let engine = leo_eng_deu_engine | ||
|
||
let result = ASSearchEngineUtilities.convertASSearchURLToOpenSearchURL(engine.urls.search, | ||
for: engine) | ||
let expected = "https://dict.leo.org/englisch-deutsch/{searchTerms}?foo=bar" | ||
XCTAssertEqual(result, expected) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: should we reference the docs? not sure where the typo was. Or we can add a JIRA ticket number here with more context.
Also interesting to see that the previous comment says:
// Note: term vs terms is not a typo.
Do you have context on this 🤔 or seems like this was a mistake?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The short version is that I was going by the docs we had and that was the origin of the first comment. But I double-checked the data eventually (and then checked with AS team) and it turned out the docs were wrong. Those headers are being fixed, but I wanted to be sure to document which version (searchTerm vs searchTerms) was correct.