X-Git-Url: https://code.wpia.club/?a=blobdiff_plain;f=tests%2Forg%2Fcacert%2Fgigi%2Fapi%2FTestFindAgent.java;h=71bad946b6ad9306b471cd09bbd6e55571ee7a95;hb=8eaf45ee6a71969eff3e04b40e4435e0dd380824;hp=3b8b9927e912107851c71d21765f17e79dad72d0;hpb=9def69bd08ea69eb27786d5b34f00e154e09e9f3;p=gigi.git diff --git a/tests/org/cacert/gigi/api/TestFindAgent.java b/tests/org/cacert/gigi/api/TestFindAgent.java index 3b8b9927..71bad946 100644 --- a/tests/org/cacert/gigi/api/TestFindAgent.java +++ b/tests/org/cacert/gigi/api/TestFindAgent.java @@ -7,6 +7,7 @@ import java.io.IOException; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.security.GeneralSecurityException; +import java.util.Arrays; import org.cacert.gigi.GigiApiException; import org.cacert.gigi.dbObjects.Certificate; @@ -20,6 +21,9 @@ import org.cacert.gigi.pages.account.FindAgentAccess; import org.cacert.gigi.testUtils.IOUtils; import org.cacert.gigi.testUtils.RestrictedApiTest; import org.cacert.gigi.testUtils.TestEmailReceiver.TestMail; +import org.json.JSONArray; +import org.json.JSONObject; +import org.json.JSONTokener; import org.junit.Test; public class TestFindAgent extends RestrictedApiTest { @@ -33,7 +37,7 @@ public class TestFindAgent extends RestrictedApiTest { assertEquals(501, v.getResponseCode()); assertThat(IOUtils.readURL(new InputStreamReader(v.getErrorStream(), "UTF-8")), containsString(FindAgentAccess.PATH)); - grant(u.getEmail(), Group.LOCATE_AGENT); + grant(u, Group.LOCATE_AGENT); v = doApi(FindAgent.PATH_RESOLVE, "serial=" + target2.getSerial().toLowerCase()); assertEquals(u.getId(), Integer.parseInt(IOUtils.readURL(v))); } @@ -58,13 +62,13 @@ public class TestFindAgent extends RestrictedApiTest { assertThat(v.getResponseMessage(), containsString("needs to enable access")); // even if sender enables service - grant((userUFirst ? u : us2).getEmail(), Group.LOCATE_AGENT); + grant((userUFirst ? u : us2), Group.LOCATE_AGENT); v = doApi(FindAgent.PATH_MAIL, "from=" + id + "&to=" + u2 + "&subject=the-subject&body=body"); assertEquals(v.getResponseMessage(), 501, v.getResponseCode()); assertThat(v.getResponseMessage(), containsString("needs to enable access")); // receiver needs to enable access as well - grant((userUFirst ? us2 : u).getEmail(), Group.LOCATE_AGENT); + grant((userUFirst ? us2 : u), Group.LOCATE_AGENT); v = doApi(FindAgent.PATH_MAIL, "from=" + id + "&to=" + u2 + "&subject=the-subject&body=body"); assertEquals(v.getResponseMessage(), 200, v.getResponseCode()); TestMail mail = getMailReceiver().receive(); @@ -78,10 +82,21 @@ public class TestFindAgent extends RestrictedApiTest { int u2 = createVerifiedUser("f", "l", createUniqueName() + "@email.com", TEST_PASSWORD); String res = IOUtils.readURL(doApi(FindAgent.PATH_INFO, "id=" + id + "&id=" + u2)).replace("\r", ""); - assertEquals(res, ""); - grant(email, Group.LOCATE_AGENT); - grant(User.getById(u2).getEmail(), Group.LOCATE_AGENT); res = IOUtils.readURL(doApi(FindAgent.PATH_INFO, "id=" + id + "&id=" + u2)).replace("\r", ""); - assertEquals(id + ",true," + u.getPreferredName().toAbbreviatedString() + "\n" + u2 + ",false," + User.getById(u2).getPreferredName().toAbbreviatedString() + "\n", res); + assertEquals(new JSONArray().toString(), new JSONArray(new JSONTokener(res)).toString()); + grant(u, Group.LOCATE_AGENT); + grant(User.getById(u2), Group.LOCATE_AGENT); + res = IOUtils.readURL(doApi(FindAgent.PATH_INFO, "id=" + id + "&id=" + u2)).replace("\r", ""); + JSONTokener jt = new JSONTokener(res); + JSONObject j1 = new JSONObject(); + j1.put("id", id); + j1.put("canAssure", true); + j1.put("name", u.getPreferredName().toAbbreviatedString()); + JSONObject j2 = new JSONObject(); + j2.put("id", u2); + j2.put("canAssure", false); + j2.put("name", User.getById(u2).getPreferredName().toAbbreviatedString()); + JSONArray ja = new JSONArray(Arrays.asList(j1, j2)); + assertEquals(ja.toString(), new JSONArray(jt).toString()); } }