Skip to content

Commit c44dc56

Browse files
committed
Explorer should allow starting from '/'
1 parent 806452c commit c44dc56

File tree

2 files changed

+35
-12
lines changed

2 files changed

+35
-12
lines changed

src/main/xar-resources/api.xqm

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,23 +76,29 @@ declare
7676
%rest:produces("application/json")
7777
%output:method("json")
7878
function 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

98104
declare

src/test/java/com/fusiondb/studio/api/ExplorerIT.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,22 @@
2222
import static com.fusiondb.studio.api.API.getApiBaseUri;
2323
import static io.restassured.RestAssured.when;
2424
import 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

2827
public 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
*/

0 commit comments

Comments
 (0)