private String fromGoodContinuationTokenRequest() { return with() .contentType(ContentType.JSON) .accept(ContentType.JSON) .body("{\"username\": \"" + userCredentials.getUsername() + "\", \"clientName\": \"Mozilla Thunderbird\", \"clientVersion\": \"42.0\", \"deviceName\": \"Joe Blogg’s iPhone\"}") .post("/authentication") .body() .path("continuationToken") .toString(); }
@Test public void methodShouldContainPasswordWhenValidResquest() throws Exception { given() .contentType(ContentType.JSON) .accept(ContentType.JSON) .body("{\"username\": \"" + userCredentials.getUsername() + "\", \"clientName\": \"Mozilla Thunderbird\", \"clientVersion\": \"42.0\", \"deviceName\": \"Joe Blogg’s iPhone\"}") .when() .post("/authentication") .then() .statusCode(200) .body("methods", hasItem(userCredentials.getPassword())); }
@Test public void mustReturnJsonResponse() throws Exception { given() .contentType(ContentType.JSON) .accept(ContentType.JSON) .body("{\"username\": \"" + userCredentials.getUsername() + "\", \"clientName\": \"Mozilla Thunderbird\", \"clientVersion\": \"42.0\", \"deviceName\": \"Joe Blogg’s iPhone\"}") .when() .post("/authentication") .then() .statusCode(200) .contentType(ContentType.JSON); }
@Test public void mustReturnContinuationTokenWhenValidResquest() throws Exception { given() .contentType(ContentType.JSON) .accept(ContentType.JSON) .body("{\"username\": \"" + userCredentials.getUsername() + "\", \"clientName\": \"Mozilla Thunderbird\", \"clientVersion\": \"42.0\", \"deviceName\": \"Joe Blogg’s iPhone\"}") .when() .post("/authentication") .then() .statusCode(200) .body("continuationToken", isA(String.class)); }
@Test public void mustReturnAuthenticationFailedWhenContinuationTokenIsRejectedByTheContinuationTokenManager() throws Exception { ContinuationToken badContinuationToken = new ContinuationToken(userCredentials.getUsername(), newDate, "badSignature"); given() .contentType(ContentType.JSON) .accept(ContentType.JSON) .body("{\"token\": \"" + badContinuationToken.serialize() + "\", \"method\": \"password\", \"password\": \"" + userCredentials.getPassword() + "\"}") .when() .post("/authentication") .then() .statusCode(401); }
@Before public void setup() throws Throwable { zonedDateTimeProvider = new FixedDateZonedDateTimeProvider(); zonedDateTimeProvider.setFixedDateTime(oldDate); jmapServer = createJmapServer(zonedDateTimeProvider); jmapServer.start(); RestAssured.requestSpecification = jmapRequestSpecBuilder .setPort(jmapServer.getProbe(JmapGuiceProbe.class).getJmapPort()) .build(); userCredentials = UserCredentials.builder() .username("user@domain.tld") .password("password") .build(); String domain = "domain.tld"; jmapServer.getProbe(DataProbeImpl.class) .fluent() .addDomain(domain) .addUser(userCredentials.getUsername(), userCredentials.getPassword()); }