Bug 1404044 - Prevent android sync from failing on overlarge timestamps in password sync r?Grisha draft
authorThom Chiovoloni <tchiovoloni@mozilla.com>
Fri, 20 Oct 2017 15:46:05 -0400
changeset 684078 0ca89bb7e2d8558d0caffda42401d5168f26c87d
parent 681761 34db1d5769c1b2c24ee6f50fcee59cd3dac038ab
child 736806 0a279688b751957cbd63e68b08879eec35b25be7
push id85549
push userbmo:tchiovoloni@mozilla.com
push dateFri, 20 Oct 2017 19:47:03 +0000
reviewersGrisha
bugs1404044
milestone58.0a1
Bug 1404044 - Prevent android sync from failing on overlarge timestamps in password sync r?Grisha This was done by way of hacking our vendored version of org.simple.json. MozReview-Commit-ID: GpTFpmeevVN
mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/domain/test/TestPasswordRecord.java
mobile/android/thirdparty/org/json/simple/parser/Yylex.java
new file mode 100644
--- /dev/null
+++ b/mobile/android/tests/background/junit4/src/org/mozilla/gecko/sync/repositories/domain/test/TestPasswordRecord.java
@@ -0,0 +1,50 @@
+/* Any copyright is dedicated to the Public Domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+package org.mozilla.gecko.sync.repositories.domain.test;
+
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mozilla.gecko.background.testhelpers.TestRunner;
+import org.mozilla.gecko.sync.ExtendedJSONObject;
+import org.mozilla.gecko.sync.NonObjectJSONException;
+import org.mozilla.gecko.sync.repositories.domain.PasswordRecord;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+
+@RunWith(TestRunner.class)
+public class TestPasswordRecord {
+    @Test
+    public void testInitFromPayload() {
+        ExtendedJSONObject o = null;
+        try {
+            o = new ExtendedJSONObject("{" +
+                    "\"hostname\": \"https://example.com\",\n" +
+                    "\"formSubmitURL\": \"https://example.com/login\",\n" +
+                    "\"httpRealm\": null,\n" +
+                    "\"username\": \"johndoe\",\n" +
+                    "\"password\": \"p4ssw0rd\",\n" +
+                    "\"usernameField\": \"user\",\n" +
+                    "\"passwordField\": \"pass\",\n" +
+                    // Above the max sane value to ensure we don't regress 1404044
+                    "\"timeLastUsed\": 18446732429235952000" +
+                    "}");
+        } catch (IOException e) {
+            Assert.fail("Somehow got an IOException when parsing json from a string D:");
+        } catch (NonObjectJSONException e) {
+            Assert.fail(e.getMessage());
+        }
+        PasswordRecord p = new PasswordRecord();
+        p.initFromPayload(o);
+        assertEquals(p.encryptedUsername, o.getString("username"));
+        assertEquals(p.encryptedPassword, o.getString("password"));
+        assertEquals(p.usernameField, o.getString("usernameField"));
+        assertEquals(p.passwordField, o.getString("passwordField"));
+        assertEquals(p.formSubmitURL, o.getString("formSubmitURL"));
+        assertEquals(p.hostname, o.getString("hostname"));
+        assertEquals(p.httpRealm, null);
+    }
+}
--- a/mobile/android/thirdparty/org/json/simple/parser/Yylex.java
+++ b/mobile/android/thirdparty/org/json/simple/parser/Yylex.java
@@ -652,17 +652,27 @@ int getPosition(){
           { sb.append('\t');
           }
         case 43: break;
         case 7: 
           { return new Yytoken(Yytoken.TYPE_LEFT_SQUARE,null);
           }
         case 44: break;
         case 2: 
-          { Long val=Long.valueOf(yytext()); return new Yytoken(Yytoken.TYPE_VALUE, val);
+          {
+            String text = yytext();
+            try {
+              Long val = Long.valueOf(text);
+              return new Yytoken(Yytoken.TYPE_VALUE, val);
+            } catch (NumberFormatException e) {
+              // Change from default org.simple.json, adjust parser to make bugs like
+              // 1404044 possible to handle.
+              Double val = Double.valueOf(text);
+              return new Yytoken(Yytoken.TYPE_VALUE, val);
+            }
           }
         case 45: break;
         case 18: 
           { sb.append('\n');
           }
         case 46: break;
         case 9: 
           { return new Yytoken(Yytoken.TYPE_COMMA,null);