@Inject private UploadStepdefs(UserStepdefs userStepdefs, MainStepdefs mainStepdefs) throws URISyntaxException { this.userStepdefs = userStepdefs; this.mainStepdefs = mainStepdefs; uploadUri = baseUri(mainStepdefs.jmapServer).setPath("/upload").build(); }
public AccessToken authenticate(String username) { return tokenByUser.computeIfAbsent(username, (user) -> { String password = passwordByUser.get(user); Preconditions.checkState(password != null, "unknown user " + user); return authenticateJamesUser(baseUri(mainStepdefs.jmapServer), user, password); }); }
@When("^un-authenticated user downloads \"([^\"]*)\"$") public void downloadsUnAuthenticated(String blobId) throws Throwable { String attachmentIdOrMessageId = Optional.ofNullable(blobIdByAttachmentId.get(blobId)) .orElse(Optional.ofNullable(inputToMessageId.get(blobId)) .map(MessageId::serialize) .orElse(null)); response = Request.Get( baseUri(mainStepdefs.jmapServer) .setPath("/download/" + attachmentIdOrMessageId) .build()) .execute() .returnResponse(); }
@When("^\"(?:[^\"]*)\" downloads \"([^\"]*)\" without any authentication token$") public void getDownloadWithoutToken(String attachmentId) throws Exception { String blobId = blobIdByAttachmentId.get(attachmentId); response = Request.Get(baseUri(mainStepdefs.jmapServer).setPath("/download/" + blobId).build()) .execute() .returnResponse(); }
private void downLoad(String username, String blobId) throws IOException, URISyntaxException { URIBuilder uriBuilder = baseUri(mainStepdefs.jmapServer).setPath("/download/" + blobId); response = authenticatedDownloadRequest(uriBuilder, blobId, username).execute().returnResponse(); }
@When("^\"(?:[^\"]*)\" downloads \"([^\"]*)\" with a bad authentication token$") public void getDownloadWithBadToken(String attachmentId) throws Exception { String blobId = blobIdByAttachmentId.get(attachmentId); response = Request.Get( baseUri(mainStepdefs.jmapServer) .setPath("/download/" + blobId) .addParameter("access_token", "bad") .build()) .execute() .returnResponse(); }
@When("^\"(?:[^\"]*)\" downloads \"([^\"]*)\" with an invalid authentication token$") public void getDownloadWithUnknownToken(String attachmentId) throws Exception { String blobId = blobIdByAttachmentId.get(attachmentId); response = Request.Get( baseUri(mainStepdefs.jmapServer) .setPath("/download/" + blobId) .addParameter("access_token", INVALID_ATTACHMENT_TOKEN) .build()) .execute() .returnResponse(); }
@When("^\"([^\"]*)\" downloads \"([^\"]*)\" with \"([^\"]*)\" name$") public void downloadsWithName(String username, String attachmentId, String name) throws Exception { String blobId = blobIdByAttachmentId.get(attachmentId); URIBuilder uriBuilder = baseUri(mainStepdefs.jmapServer).setPath("/download/" + blobId + "/" + name); response = authenticatedDownloadRequest(uriBuilder, blobId, username) .execute() .returnResponse(); }
@When("^\"(?:[^\"]*)\" downloads \"([^\"]*)\" with an empty authentication token$") public void getDownloadWithEmptyToken(String attachmentId) throws Exception { String blobId = blobIdByAttachmentId.get(attachmentId); response = Request.Get( baseUri(mainStepdefs.jmapServer) .setPath("/download/" + blobId) .addParameter("access_token", "") .build()) .execute() .returnResponse(); }
@When("^\"(?:[^\"]*)\" downloads \"([^\"]*)\" with an expired token$") public void getDownloadWithExpiredToken(String attachmentId) throws Exception { String blobId = blobIdByAttachmentId.get(attachmentId); response = Request.Get(baseUri(mainStepdefs.jmapServer).setPath("/download/" + blobId) .addParameter("access_token", EXPIRED_ATTACHMENT_TOKEN) .build()) .execute() .returnResponse(); }
@When("^\"([^\"]*)\" downloads \"([^\"]*)\" with wrong blobId$") public void getDownloadWithWrongBlobId(String username, String attachmentId) throws Throwable { String blobId = blobIdByAttachmentId.get(attachmentId); URIBuilder uriBuilder = baseUri(mainStepdefs.jmapServer).setPath("/download/badbadbadbadbadbadbadbadbadbadbadbadbadb"); trustForBlobId(blobId, username); AttachmentAccessTokenKey key = new AttachmentAccessTokenKey(username, blobId); uriBuilder.addParameter("access_token", attachmentAccessTokens.get(key).serialize()); response = Request.Get(uriBuilder.build()) .execute() .returnResponse(); }
@When("^\"([^\"]*)\" downloads \"([^\"]*)\" without blobId parameter$") public void getDownloadWithoutBlobId(String username, String attachmentId) throws Throwable { String blobId = blobIdByAttachmentId.get(attachmentId); URIBuilder uriBuilder = baseUri(mainStepdefs.jmapServer).setPath("/download/"); trustForBlobId(blobId, username); AttachmentAccessTokenKey key = new AttachmentAccessTokenKey(username, blobId); uriBuilder.addParameter("access_token", attachmentAccessTokens.get(key).serialize()); response = Request.Get(uriBuilder.build()) .execute() .returnResponse(); }
@When("^\"([^\"]*)\" asks for a token for attachment \"([^\"]*)\"$") public void postDownload(String username, String attachmentId) throws Throwable { String blobId = blobIdByAttachmentId.get(attachmentId); AccessToken accessToken = userStepdefs.authenticate(username); response = Request.Post(baseUri(mainStepdefs.jmapServer).setPath("/download/" + blobId).build()) .addHeader("Authorization", accessToken.serialize()) .execute() .returnResponse(); }
@Then("^\"([^\"]*)\" should be able to retrieve the content$") public void contentShouldBeRetrievable(String username) throws Exception { AccessToken accessToken = userStepdefs.authenticate(username); DocumentContext jsonPath = JsonPath.parse(response.getEntity().getContent()); Request request = Request.Get(baseUri(mainStepdefs.jmapServer).setPath("/download/" + jsonPath.<String>read("blobId")).build()); if (accessToken != null) { request.addHeader("Authorization", accessToken.serialize()); } response = request.execute().returnResponse(); httpAuthorizedStatus(); }
@When("^\"([^\"]*)\" checks for the availability of the attachment endpoint$") public void optionDownload(String username) throws Throwable { AccessToken accessToken = userStepdefs.authenticate(username); URI target = baseUri(mainStepdefs.jmapServer).setPath("/download/" + ONE_ATTACHMENT_EML_ATTACHMENT_BLOB_ID).build(); Request request = Request.Options(target); if (accessToken != null) { request.addHeader("Authorization", accessToken.serialize()); } response = request.execute().returnResponse(); }
private void trustForBlobId(String blobId, String username) throws Exception { Response tokenGenerationResponse = Request.Post(baseUri(mainStepdefs.jmapServer).setPath("/download/" + blobId).build()) .addHeader("Authorization", userStepdefs.authenticate(username).serialize()) .execute(); String serializedAttachmentAccessToken = tokenGenerationResponse.returnContent().asString(); attachmentAccessTokens.put( new AttachmentAccessTokenKey(username, blobId), AttachmentAccessToken.from( serializedAttachmentAccessToken, blobId)); }
@When("^\"([^\"]*)\" downloads \"(?:[^\"]*)\" with a valid authentication token but a bad blobId$") public void downloadsWithValidToken(String username) { userStepdefs.execWithUser(username, () -> { URIBuilder uriBuilder = baseUri(mainStepdefs.jmapServer).setPath("/download/badblobId"); response = Request.Get(uriBuilder.build()) .addHeader("Authorization", userStepdefs.authenticate(username).serialize()) .execute() .returnResponse(); }); }
public void post(String requestBody) throws Exception { response = Request.Post(baseUri(mainStepdefs.jmapServer).setPath("/jmap").build()) .addHeader("Authorization", userStepdefs.authenticate(userStepdefs.getConnectedUser()).serialize()) .addHeader("Accept", org.apache.http.entity.ContentType.APPLICATION_JSON.getMimeType()) .bodyString(requestBody, org.apache.http.entity.ContentType.APPLICATION_JSON) .execute() .returnResponse(); jsonPath = JsonPath.using(Configuration.defaultConfiguration() .addOptions(Option.SUPPRESS_EXCEPTIONS)) .parse(response.getEntity().getContent()); } }
@Test public void provisionMailboxesShouldSubscribeToThem() throws Exception { String token = authenticateJamesUser(baseUri(jmapServer), USER, PASSWORD).serialize(); with() .header("Authorization", token) .body("[[\"getMailboxes\", {}, \"#0\"]]") .post("/jmap"); assertThat(jmapServer.getProbe(MailboxProbeImpl.class) .listSubscriptions(USER)) .containsAll(DefaultMailboxes.DEFAULT_MAILBOXES); } }
@Before public void setup() throws Throwable { jmapServer = createJmapServer(); jmapServer.start(); jmapGuiceProbe = jmapServer.getProbe(JmapGuiceProbe.class); RestAssured.requestSpecification = jmapRequestSpecBuilder .setPort(jmapGuiceProbe.getJmapPort()) .build(); jmapServer.getProbe(DataProbeImpl.class) .fluent() .addDomain(DOMAIN) .addUser(USER, PASSWORD); accessToken = authenticateJamesUser(baseUri(jmapServer), USER, PASSWORD); }