File tree Expand file tree Collapse file tree 2 files changed +35
-12
lines changed
test/java/com/fusiondb/studio/api Expand file tree Collapse file tree 2 files changed +35
-12
lines changed Original file line number Diff line number Diff line change @@ -76,23 +76,29 @@ declare
7676 %rest:produces("application/json" )
7777 %output:method("json" )
7878function api:explorer ($uri) {
79- api:with-valid-uri-ex ($uri, function ($uri) {
79+ if (count ($uri) eq 1 and ($uri[1 ] = ("/" , "/db" ) or fn:starts-with ($uri[1 ], "/db/" )))
80+ then
8081 if (sm:has-access ($uri, "r-x" ))
8182 then
82- [
83- (),
83+ api:cors-allow (
8484 exp:describe ($uri)
85- ]
85+ )
8686 else
87- [
87+ api:cors-allow (
88+ map {
89+ "code" : $hsc:forbidden,
90+ "reason" : "User: " || (sm:id ()//sm:username)[1 ] || " is not permitted to access: " || $uri
91+ },
92+ ()
93+ )
94+ else
95+ api:cors-allow (
8896 map {
89- "code" : $hsc:forbidden ,
90- "reason" : "User: " || ( sm:id ()//sm:username)[ 1 ] || " is not permitted to access: " || $uri
97+ "code" : $hsc:bad-request ,
98+ "reason" : "URI must start / or /db"
9199 },
92100 ()
93- ]
94-
95- })
101+ )
96102};
97103
98104declare
Original file line number Diff line number Diff line change 2222import static com .fusiondb .studio .api .API .getApiBaseUri ;
2323import static io .restassured .RestAssured .when ;
2424import static io .restassured .module .jsv .JsonSchemaValidator .matchesJsonSchemaInClasspath ;
25- import static org .apache .http .HttpStatus .SC_FORBIDDEN ;
26- import static org .apache .http .HttpStatus .SC_OK ;
25+ import static org .apache .http .HttpStatus .*;
2726
2827public class ExplorerIT {
2928
3029 @ Test
3130 public void root () {
31+ when ().
32+ get (getApiBaseUri () + "/explorer?uri=/" ).
33+ then ().
34+ statusCode (SC_OK ).
35+ assertThat ().
36+ body (matchesJsonSchemaInClasspath ("explorer-schema.json" ));
37+ }
38+
39+ @ Test
40+ public void db () {
3241 when ().
3342 get (getApiBaseUri () + "/explorer?uri=/db" ).
3443 then ().
@@ -37,6 +46,14 @@ public void root() {
3746 body (matchesJsonSchemaInClasspath ("explorer-schema.json" ));
3847 }
3948
49+ @ Test
50+ public void invalidUri () {
51+ when ().
52+ get (getApiBaseUri () + "/explorer?uri=/invalid" ).
53+ then ().
54+ statusCode (SC_BAD_REQUEST );
55+ }
56+
4057 /**
4158 * Attempt to access a non-public Collection as guest user.
4259 */
You can’t perform that action at this time.
0 commit comments