@@ -1975,6 +1975,30 @@ public void listObjects_500() throws Exception {
1975
1975
"{\" code\" :\" internal_error\" ,\" message\" :\" Internal Server Error\" }" , exception .getResponseData ());
1976
1976
}
1977
1977
1978
+ @ Test
1979
+ public void listObjectsWithContextTest () throws Exception {
1980
+ // Given
1981
+ String postPath = String .format ("https://localhost/stores/%s/list-objects" , DEFAULT_STORE_ID );
1982
+ String expectedBody = String .format (
1983
+ "{\" authorization_model_id\" :\" %s\" ,\" type\" :null,\" relation\" :\" %s\" ,\" user\" :\" %s\" ,\" contextual_tuples\" :null,\" context\" :{\" some\" :\" context\" }}" ,
1984
+ DEFAULT_AUTH_MODEL_ID , DEFAULT_RELATION , DEFAULT_USER );
1985
+ mockHttpClient
1986
+ .onPost (postPath )
1987
+ .withBody (is (expectedBody ))
1988
+ .doReturn (200 , String .format ("{\" objects\" :[\" %s\" ]}" , DEFAULT_OBJECT ));
1989
+ ClientListObjectsRequest request = new ClientListObjectsRequest ()
1990
+ .relation (DEFAULT_RELATION )
1991
+ .user (DEFAULT_USER )
1992
+ .context (Map .of ("some" , "context" ));
1993
+
1994
+ // When
1995
+ ClientListObjectsResponse response = fga .listObjects (request ).get ();
1996
+
1997
+ // Then
1998
+ mockHttpClient .verify ().post (postPath ).withBody (is (expectedBody )).called (1 );
1999
+ assertEquals (List .of (DEFAULT_OBJECT ), response .getObjects ());
2000
+ }
2001
+
1978
2002
/**
1979
2003
* Check whether a user is authorized to access an object.
1980
2004
*/
@@ -2196,6 +2220,54 @@ public void listRelations_500() throws Exception {
2196
2220
"{\" code\" :\" internal_error\" ,\" message\" :\" Internal Server Error\" }" , exception .getResponseData ());
2197
2221
}
2198
2222
2223
+ @ Test
2224
+ public void listRelations_contextAndContextualTuples () throws Exception {
2225
+ // Given
2226
+ String postUrl = String .format ("https://localhost/stores/%s/check" , DEFAULT_STORE_ID );
2227
+ String expectedBody = String .format (
2228
+ "{\" tuple_key\" :{\" user\" :\" %s\" ,\" relation\" :\" %s\" ,\" object\" :\" %s\" },\" contextual_tuples\" :{\" tuple_keys\" :[{\" user\" :\" %s\" ,\" relation\" :\" %s\" ,\" object\" :\" %s\" ,\" condition\" :null}]},\" authorization_model_id\" :\" %s\" ,\" trace\" :null,\" context\" :{\" some\" :\" context\" }}" ,
2229
+ DEFAULT_USER ,
2230
+ "owner" ,
2231
+ DEFAULT_OBJECT ,
2232
+ DEFAULT_USER ,
2233
+ DEFAULT_RELATION ,
2234
+ DEFAULT_OBJECT ,
2235
+ DEFAULT_AUTH_MODEL_ID );
2236
+ mockHttpClient
2237
+ .onPost (postUrl )
2238
+ .withBody (is (expectedBody ))
2239
+ .withHeader (CLIENT_METHOD_HEADER , "BatchCheck" )
2240
+ .withHeader (CLIENT_BULK_REQUEST_ID_HEADER , anyValidUUID ())
2241
+ .doReturn (200 , "{\" allowed\" :false}" );
2242
+ ClientListRelationsRequest request = new ClientListRelationsRequest ()
2243
+ .relations (List .of ("owner" ))
2244
+ ._object (DEFAULT_OBJECT )
2245
+ .user (DEFAULT_USER )
2246
+ .context (Map .of ("some" , "context" ))
2247
+ .contextualTupleKeys (List .of (new ClientTupleKey ()
2248
+ .user (DEFAULT_USER )
2249
+ .relation (DEFAULT_RELATION )
2250
+ ._object (DEFAULT_OBJECT )));
2251
+ ClientListRelationsOptions options =
2252
+ new ClientListRelationsOptions ().authorizationModelId (DEFAULT_AUTH_MODEL_ID );
2253
+
2254
+ // When
2255
+ ClientListRelationsResponse response =
2256
+ fga .listRelations (request , options ).get ();
2257
+
2258
+ // Then
2259
+ mockHttpClient
2260
+ .verify ()
2261
+ .post (postUrl )
2262
+ .withBody (is (expectedBody ))
2263
+ .withHeader (CLIENT_METHOD_HEADER , "BatchCheck" )
2264
+ .withHeader (CLIENT_BULK_REQUEST_ID_HEADER , anyValidUUID ())
2265
+ .called (1 );
2266
+ assertNotNull (response );
2267
+ assertNotNull (response .getRelations ());
2268
+ assertTrue (response .getRelations ().isEmpty ());
2269
+ }
2270
+
2199
2271
/**
2200
2272
* Read assertions for an authorization model ID.
2201
2273
*/
0 commit comments