Bug 1287643 - Add Push crypto params to FxAccountDevice. r?nalexander draft
authorEdouard Oger <eoger@fastmail.com>
Wed, 20 Jul 2016 10:46:17 -0700
changeset 403388 66231e2515127cfbf707ef6c200b7a75fca61f8b
parent 403386 8ef9629d8f90d6507b1bad01146b14101de79174
child 403389 ad3c3225551b35b4109f62015a94a4a838b1c956
push id26908
push userbmo:eoger@fastmail.com
push dateFri, 19 Aug 2016 18:43:11 +0000
reviewersnalexander
bugs1287643
milestone51.0a1
Bug 1287643 - Add Push crypto params to FxAccountDevice. r?nalexander MozReview-Commit-ID: LFnbpA0zjjj
mobile/android/services/src/main/java/org/mozilla/gecko/fxa/FxAccountDevice.java
mobile/android/tests/background/junit4/src/org/mozilla/gecko/fxa/login/MockFxAccountClient.java
--- a/mobile/android/services/src/main/java/org/mozilla/gecko/fxa/FxAccountDevice.java
+++ b/mobile/android/services/src/main/java/org/mozilla/gecko/fxa/FxAccountDevice.java
@@ -7,51 +7,75 @@ package org.mozilla.gecko.fxa;
 import org.mozilla.gecko.sync.ExtendedJSONObject;
 
 public class FxAccountDevice {
 
   public static final String JSON_KEY_NAME = "name";
   public static final String JSON_KEY_ID = "id";
   public static final String JSON_KEY_TYPE = "type";
   public static final String JSON_KEY_ISCURRENTDEVICE = "isCurrentDevice";
+  public static final String JSON_KEY_PUSH_CALLBACK = "pushCallback";
+  public static final String JSON_KEY_PUSH_PUBLICKEY = "pushPublicKey";
+  public static final String JSON_KEY_PUSH_AUTHKEY = "pushAuthKey";
 
-  public String id;
-  public String name;
-  public String type;
-  public Boolean isCurrentDevice;
+  public final String id;
+  public final String name;
+  public final String type;
+  public final Boolean isCurrentDevice;
+  public final String pushCallback;
+  public final String pushPublicKey;
+  public final String pushAuthKey;
 
-  public FxAccountDevice(String name, String id, String type, Boolean isCurrentDevice) {
+  public FxAccountDevice(String name, String id, String type, Boolean isCurrentDevice,
+                         String pushCallback, String pushPublicKey, String pushAuthKey) {
     this.name = name;
     this.id = id;
     this.type = type;
     this.isCurrentDevice = isCurrentDevice;
+    this.pushCallback = pushCallback;
+    this.pushPublicKey = pushPublicKey;
+    this.pushAuthKey = pushAuthKey;
   }
 
-  public static FxAccountDevice forRegister(String name, String type) {
-    return new FxAccountDevice(name, null, type, null);
+  public static FxAccountDevice forRegister(String name, String type, String pushCallback,
+                                            String pushPublicKey, String pushAuthKey) {
+    return new FxAccountDevice(name, null, type, null, pushCallback, pushPublicKey, pushAuthKey);
   }
 
-  public static FxAccountDevice forUpdate(String id, String name) {
-    return new FxAccountDevice(name, id, null, null);
+  public static FxAccountDevice forUpdate(String id, String name, String pushCallback,
+                                          String pushPublicKey, String pushAuthKey) {
+    return new FxAccountDevice(name, id, null, null, pushCallback, pushPublicKey, pushAuthKey);
   }
 
   public static FxAccountDevice fromJson(ExtendedJSONObject json) {
     String name = json.getString(JSON_KEY_NAME);
     String id = json.getString(JSON_KEY_ID);
     String type = json.getString(JSON_KEY_TYPE);
     Boolean isCurrentDevice = json.getBoolean(JSON_KEY_ISCURRENTDEVICE);
-    return new FxAccountDevice(name, id, type, isCurrentDevice);
+    String pushCallback = json.getString(JSON_KEY_PUSH_CALLBACK);
+    String pushPublicKey = json.getString(JSON_KEY_PUSH_PUBLICKEY);
+    String pushAuthKey = json.getString(JSON_KEY_PUSH_AUTHKEY);
+    return new FxAccountDevice(name, id, type, isCurrentDevice, pushCallback, pushPublicKey, pushAuthKey);
   }
 
   public ExtendedJSONObject toJson() {
     final ExtendedJSONObject body = new ExtendedJSONObject();
     if (this.name != null) {
       body.put(JSON_KEY_NAME, this.name);
     }
     if (this.id != null) {
       body.put(JSON_KEY_ID, this.id);
     }
     if (this.type != null) {
       body.put(JSON_KEY_TYPE, this.type);
     }
+    if (this.pushCallback != null) {
+      body.put(JSON_KEY_PUSH_CALLBACK, this.pushCallback);
+    }
+    if (this.pushPublicKey != null) {
+      body.put(JSON_KEY_PUSH_PUBLICKEY, this.pushPublicKey);
+    }
+    if (this.pushAuthKey != null) {
+      body.put(JSON_KEY_PUSH_AUTHKEY, this.pushAuthKey);
+    }
     return body;
   }
 }
--- a/mobile/android/tests/background/junit4/src/org/mozilla/gecko/fxa/login/MockFxAccountClient.java
+++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/fxa/login/MockFxAccountClient.java
@@ -173,30 +173,33 @@ public class MockFxAccountClient impleme
     if (!user.verified) {
       handleFailure(requestDelegate, HttpStatus.SC_BAD_REQUEST, FxAccountRemoteError.ATTEMPT_TO_OPERATE_ON_AN_UNVERIFIED_ACCOUNT, "user is unverified");
       return;
     }
     try {
       String deviceId = deviceToRegister.id;
       if (TextUtils.isEmpty(deviceId)) { // Create
         deviceId = UUID.randomUUID().toString();
-        FxAccountDevice device = new FxAccountDevice(deviceToRegister.name, deviceId, deviceToRegister.type, null);
-        deviceToRegister.id = deviceId;
+        FxAccountDevice device = new FxAccountDevice(deviceToRegister.name, deviceId, deviceToRegister.type, null, null, null, null);
+        requestDelegate.handleSuccess(device);
       } else { // Update
         FxAccountDevice existingDevice = user.devices.get(deviceId);
         if (existingDevice != null) {
+          String deviceName = existingDevice.name;
           if (!TextUtils.isEmpty(deviceToRegister.name)) {
-            existingDevice.name = deviceToRegister.name;
+            deviceName = deviceToRegister.name;
           } // We could also update the other fields..
+          FxAccountDevice device = new FxAccountDevice(deviceName, existingDevice.id, existingDevice.type,
+                  existingDevice.isCurrentDevice, existingDevice.pushCallback, existingDevice.pushPublicKey,existingDevice.pushAuthKey);
+          requestDelegate.handleSuccess(device);
         } else { // Device unknown
           handleFailure(requestDelegate, HttpStatus.SC_BAD_REQUEST, FxAccountRemoteError.UNKNOWN_DEVICE, "device is unknown");
           return;
         }
       }
-      requestDelegate.handleSuccess(deviceToRegister);
     } catch (Exception e) {
       requestDelegate.handleError(e);
     }
   }
 
   @Override
   public void deviceList(byte[] sessionToken, RequestDelegate<FxAccountDevice[]> requestDelegate) {
     String email = sessionTokens.get(Utils.byte2Hex(sessionToken));