-
Notifications
You must be signed in to change notification settings - Fork 16
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
fix: added url path encoding #376
Changes from 2 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 |
---|---|---|
|
@@ -44,4 +44,29 @@ class HttpEndpointTest: UnitTest { | |
|
||
XCTAssertEqual(actual, expected) | ||
} | ||
|
||
func test_getUrlString_givenRandomPathNeedsEncoding_expectEncodedPath() { | ||
let identifierWithSpecialChar = String.randomStringWithSpecialCharacters() | ||
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. I would prefer if we hard-coded test data instead of randomly generate it. Maybe the randomly generated string gives us a char with no special chars, for example. The other test function is great in that it includes a special character that we have identified causes issues for customers. I like the idea of hard-coding test strings that we know could cause an issue. 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. Good point, but random values does extend range for testing more characters. We can perhaps update 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. What if we hard-code I think that would do the same thing as |
||
let endpoint = CIOApiEndpoint.identifyCustomer(identifier: identifierWithSpecialChar) | ||
|
||
let expectedIdentifier = identifierWithSpecialChar.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? identifierWithSpecialChar | ||
let expected = "https://customer.io/api/v1/customers/\(expectedIdentifier)" | ||
|
||
setHttpBaseUrls(trackingApi: "https://customer.io") | ||
|
||
let actual = endpoint.getUrlString(baseUrls: httpBaseUrls) | ||
|
||
XCTAssertEqual(actual, expected) | ||
} | ||
|
||
func test_getUrl_givenUnencodedPathWithSpecialCharacter_expectValidUrl() { | ||
let identifierWithSpecialChar = "social-login|1234567890abcde" | ||
let endpoint = CIOApiEndpoint.identifyCustomer(identifier: identifierWithSpecialChar) | ||
|
||
setHttpBaseUrls(trackingApi: "https://customer.io") | ||
|
||
let actualUrl = endpoint.getUrl(baseUrls: httpBaseUrls) | ||
|
||
XCTAssertNotNil(actualUrl, "Expected valid URL but got nil. Ensure path is encoded correctly.") | ||
levibostian marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
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.
If we do end up using this function, move it into
Tests/Shared
since it's a function used only for tests.