Skip to content

Commit

Permalink
Fix to rollback action version endpoint (#370)
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmyjames authored Aug 26, 2021
1 parent 83fb5ab commit 820b5fd
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
21 changes: 20 additions & 1 deletion src/main/java/com/auth0/client/mgmt/ActionsEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
import com.auth0.utils.Asserts;
import com.fasterxml.jackson.core.type.TypeReference;
import okhttp3.HttpUrl;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.RequestBody;

/**
* Class that provides an implementation of the Actions methods of the Management API as defined in https://auth0.com/docs/api/management/v2#!/Actions
Expand Down Expand Up @@ -266,7 +268,8 @@ public Request<Version> rollBackToVersion(String actionId, String actionVersionI
.build()
.toString();

EmptyBodyRequest<Version> request = new EmptyBodyRequest<>(client, url, "POST", new TypeReference<Version>() {
// Needed to successfully call the roll-back endpoint until DXEX-1738 is resolved.
EmptyObjectRequest<Version> request = new EmptyObjectRequest<>(client, url, "POST", new TypeReference<Version>() {
});

request.addHeader(AUTHORIZATION_HEADER, "Bearer " + apiToken);
Expand Down Expand Up @@ -428,4 +431,20 @@ private void applyFilter(BaseFilter filter, HttpUrl.Builder builder) {
filter.getAsMap().forEach((k, v) -> builder.addQueryParameter(k, String.valueOf(v)));
}
}

// Temporary request implementation to send an empty json object on the request body.
private static class EmptyObjectRequest<T> extends EmptyBodyRequest<T> {
EmptyObjectRequest(OkHttpClient client, String url, String method, TypeReference<T> tType) {
super(client, url, method, tType);
}

@Override
@SuppressWarnings("deprecation")
protected RequestBody createRequestBody() {
// Use OkHttp v3 signature to ensure binary compatibility between v3 and v4
// https://github.com/auth0/auth0-java/issues/324
return RequestBody.create(MediaType.parse("application/json"), "{}".getBytes());
}

}
}
3 changes: 2 additions & 1 deletion src/test/java/com/auth0/client/mgmt/ActionsEntityTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.*;

import static com.auth0.client.MockServer.bodyFromRequest;
import static com.auth0.client.MockServer.readFromRequest;
import static com.auth0.client.RecordedRequestMatcher.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
Expand Down Expand Up @@ -304,7 +305,7 @@ public void shouldRollBackActionVersion() throws Exception {
assertThat(recordedRequest, hasHeader("Content-Type", "application/json"));
assertThat(recordedRequest, hasHeader("Authorization", "Bearer apiToken"));
assertThat(recordedRequest.getBody(), is(notNullValue()));
assertThat(recordedRequest.getBody().size(), is(0L));
assertThat(readFromRequest(recordedRequest), is("{}"));

assertThat(response, is(notNullValue()));
}
Expand Down

0 comments on commit 820b5fd

Please sign in to comment.