Skip to content

Commit

Permalink
fix(java-sdk): don't send tuple key on empty read request
Browse files Browse the repository at this point in the history
closes #30
  • Loading branch information
booniepepper committed Oct 31, 2023
1 parent a386024 commit 9ea73d6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -227,18 +227,17 @@ public class OpenFgaClient {
String storeId = configuration.getStoreIdChecked();
ReadRequest body = new ReadRequest();
TupleKey tupleKey = new TupleKey();
if (request != null) {
if (request != null && (request.getUser() != null || request.getRelation() != null || request.getObject() != null)) {
TupleKey tupleKey = new TupleKey();
tupleKey.user(request.getUser()).relation(request.getRelation())._object(request.getObject());
body.tupleKey(tupleKey);
}

if (options != null) {
body.pageSize(options.getPageSize()).continuationToken(options.getContinuationToken());
}

body.tupleKey(tupleKey);

return call(() -> api.read(storeId, body)).thenApply(ClientReadResponse::new);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,21 @@ public class OpenFgaClientTest {
assertEquals(DEFAULT_OBJECT, key.getObject());
}

@Test
public void read_emptyRequestSendsNoTupleKey() throws Exception {
// Given
String postUrl = String.format("https://localhost/stores/%s/read", DEFAULT_STORE_ID);
String expectedBody = "{\"tuple_key\":null,\"page_size\":null,\"continuation_token\":null}";
mockHttpClient.onPost(postUrl).withBody(is(expectedBody)).doReturn(200, EMPTY_RESPONSE_BODY);
ClientReadRequest request = new ClientReadRequest();
// When
ClientReadResponse response = fga.read(request).get();
// Then
mockHttpClient.verify().post(postUrl).withBody(is(expectedBody)).called(1);
}

@Test
public void read_storeIdRequired() {
// Given
Expand Down

0 comments on commit 9ea73d6

Please sign in to comment.