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

--HG--
extra : rebase_source : 2a29b53919a617e2ea89d776a53a43257959bc22
This commit is contained in:
Thom Chiovoloni 2017-10-20 15:46:05 -04:00
Родитель cd5f71abe4
Коммит b367ef8b16
2 изменённых файлов: 61 добавлений и 1 удалений

Просмотреть файл

@ -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);
}
}

Просмотреть файл

@ -657,7 +657,17 @@ int getPosition(){
}
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: