Skip to content

Commit

Permalink
Detect invalid WP site and return error (#841)
Browse files Browse the repository at this point in the history
  • Loading branch information
itsmeichigo authored Mar 8, 2024
2 parents 01c8c7d + 958e0c8 commit 0fc37d1
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ _None._

### Bug Fixes

_None._
- Detect invalid WordPress site address. [#841]

### Internal Changes

Expand Down
8 changes: 8 additions & 0 deletions WordPressAuthenticator/Services/WordPressComBlogService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ class WordPressComBlogService {
}

let site = WordPressComSiteInfo(remote: response)
guard site.url != Constants.wordPressBlogURL else {
failure(ServiceError.invalidWordPressAddress)
return
}
success(site)
}, failure: { error in
let result = error ?? ServiceError.unknown
Expand All @@ -53,8 +57,12 @@ class WordPressComBlogService {
// MARK: - Nested Types
//
extension WordPressComBlogService {
enum Constants {
static let wordPressBlogURL = "https://wordpress.com/blog"
}

enum ServiceError: Error {
case unknown
case invalidWordPressAddress
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -541,12 +541,19 @@ private extension SiteAddressViewController {
self.presentNextControllerIfPossible(siteInfo: siteInfo)
}

service.fetchUnauthenticatedSiteInfoForAddress(for: baseSiteUrl, success: successBlock, failure: { [weak self] _ in
service.fetchUnauthenticatedSiteInfoForAddress(for: baseSiteUrl, success: successBlock, failure: { [weak self] error in
self?.configureViewLoading(false)
guard let self = self else {
return
}
self.presentNextControllerIfPossible(siteInfo: nil)

if self.authenticationDelegate.shouldHandleError(error) {
self.authenticationDelegate.handleError(error) { [weak self] customUI in
self?.navigationController?.pushViewController(customUI, animated: true)
}
} else {
self.displayError(message: Localization.invalidURL)
}
})
}

Expand Down

0 comments on commit 0fc37d1

Please sign in to comment.