Search in sources :

Example 1 with RequestMatcherExtension

use of com.github.tomakehurst.wiremock.matching.RequestMatcherExtension in project box-java-sdk by box.

the class BoxDeveloperEditionAPIConnectionTest method getRequestMatcher.

private RequestMatcherExtension getRequestMatcher(final String tokenPath) {
    return new RequestMatcherExtension() {

        @Override
        public MatchResult match(Request request, Parameters parameters) {
            if (!request.getMethod().equals(RequestMethod.POST) || !request.getUrl().equals(tokenPath)) {
                return MatchResult.noMatch();
            }
            Assert.assertNotNull("JTI should be saved from previous request", BoxDeveloperEditionAPIConnectionTest.this.jtiClaim);
            try {
                JwtClaims claims = BoxDeveloperEditionAPIConnectionTest.this.getClaimsFromRequest(request);
                String jti = claims.getJwtId();
                long expTimestamp = claims.getExpirationTime().getValue();
                Assert.assertNotEquals("JWT should have a new timestamp", 1511003910L, expTimestamp);
                Assert.assertNotEquals("JWT should have a new jti claim", BoxDeveloperEditionAPIConnectionTest.this.jtiClaim, jti);
            } catch (Exception ex) {
                Assert.fail("Could not parse JWT when request is retried: " + ex.getMessage());
            }
            return MatchResult.exactMatch();
        }
    };
}
Also used : Parameters(com.github.tomakehurst.wiremock.extension.Parameters) JwtClaims(org.jose4j.jwt.JwtClaims) Request(com.github.tomakehurst.wiremock.http.Request) RequestMatcherExtension(com.github.tomakehurst.wiremock.matching.RequestMatcherExtension)

Aggregations

Parameters (com.github.tomakehurst.wiremock.extension.Parameters)1 Request (com.github.tomakehurst.wiremock.http.Request)1 RequestMatcherExtension (com.github.tomakehurst.wiremock.matching.RequestMatcherExtension)1 JwtClaims (org.jose4j.jwt.JwtClaims)1