diff --git a/LICENSE.txt b/LICENSE.txt
index 534e44ea185b..fef2417edf2c 100644
--- a/LICENSE.txt
+++ b/LICENSE.txt
@@ -224,3 +224,26 @@ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+==========================================================================
+The following license applies to the Scalar API Reference JavaScript library
+--------------------------------------------------------------------------
+Copyright (c) 2023-present Scalar, https://github.com/scalar/scalar
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+
diff --git a/NOTICE.txt b/NOTICE.txt
index 7cd5811b2b47..69b6b70eba8c 100644
--- a/NOTICE.txt
+++ b/NOTICE.txt
@@ -30,6 +30,9 @@ License: ISC https://github.com/d3/d3/blob/main/LICENSE
This product includes the highlight.js Javascript library created by Ivan Sagalaev
Copyright (c) 2006, Ivan Sagalaev, https://github.com/isagalaev/highlight.js
+This product includes the Scalar API Reference JavaScript library.
+Copyright (c) 2023-present Scalar, https://github.com/scalar/scalar
+
This product includes the Chosen Javascript library created by Patrick Filler
Copyright (c) 2011-2014 by Harvest, https://github.com/harvesthq/chosen
diff --git a/changelog/unreleased/PR-5201-api-explorer.yml b/changelog/unreleased/PR-5201-api-explorer.yml
new file mode 100644
index 000000000000..f81c19b42414
--- /dev/null
+++ b/changelog/unreleased/PR-5201-api-explorer.yml
@@ -0,0 +1,7 @@
+title: Add a Scalar based API Explorer to the Solr Admin UI
+type: added
+authors:
+ - name: Eric Pugh
+links:
+ - name: PR#5201
+ url: https://github.com/apache/solr/pull/5201
diff --git a/dev-docs/api-explorer.adoc b/dev-docs/api-explorer.adoc
new file mode 100644
index 000000000000..3f4f328cf002
--- /dev/null
+++ b/dev-docs/api-explorer.adoc
@@ -0,0 +1,38 @@
+= Browsing the V2 API with the API Explorer
+
+Solr's v2 (JAX-RS) API is described by an OpenAPI spec generated at build time
+from the annotated interfaces in `solr/api/src/java/.../client/api/endpoint`.
+The API Explorer is bundled in the Admin UI and renders the generated spec using Scalar.
+It's a standalone page in its own project, `solr/webapp/scalar`, loaded in an iframe
+rather than mounted directly into the Angular app: Scalar manages its own URL hash for deep-linking to operations,
+which conflicts with AngularJS's `ngRoute` (both rewrite `window.location.hash`), causing an
+infinite digest/navigation loop. A dedicated document/window avoids the conflict entirely.
+The project owns everything the explorer needs (`web/index.html`, `web/scalar-init.js`,
+and the Scalar bundle itself), and `:solr:webapp` mounts its
+output at `libs/scalar` in the WAR.
+`LoadAdminUiServlet` permits same-origin frames; the Scalar-specific headers in
+`solr/server/etc/jetty.xml` permit the explorer page to be framed by the Admin UI.
+
+== Usage
+
+Start solr as usual.
+Open the *API Explorer* item in the Admin UI's left nav to browse endpoints and send requests.
+The page and its assets are served locally; API requests go directly to the same Solr origin.
+Executing a request can change the running instance, just as calling its API directly can.
+
+Rebuild the webapp after changing API annotations to refresh the explorer's spec.
+
+== Maintaining Scalar
+
+The build downloads the pinned `@scalar/api-reference` npm archive directly
+(not through npm) and copies its `dist/browser/standalone.js` next to the page.
+The version is recorded as `scalar-api-reference` in `gradle/libs.versions.toml`.
+The archive comes from npm's registry, or from a mirror set with `solr.npm.registry` /
+`SOLR_NPM_REGISTRY` (the same override the node-based builds use); once cached, `--offline` works.
+
+The initializer lives in `web/scalar-init.js` as a
+separate script so it also works with a policy that disallows inline scripts.
+Default CDN fonts, the request proxy, AI chat, hosted-client links, developer tools, and telemetry are disabled.
+
+As with the Admin UI's other JavaScript libraries, Scalar's MIT license is recorded in the
+root `LICENSE.txt` and `NOTICE.txt` rather than in `solr/licenses`.
diff --git a/dev-docs/apis.adoc b/dev-docs/apis.adoc
index b394b16d4522..f8edba1e7ff2 100644
--- a/dev-docs/apis.adoc
+++ b/dev-docs/apis.adoc
@@ -47,6 +47,8 @@ Many libraries implement the JAX-RS spec: Solr currently uses the implementation
These v2 API definitions consist of two parts: a JAX-RS annotated interface in the `api` module "defining" the API, and a class in `core` "implementing" the interface.
Separating the API "definition" and "implementation" in this way allows us to only define each API in a single place, and use code generators to produce other API-related bits such as SolrJ code and ref-guide documentation.
+One of those other bits is an OpenAPI spec - see link:api-explorer.adoc[api-explorer.adoc] for how to browse it with the API Explorer against a running local Solr.
+
=== Writing JAX-RS APIs
Writing a new v2 API may appear daunting, but additions in reality are actually pretty simple:
diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml
index 5a160315f627..693a670550c4 100644
--- a/gradle/libs.versions.toml
+++ b/gradle/libs.versions.toml
@@ -169,6 +169,8 @@ perfmark = "0.27.0"
picocli = "4.7.6"
prometheus-metrics = "1.8.0"
quicktheories = "0.26"
+# @keep Scalar API Reference version used by the webapp
+scalar-api-reference = "1.46.4"
selenium = "4.47.0"
semver4j = "6.0.0"
slf4j = "2.0.20"
@@ -449,6 +451,7 @@ picocli-codegen = { module = "info.picocli:picocli-codegen", version.ref = "pico
prometheus-metrics-expositionformats = { module = "io.prometheus:prometheus-metrics-exposition-formats", version.ref = "prometheus-metrics" }
prometheus-metrics-model = { module = "io.prometheus:prometheus-metrics-model", version.ref = "prometheus-metrics" }
quicktheories-quicktheories = { module = "org.quicktheories:quicktheories", version.ref = "quicktheories" }
+scalar-api-reference = { module = "@scalar:api-reference", version.ref = "scalar-api-reference" }
selenium-chromedriver = { module = "org.seleniumhq.selenium:selenium-chrome-driver", version.ref = "selenium" }
semver4j-semver4j = { module = "org.semver4j:semver4j", version.ref = "semver4j" }
slf4j-api = { module = "org.slf4j:slf4j-api", version.ref = "slf4j" }
diff --git a/settings.gradle b/settings.gradle
index 615bba1a2b64..b9f6d2d39daa 100644
--- a/settings.gradle
+++ b/settings.gradle
@@ -71,6 +71,7 @@ gradle.ext.withJsClient = disableJsClientValue == null || disableJsClientValue !
if (gradle.ext.withJsClient) {
include(":solr:webapp:js-client")
}
+include(":solr:webapp:scalar")
// Configures development for joint Lucene/ Solr composite build.
apply from: file('gradle/lucene-dev/lucene-dev-repo-composite.gradle')
diff --git a/solr/api/src/java/org/apache/solr/client/api/util/ApiMetadata.java b/solr/api/src/java/org/apache/solr/client/api/util/ApiMetadata.java
index 11a70a916d3e..b3381c4766d7 100644
--- a/solr/api/src/java/org/apache/solr/client/api/util/ApiMetadata.java
+++ b/solr/api/src/java/org/apache/solr/client/api/util/ApiMetadata.java
@@ -20,6 +20,7 @@
import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.info.Info;
import io.swagger.v3.oas.annotations.info.License;
+import io.swagger.v3.oas.annotations.servers.Server;
@OpenAPIDefinition(
info =
@@ -27,5 +28,8 @@
title = "v2 API",
description = "OpenAPI spec for Solr's v2 API endpoints",
license = @License(name = "ASL 2.0"),
- version = SolrVersion.LATEST_STRING))
+ version = SolrVersion.LATEST_STRING),
+ // A relative URL keeps API-explorer tooling (e.g. Swagger UI) same-origin with
+ // whichever node ends up serving it, so "try it out" calls need no CORS setup.
+ servers = @Server(url = "/api", description = "This Solr node"))
public class ApiMetadata {}
diff --git a/solr/core/src/java/org/apache/solr/servlet/LoadAdminUiServlet.java b/solr/core/src/java/org/apache/solr/servlet/LoadAdminUiServlet.java
index 83b5ef3fd8e8..d89cb100de9c 100644
--- a/solr/core/src/java/org/apache/solr/servlet/LoadAdminUiServlet.java
+++ b/solr/core/src/java/org/apache/solr/servlet/LoadAdminUiServlet.java
@@ -72,7 +72,7 @@ public void doGet(HttpServletRequest request, HttpServletResponse response) thro
HttpHeaders.CONTENT_SECURITY_POLICY,
"default-src 'none'; base-uri 'none'; connect-src "
+ connectSrc
- + "; form-action 'self'; font-src 'self'; frame-ancestors 'none'; img-src 'self' data:; media-src 'self'; style-src 'self' 'unsafe-inline'; script-src 'self'; worker-src 'self';");
+ + "; form-action 'self'; font-src 'self'; frame-ancestors 'none'; frame-src 'self'; img-src 'self' data:; media-src 'self'; style-src 'self' 'unsafe-inline'; script-src 'self'; worker-src 'self';");
// We have to close this to flush OutputStreamWriter buffer
try (Writer out =
diff --git a/solr/server/etc/jetty.xml b/solr/server/etc/jetty.xml
index c6d637b32e8f..c5d24e8fce1d 100644
--- a/solr/server/etc/jetty.xml
+++ b/solr/server/etc/jetty.xml
@@ -90,6 +90,22 @@
+
+
+
+
+ /solr/libs/scalar/index.html
+ Content-Security-Policy
+ default-src 'none'; base-uri 'none'; connect-src 'self'; form-action 'self'; font-src 'self'; frame-ancestors 'self'; img-src 'self' data:; media-src 'self'; style-src 'self' 'unsafe-inline'; script-src 'self'; worker-src 'self';
+
+
+
+
diff --git a/solr/solr-ref-guide/modules/getting-started/pages/solr-admin-ui.adoc b/solr/solr-ref-guide/modules/getting-started/pages/solr-admin-ui.adoc
index 0ff1885be0e5..d0a97db67a46 100644
--- a/solr/solr-ref-guide/modules/getting-started/pages/solr-admin-ui.adoc
+++ b/solr/solr-ref-guide/modules/getting-started/pages/solr-admin-ui.adoc
@@ -49,6 +49,12 @@ The path to the Solr Admin UI given above is `\http://hostname:port/solr`, which
A convenience redirect is also supported, so simply accessing the Admin UI at `\http://hostname:port/` will also redirect to `\http://hostname:port/solr/#/`.
====
+=== API Explorer
+
+The *API Explorer* item in the Admin UI's left-hand navigation opens interactive documentation for Solr's v2 API.
+It renders the OpenAPI specification bundled with Solr and lets you browse endpoints and send requests to the running instance.
+Requests use the instance's authentication and authorization rules and can modify its data or configuration.
+
=== Login Screen
If authentication has been enabled, Solr will present a login screen to unauthenticated users before allowing them further access to the Admin UI.
diff --git a/solr/webapp/build.gradle b/solr/webapp/build.gradle
index 02b60ad323c1..5f8c011ddf87 100644
--- a/solr/webapp/build.gradle
+++ b/solr/webapp/build.gradle
@@ -41,6 +41,8 @@ configurations {
solrCore
generatedJSClientBundle
uiBundle
+ openapiSpec
+ scalarBundle
}
dependencies {
@@ -53,6 +55,10 @@ dependencies {
generatedJSClientBundle project(path: ":solr:webapp:js-client", configuration: "jsClientBundle")
}
uiBundle files(layout.buildDirectory.dir("generated/ui-resources")) { builtBy tasks.named('prepareUiResources') }
+ // Supplies the generated specification to the API Explorer.
+ openapiSpec project(path: ":solr:api", configuration: "openapiSpec")
+ // Supplies the API Explorer, a standalone Scalar page the Admin UI loads in an iframe.
+ scalarBundle project(path: ":solr:webapp:scalar", configuration: "scalarBundle")
// Browser-based tests of the AngularJS Admin UI (see src/test)
testImplementation project(':solr:core')
@@ -108,6 +114,20 @@ tasks.withType(Test).configureEach {
logger.warn('NOTE: :solr:webapp tests are disabled because -PdisableJsClient=true ' +
'excludes the js-client bundle the Admin UI tests need.')
}
+
+ // The API Explorer (its own project) and the OpenAPI spec it fetches are built separately
+ // and mounted into the war; like the js-client bundle above, neither exists in the source
+ // tree these tests serve.
+ if (seleniumEnabled) {
+ def scalarBundle = configurations.scalarBundle
+ def openapiSpec = configurations.openapiSpec
+ inputs.files(scalarBundle).withPropertyName('scalarBundle')
+ inputs.files(openapiSpec).withPropertyName('openapiSpec')
+ doFirst {
+ systemProperty 'tests.ui.scalar.bundle', scalarBundle.singleFile
+ systemProperty 'tests.ui.scalar.spec', openapiSpec.singleFile
+ }
+ }
}
war {
@@ -121,6 +141,17 @@ war {
from(configurations.uiBundle, {
into "ui"
})
+
+ // Supplies the generated specification to the API Explorer.
+ from(configurations.openapiSpec, {
+ into "libs/scalar"
+ rename { "spec.json" }
+ })
+
+ // Supplies the API Explorer, a standalone Scalar page the Admin UI loads in an iframe.
+ from(configurations.scalarBundle, {
+ into "libs/scalar"
+ })
}
// Expose 'war' archive as an artifact so that it can be packaged in the distribution.
diff --git a/solr/webapp/gradle.lockfile b/solr/webapp/gradle.lockfile
index a64f6c31ce7e..e402dba4fa18 100644
--- a/solr/webapp/gradle.lockfile
+++ b/solr/webapp/gradle.lockfile
@@ -206,4 +206,4 @@ org.slf4j:jul-to-slf4j:2.0.20=serverLib
org.slf4j:slf4j-api:2.0.20=jarValidation,serverLib,solrCore,testCompileClasspath,testRuntimeClasspath
org.testcontainers:testcontainers:2.0.5=jarValidation,testRuntimeClasspath
org.xerial.snappy:snappy-java:1.1.10.8=jarValidation,solrCore,testRuntimeClasspath
-empty=compileClasspath,generatedJSClientBundle,generatedUIBundle,missingdoclet,providedCompile,providedRuntime,runtimeClasspath,uiBundle,war
+empty=compileClasspath,generatedJSClientBundle,generatedUIBundle,missingdoclet,openapiSpec,providedCompile,providedRuntime,runtimeClasspath,scalarBundle,uiBundle,war
diff --git a/solr/webapp/scalar/build.gradle.kts b/solr/webapp/scalar/build.gradle.kts
new file mode 100644
index 000000000000..06da8c56daac
--- /dev/null
+++ b/solr/webapp/scalar/build.gradle.kts
@@ -0,0 +1,88 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// The Admin UI's API Explorer: a standalone page that renders the generated OpenAPI spec with
+// Scalar. It can't be an ordinary Admin UI screen because Scalar manages its own URL hash for
+// deep-linking, which conflicts with AngularJS's ngRoute (both rewrite window.location.hash) and
+// causes an infinite digest/navigation loop. The Admin UI instead loads this page in an iframe,
+// and :solr:webapp mounts this project's output at libs/scalar in the war.
+
+plugins {
+ id("base")
+}
+
+description = "The Admin UI's API Explorer, a standalone Scalar page loaded in an iframe"
+
+// Scalar's prebuilt browser bundle is published only to npm. Fetch the package archive directly
+// (from npm's registry, or the mirror the node-based builds use) rather than running npm.
+val propertyOrEnvOrDefault: groovy.lang.Closure<*> by extra
+val npmRegistry = propertyOrEnvOrDefault.call("solr.npm.registry", "SOLR_NPM_REGISTRY", "")
+ .toString()
+ .ifEmpty { "https://registry.npmjs.org" }
+
+repositories {
+ exclusiveContent {
+ forRepository {
+ ivy {
+ name = "scalarNpm"
+ url = uri(npmRegistry)
+ patternLayout {
+ artifact("[organisation]/[module]/-/[module]-[revision].[ext]")
+ }
+ metadataSources { artifact() }
+ }
+ }
+ filter { includeModule("@scalar", "api-reference") }
+ }
+}
+
+val scalarArchive = configurations.create("scalarArchive") {
+ isTransitive = false
+}
+
+dependencies {
+ scalarArchive(libs.scalar.api.reference) {
+ artifact {
+ type = "tgz"
+ extension = "tgz"
+ }
+ }
+}
+
+val scalarBundleDir = layout.buildDirectory.dir("scalarBundle")
+
+val scalarBundle = configurations.create("scalarBundle") {
+ isCanBeConsumed = true
+ isCanBeResolved = false
+}
+
+val assembleScalarBundle = tasks.register("assembleScalarBundle") {
+ from("web")
+ from(provider { tarTree(resources.gzip(scalarArchive.singleFile)) }) {
+ include("package/dist/browser/standalone.js")
+ eachFile { path = name }
+ includeEmptyDirs = false
+ }
+
+ into(scalarBundleDir)
+}
+
+artifacts {
+ add("scalarBundle", scalarBundleDir) {
+ builtBy(assembleScalarBundle)
+ }
+}
diff --git a/solr/webapp/scalar/gradle.lockfile b/solr/webapp/scalar/gradle.lockfile
new file mode 100644
index 000000000000..f0fdaed01ec6
--- /dev/null
+++ b/solr/webapp/scalar/gradle.lockfile
@@ -0,0 +1,6 @@
+# This is a Gradle generated file for dependency locking.
+# Manual edits can break the build and are not advised.
+# This file is expected to be part of source control.
+# To regenerate this file, run: ./gradlew :solr:webapp:scalar:dependencies --write-locks
+@scalar:api-reference:1.46.4=scalarArchive
+empty=jarValidation
diff --git a/solr/webapp/scalar/web/index.html b/solr/webapp/scalar/web/index.html
new file mode 100644
index 000000000000..8c27866441ca
--- /dev/null
+++ b/solr/webapp/scalar/web/index.html
@@ -0,0 +1,36 @@
+
+
+
+
+
+
+ Solr V2 API Explorer
+
+
+
+
+
+
+
+
diff --git a/solr/webapp/scalar/web/scalar-init.js b/solr/webapp/scalar/web/scalar-init.js
new file mode 100644
index 000000000000..78b45217c419
--- /dev/null
+++ b/solr/webapp/scalar/web/scalar-init.js
@@ -0,0 +1,41 @@
+/*
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+Scalar.createApiReference("#app", {
+ url: "spec.json",
+ // Keep fonts local and send API requests directly to Solr.
+ withDefaultFonts: false,
+ proxyUrl: "",
+ agent: { disabled: true },
+ hideClientButton: true,
+ showDeveloperTools: "never",
+ telemetry: false,
+ // The Admin UI has no dark mode of its own; keep the explorer visually consistent with it.
+ forceDarkModeState: "light",
+ hideDarkModeToggle: true,
+ // The explorer runs outside the Admin UI interceptors. Read the current
+ // credentials for each same-origin request and suppress the Basic Auth popup.
+ onBeforeRequest: ({ request }) => {
+ if (new URL(request.url).origin === window.location.origin) {
+ const authorization = sessionStorage.getItem("auth.header");
+ if (authorization) {
+ request.headers.set("Authorization", authorization);
+ }
+ request.headers.set("X-Requested-With", "XMLHttpRequest");
+ }
+ }
+});
diff --git a/solr/webapp/src/test/org/apache/solr/webapp/AdminUiSecurityAuthTest.java b/solr/webapp/src/test/org/apache/solr/webapp/AdminUiSecurityAuthTest.java
index 66392e8ae694..1244af49669c 100644
--- a/solr/webapp/src/test/org/apache/solr/webapp/AdminUiSecurityAuthTest.java
+++ b/solr/webapp/src/test/org/apache/solr/webapp/AdminUiSecurityAuthTest.java
@@ -26,10 +26,7 @@
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
-/**
- * Tests the Admin UI with BasicAuth enabled: the login screen flow and the Security screen,
- * including adding a user through the UI dialog.
- */
+/** Tests login, security management, and API Explorer requests with BasicAuth enabled. */
public class AdminUiSecurityAuthTest extends AdminUiTestBase {
private static final String USER = "solr";
@@ -130,6 +127,87 @@ public void testLoginAndSecurityScreen() throws Exception {
waitForPageContains(permission);
}
+ @Test
+ public void testApiExplorerUsesAdminCredentials() throws Exception {
+ ensureCloudCluster();
+ driver.get(baseUrl + "/index.html#/");
+ ((JavascriptExecutor) driver).executeScript("sessionStorage.clear();");
+ openPage("", By.id("login"));
+ setText(By.id("username"), USER);
+ setText(By.id("password"), PASS);
+ click(By.xpath("//div[@id='login']//button[@type='submit']"));
+ waitFor(By.id("nodes-table"));
+
+ try {
+ driver.get(baseUrl + "/index.html#/~api-explorer");
+ driver.switchTo().frame(waitFor(By.cssSelector("#content #api-explorer iframe")));
+ By collectionsGroup =
+ By.xpath(
+ "//button[@aria-expanded and .//div[contains(@class,'group/button-label')"
+ + " and normalize-space(.)='collections']]");
+ By listCollections =
+ By.xpath(
+ "//*[self::a or self::button][.//div[contains(@class,'group/button-label')"
+ + " and contains(., 'List all collections in this Solr cluster')]]");
+ if ("false".equals(waitFor(collectionsGroup).getDomAttribute("aria-expanded"))) {
+ activateExplorerControl(collectionsGroup);
+ }
+ activateExplorerControl(listCollections);
+ waitForPageContains("List all collections in this Solr cluster");
+ // Observe the actual request and response without replacing the Solr endpoint.
+ // Store only whether the credential matches, never the credential itself.
+ ((JavascriptExecutor) driver)
+ .executeScript(
+ "const original = window.fetch;"
+ + " window.fetch = async function(input, init) {"
+ + " const request = input instanceof Request ? input : new Request(input, init);"
+ + " const response = await original.call(this, input, init);"
+ + " if (new URL(request.url).pathname === '/api/collections'"
+ + " && request.method === 'GET') {"
+ + " let collections = false;"
+ + " try { collections = Array.isArray((await response.clone().json()).collections); }"
+ + " catch (ignored) {}"
+ + " const auth = sessionStorage.getItem('auth.header');"
+ + " window.explorerResult = {status: response.status, collections: collections,"
+ + " authenticated: !!auth && request.headers.get('Authorization') === auth,"
+ + " requestedWith: request.headers.get('X-Requested-With')};"
+ + " } return response; };");
+ activateExplorerControl(
+ By.xpath(
+ "//button[contains(@class,'show-api-client-button') and @method='get'"
+ + " and contains(., '(get /collections)')]"));
+ activateExplorerControl(
+ By.xpath(
+ "//div[contains(@class,'scalar-address-bar')]//button"
+ + "[.//span[contains(., 'Send get request')]]"));
+ waitUntil(
+ "the explorer should receive the collections response",
+ () ->
+ Boolean.TRUE.equals(
+ ((JavascriptExecutor) driver).executeScript("return !!window.explorerResult;")));
+ @SuppressWarnings("unchecked")
+ Map result =
+ (Map)
+ ((JavascriptExecutor) driver).executeScript("return window.explorerResult;");
+ assertEquals(200L, result.get("status"));
+ assertEquals(Boolean.TRUE, result.get("collections"));
+ assertEquals(Boolean.TRUE, result.get("authenticated"));
+ assertEquals("XMLHttpRequest", result.get("requestedWith"));
+ waitForTextContains(By.cssSelector("body"), "200 OK");
+ driver.switchTo().defaultContent();
+ driver.get(baseUrl + "/index.html#/~cloud?view=nodes");
+ waitFor(By.id("nodes-table"));
+ } finally {
+ driver.switchTo().defaultContent();
+ ((JavascriptExecutor) driver).executeScript("sessionStorage.clear();");
+ }
+ driver.get("about:blank");
+ }
+
+ private void activateExplorerControl(By locator) {
+ ((JavascriptExecutor) driver).executeScript("arguments[0].click();", waitFor(locator));
+ }
+
/** Returns the authorization config as fetched with credentials. */
private NamedList