X-Git-Url: https://code.wpia.club/?p=gigi.git;a=blobdiff_plain;f=tests%2Forg%2Fcacert%2Fgigi%2Fapi%2FImportCATSResult.java;h=4a90500dc6dc722fe448168e512d0fe56d55d356;hp=41c49c564dd3ce00a479c5dad7d2cab628f47fbf;hb=60ebf68ed0f78b0353903ff7845c4c611a82e62d;hpb=31bd86b7903b06266a84b3350914858c8a207b35 diff --git a/tests/org/cacert/gigi/api/ImportCATSResult.java b/tests/org/cacert/gigi/api/ImportCATSResult.java index 41c49c56..4a90500d 100644 --- a/tests/org/cacert/gigi/api/ImportCATSResult.java +++ b/tests/org/cacert/gigi/api/ImportCATSResult.java @@ -73,21 +73,41 @@ public class ImportCATSResult extends ClientTest { apiImport(u2, "Test Training"); assertEquals(1, u2.getTrainings().length); assertFalse(u2.hasPassedCATS()); - apiImport(u2, CATS.ASSURER_CHALLANGE_NAME); + apiImport(u2, CATS.ASSURER_CHALLENGE_NAME); assertEquals(2, u2.getTrainings().length); assertTrue(u2.hasPassedCATS()); } + @Test + public void testImportCATSFailures() throws GigiApiException, IOException, GeneralSecurityException, InterruptedException { + assertEquals(1, u.getTrainings().length); + assertNotEquals(200, executeImportQuery("").getResponseCode()); + assertNotEquals(200, executeImportQuery("mid=" + u.getId()).getResponseCode()); + assertNotEquals(200, executeImportQuery("mid=" + u.getId() + "&variant=Test+Training").getResponseCode()); + assertNotEquals(200, executeImportQuery("mid=" + u.getId() + "&variant=Test+Training&date=" + System.currentTimeMillis()).getResponseCode()); + assertNotEquals(200, executeImportQuery("mid=" + u.getId() + "&variant=Test+Training&date=" + System.currentTimeMillis() + "&language=en").getResponseCode()); + assertNotEquals(200, executeImportQuery("mid=" + u.getId() + "&variant=Test+Training&date=" + System.currentTimeMillis() + "&version=1.0").getResponseCode()); + assertEquals(1, u.getTrainings().length); + apiImport(u, "Test Training"); + assertEquals(2, u.getTrainings().length); + + } + private void apiImport(User target, String test) throws IOException, MalformedURLException, NoSuchAlgorithmException, KeyManagementException, UnsupportedEncodingException, GeneralSecurityException { + HttpURLConnection connection = executeImportQuery("mid=" + target.getId() + "&variant=" + URLEncoder.encode(test, "UTF-8") + "&date=" + System.currentTimeMillis() + "&language=en&version=1.0"); + if (connection.getResponseCode() != 200) { + throw new Error(connection.getResponseMessage()); + } + } + + private HttpURLConnection executeImportQuery(String query) throws IOException, MalformedURLException, NoSuchAlgorithmException, KeyManagementException, UnsupportedEncodingException, Error { HttpURLConnection connection = (HttpURLConnection) new URL("https://" + getServerName().replaceFirst("^www.", "api.") + CATSImport.PATH).openConnection(); authenticateClientCert(pk, ce, connection); connection.setDoOutput(true); OutputStream os = connection.getOutputStream(); - os.write(("mid=" + target.getId() + "&variant=" + URLEncoder.encode(test, "UTF-8") + "&date=" + System.currentTimeMillis()).getBytes("UTF-8")); - if (connection.getResponseCode() != 200) { - throw new Error(connection.getResponseMessage()); - } + os.write(query.getBytes("UTF-8")); + return connection; } private String apiLookup(Certificate target) throws IOException, MalformedURLException, NoSuchAlgorithmException, KeyManagementException, UnsupportedEncodingException, GeneralSecurityException {