Skip to content

Commit

Permalink
No Bug - Remove whitespace (#4013)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamnemecek authored and farhanpatel committed Jul 9, 2018
1 parent 63e2ae7 commit 0f8e4df
Show file tree
Hide file tree
Showing 160 changed files with 1,063 additions and 1,063 deletions.
26 changes: 13 additions & 13 deletions Account/FirefoxAccount.swift
Expand Up @@ -33,7 +33,7 @@ open class FirefoxAccount {
open let uid: String

open var fxaProfile: FxAProfile?

open var deviceRegistration: FxADeviceRegistration?

// Only set one time in the Choose What to Sync FxA screen shown during registration.
Expand Down Expand Up @@ -215,18 +215,18 @@ open class FirefoxAccount {
return "Not in a Token State: \(state?.label.rawValue ?? "Empty State")"
}
}

public class FxAProfile {
open var displayName: String?
open let email: String
open let avatar: Avatar

init(email: String, displayName: String?, avatar: String?) {
self.email = email
self.displayName = displayName
self.avatar = Avatar(url: avatar?.asURL)
}

enum ImageDownloadState {
case notStarted
case started
Expand All @@ -235,18 +235,18 @@ open class FirefoxAccount {
case succeededMalformed
case succeeded
}

open class Avatar {
open var image: UIImage?
open let url: URL?
var currentImageState: ImageDownloadState = .notStarted

init(url: URL?) {
self.image = UIImage(named: "placeholder-avatar")
self.url = url
self.updateAvatarImageState()
}

func updateAvatarImageState() {
switch currentImageState {
case .notStarted:
Expand All @@ -260,7 +260,7 @@ open class FirefoxAccount {
break
}
}

func downloadAvatar() {
SDWebImageManager.shared().loadImage(with: url, options: [.continueInBackground, .lowPriority], progress: nil) { (image, _, error, _, success, _) in
if let error = error {
Expand All @@ -274,12 +274,12 @@ open class FirefoxAccount {
}
return
}

if success == true && image == nil {
self.currentImageState = .succeededMalformed
return
}

self.image = image
self.currentImageState = .succeeded
NotificationCenter.default.post(name: .FirefoxAccountProfileChanged, object: self)
Expand All @@ -300,22 +300,22 @@ open class FirefoxAccount {
_ = self.registerOrUpdateDevice(session: session)
}
}

// Fetch current user's FxA profile. It contains the most updated email, displayName and avatar. This
// emits two `NotificationFirefoxAccountProfileChanged`, once when the profile has been downloaded and
// another when the avatar image has been downloaded.
open func updateProfile() {
guard let session = stateCache.value as? TokenState else {
return
}

let client = FxAClient10(authEndpoint: self.configuration.authEndpointURL, oauthEndpoint: self.configuration.oauthEndpointURL, profileEndpoint: self.configuration.profileEndpointURL)
client.getProfile(withSessionToken: session.sessionToken as NSData) >>== { result in
self.fxaProfile = FxAProfile(email: result.email, displayName: result.displayName, avatar: result.avatarURL)
NotificationCenter.default.post(name: .FirefoxAccountProfileChanged, object: self)
}
}

// Fetch the devices list from FxA then replace the current stored remote devices.
open func updateFxADevices(remoteDevices: RemoteDevices) -> Success {
guard let session = stateCache.value as? TokenState else {
Expand Down
24 changes: 12 additions & 12 deletions Account/FirefoxAccountConfiguration.swift
Expand Up @@ -143,17 +143,17 @@ public struct CustomFirefoxAccountConfiguration: FirefoxAccountConfiguration {
public init(prefs: Prefs? = nil) {
self.prefs = prefs
}

public var prefs: Prefs?

public let label = FirefoxAccountConfigurationLabel.custom

public var authEndpointURL: URL {
get {
if let authServer = self.prefs?.stringForKey(PrefsKeys.KeyCustomSyncAuth), let url = URL(string: authServer + "/v1") {
return url
}

// If somehow an invalid url was stored, fallback to the production URL
return ProductionFirefoxAccountConfiguration().authEndpointURL
}
Expand All @@ -167,7 +167,7 @@ public struct CustomFirefoxAccountConfiguration: FirefoxAccountConfiguration {
return ProductionFirefoxAccountConfiguration().oauthEndpointURL
}
}

public var profileEndpointURL: URL {
get {
if let profileServer = self.prefs?.stringForKey(PrefsKeys.KeyCustomSyncProfile), let url = URL(string: profileServer + "/v1") {
Expand All @@ -176,7 +176,7 @@ public struct CustomFirefoxAccountConfiguration: FirefoxAccountConfiguration {
return ProductionFirefoxAccountConfiguration().profileEndpointURL
}
}

public var signInURL: URL {
get {
if let signIn = self.prefs?.stringForKey(PrefsKeys.KeyCustomSyncWeb), let url = URL(string: signIn + "/signin?service=sync&context=fx_ios_v1") {
Expand All @@ -185,7 +185,7 @@ public struct CustomFirefoxAccountConfiguration: FirefoxAccountConfiguration {
return ProductionFirefoxAccountConfiguration().signInURL
}
}

public var forceAuthURL: URL {
get {
if let forceAuth = self.prefs?.stringForKey(PrefsKeys.KeyCustomSyncWeb), let url = URL(string: forceAuth + "/force_auth?service=sync&context=fx_ios_v1") {
Expand All @@ -194,7 +194,7 @@ public struct CustomFirefoxAccountConfiguration: FirefoxAccountConfiguration {
return ProductionFirefoxAccountConfiguration().forceAuthURL
}
}

public var settingsURL: URL {
get {
if let settings = self.prefs?.stringForKey(PrefsKeys.KeyCustomSyncWeb), let url = URL(string: settings + "/settings?service=sync&context=fx_ios_v1") {
Expand All @@ -203,13 +203,13 @@ public struct CustomFirefoxAccountConfiguration: FirefoxAccountConfiguration {
return ProductionFirefoxAccountConfiguration().settingsURL
}
}

public var sync15Configuration: Sync15Configuration {
get {
return CustomSync15Configuration(prefs: self.prefs)
}
}

public let pushConfiguration: PushConfiguration = FirefoxPushConfiguration()
}

Expand Down Expand Up @@ -252,9 +252,9 @@ public struct CustomSync15Configuration: Sync15Configuration {
public init(prefs: Prefs? = nil) {
self.prefs = prefs
}

public var prefs: Prefs?

public var tokenServerEndpointURL: URL {
get {
if let tokenServer = self.prefs?.stringForKey(PrefsKeys.KeyCustomSyncToken), let url = URL(string: tokenServer + "/1.0/sync/1.5") {
Expand Down
42 changes: 21 additions & 21 deletions Account/FxAClient10.swift
Expand Up @@ -262,11 +262,11 @@ open class FxAClient10 {

return FxADevicesResponse(devices: devices)
}

fileprivate class func notifyResponse(fromJSON json: JSON) -> FxANotifyResponse {
return FxANotifyResponse(success: json.error == nil)
}

fileprivate class func deviceDestroyResponse(fromJSON json: JSON) -> FxADeviceDestroyResponse {
return FxADeviceDestroyResponse(success: json.error == nil)
}
Expand All @@ -276,20 +276,20 @@ open class FxAClient10 {
let accessToken = json["access_token"].string else {
return nil
}

return FxAOAuthResponse(accessToken: accessToken)
}

fileprivate class func profileResponse(fromJSON json: JSON) -> FxAProfileResponse? {
guard json.error == nil,
let uid = json["uid"].string,
let email = json["email"].string else {
return nil
}

let avatarURL = json["avatar"].string
let displayName = json["displayName"].string

return FxAProfileResponse(email: email, uid: uid, avatarURL: avatarURL, displayName: displayName)
}

Expand Down Expand Up @@ -349,7 +349,7 @@ open class FxAClient10 {

return makeRequest(mutableURLRequest, responseHandler: FxAClient10.devicesResponse)
}

open func notify(deviceIDs: [GUID], collectionsChanged collections: [String], reason: String, withSessionToken sessionToken: NSData) -> Deferred<Maybe<FxANotifyResponse>> {
let httpBody = JSON([
"to": deviceIDs,
Expand Down Expand Up @@ -427,58 +427,58 @@ open class FxAClient10 {

return makeRequest(mutableURLRequest, responseHandler: FxADevice.fromJSON)
}

open func oauthAuthorize(withSessionToken sessionToken: NSData, keyPair: RSAKeyPair, certificate: String) -> Deferred<Maybe<FxAOAuthResponse>> {
let audience = self.getAudience(forURL: self.oauthURL)

let assertion = JSONWebTokenUtils.createAssertionWithPrivateKeyToSign(with: keyPair.privateKey,
certificate: certificate,
audience: audience)

let oauthAuthorizationURL = self.oauthURL.appendingPathComponent("/authorization")
var mutableURLRequest = URLRequest(url: oauthAuthorizationURL)
mutableURLRequest.httpMethod = HTTPMethod.post.rawValue
mutableURLRequest.setValue("application/json", forHTTPHeaderField: "Content-Type")

let parameters = [
"assertion": assertion,
"client_id": AppConstants.FxAiOSClientId,
"response_type": "token",
"scope": "profile",
"ttl": "300"
]

let salt: Data = Data()
let contextInfo: Data = FxAClient10.KW("sessionToken")
let key = sessionToken.deriveHKDFSHA256Key(withSalt: salt, contextInfo: contextInfo, length: UInt(2 * KeyLength))!

guard let httpBody = JSON(parameters as NSDictionary).stringValue()?.utf8EncodedData else {
return deferMaybe(FxAClientError.local(FxAClientUnknownError))
}

mutableURLRequest.httpBody = httpBody
mutableURLRequest.addAuthorizationHeader(forHKDFSHA256Key: key)

return makeRequest(mutableURLRequest, responseHandler: FxAClient10.oauthResponse)
}

open func getProfile(withSessionToken sessionToken: NSData) -> Deferred<Maybe<FxAProfileResponse>> {
let keyPair = RSAKeyPair.generate(withModulusSize: 1024)!
return self.sign(sessionToken as Data, publicKey: keyPair.publicKey) >>== { signResult in
return self.oauthAuthorize(withSessionToken: sessionToken, keyPair: keyPair, certificate: signResult.certificate) >>== { oauthResult in

let profileURL = self.profileURL.appendingPathComponent("/profile")
var mutableURLRequest = URLRequest(url: profileURL)
mutableURLRequest.httpMethod = HTTPMethod.get.rawValue

mutableURLRequest.setValue("application/json", forHTTPHeaderField: "Content-Type")
mutableURLRequest.setValue("Bearer " + oauthResult.accessToken, forHTTPHeaderField: "Authorization")

return self.makeRequest(mutableURLRequest, responseHandler: FxAClient10.profileResponse)
}
}
}

open func getAudience(forURL URL: URL) -> String {
if let port = URL.port {
return "\(URL.scheme!)://\(URL.host!):\(port)"
Expand Down Expand Up @@ -548,7 +548,7 @@ extension FxAClient10: FxALoginClient {
"publicKey": publicKey.jsonRepresentation() as NSDictionary,
"duration": NSNumber(value: OneDayInMilliseconds), // The maximum the server will allow.
]

let url = self.authURL.appendingPathComponent("/certificate/sign")
var mutableURLRequest = URLRequest(url: url)
mutableURLRequest.httpMethod = HTTPMethod.post.rawValue
Expand Down
2 changes: 1 addition & 1 deletion Account/FxAPushMessageHandler.swift
Expand Up @@ -146,7 +146,7 @@ extension FxAPushMessageHandler {

let clients = profile.remoteClientsAndTabs
let getClient = clients.getClient(fxaDeviceId: deviceId)

return getClient >>== { device in
let message = PushMessage.deviceDisconnected(device?.name)
if let id = device?.guid {
Expand Down
2 changes: 1 addition & 1 deletion AccountTests/FxAClient10Tests.swift
Expand Up @@ -157,7 +157,7 @@ class FxAClient10Tests: LiveAccountTest {
}
self.waitForExpectations(timeout: 10, handler: nil)
}

func testProfileSuccess() {
withVerifiedAccountNoExpectations { emailUTF8, quickStretchedPW in
let stageConfiguration = StageFirefoxAccountConfiguration()
Expand Down
2 changes: 1 addition & 1 deletion AccountTests/LiveAccountTest.swift
Expand Up @@ -63,7 +63,7 @@ open class LiveAccountTest: XCTestCase {
func withVerifiedAccount(_ completion: (Data, Data) -> Void) {
withExistingAccount(true, completion: completion)
}

// Helper function that waits for expectations to clear
func withVerifiedAccountNoExpectations(_ completion: (Data, Data) -> Void) {
withExistingAccount(true, completion: completion)
Expand Down

0 comments on commit 0f8e4df

Please sign in to comment.