Runway 1.1.0

This commit is contained in:
Runway committed 2026-10-29 09:22:38 -06:00
1 parent ce217fc952
commit 07d5bd7e9a
223 files changed
+21147 -255

No files matched your search

+14
View File
@@ -2,6 +2,20 @@
All notable changes are recorded here. Versions follow [Semantic Versioning](https://semver.org/).
## [2.1.1] — 2026-10-29
### Security
- **The feedback form asks the site's CAPTCHA.** The public "leave a message" form (`POST /demo/feedback`) had a
honeypot, a length cap and a per-address rate limit, but never asked the challenge a site manager can turn on in
the site's protection settings, so a site with a CAPTCHA configured still took messages from scripts. The form now
shows the site's challenge, and the route keeps no message without it solved (`?demo-feedback=captcha`). A site
with no CAPTCHA configured sees no change.
### Upgrade
Replace the plugin folder with this release's zip and restart. No setting or stored file changes.
## [2.1.0] — 2026-10-21
First public release of `runway-demo`, the reference ("kitchen-sink") plugin: it exercises every extension axis and
+2 -2
View File
@@ -30,7 +30,7 @@ mvn verify
The first build downloads its Maven dependencies, and needs the `runway-spi` jars installed in `~/.m2` as the
[authoring guide §2](../docs/PLUGIN-AUTHORING-GUIDE.md#2-prerequisites) describes.
Runs 82 unit tests (over the SPI testkit's fakes, plus a scan proving the compiled classes link nothing of the host
Runs 84 unit tests (over the SPI testkit's fakes, plus a scan proving the compiled classes link nothing of the host
but the SPI) and produces the thin `target/runway-plugin-demo.jar` and **both** installable forms:
`target/runway-demo/` (the install-ready folder) and `target/runway-plugin-runway-demo-<version>.zip` (the archive
the management UI upload expects). Two builds produce byte-identical artifacts. The zip is named after the plugin id,
@@ -76,7 +76,7 @@ Copy this folder, rename the descriptor `id`, the Maven `artifactId`, the Java p
bean-name prefix (`runwayDemo…` → your id in lowerCamelCase), and delete what you do not need. Keep the tests that
check the contract (`DemoPluginConfigTest`, `DemoTemplatesTest`) — they are the cheapest way to stay inside it.
_Java package `mx.quest.demo` · plugin id `runway-demo` · version 2.1.0 · `requiresSpi: ">=1.0.0"`._
_Java package `mx.quest.demo` · plugin id `runway-demo` · version 2.1.1 · `requiresSpi: ">=1.0.0"`._
## License
+18 -11
View File
@@ -7,10 +7,10 @@
> shows them working.
- **id** `runway-demo` · **install folder** `external/plugins/runway-demo/` · **Java package** `mx.quest.demo`
- **version** `2.1.0` · **`requiresSpi`** `">=1.0.0"` · links **only** `mx.quest.runway.spi`
- **version** `2.1.1` · **`requiresSpi`** `">=1.0.0"` · links **only** `mx.quest.runway.spi`
- **jar** `runway-plugin-demo.jar` (thin: 18 top-level classes, nothing bundled) · **Maven artifactId**
`runway-plugin-runway-demo` · **release zip** `runway-plugin-runway-demo-<version>.zip`
- **Verified** live against the packaged kernel (§9) and by 82 unit tests with 20 mutation checks (§8).
- **Verified** live against the packaged kernel (§9) and by 84 unit tests with 21 mutation checks (§8).
---
@@ -20,7 +20,7 @@
|---|---|---|
| A generator `<meta>`, the plugin stylesheet and an inert analytics `<script>` in every page's `<head>` | visitors | `HeadContributor` + `PluginSettings` |
| A notice callout at `data-widget="demo-notice/<instance>"` | visitors | `ContentWidget` + `PluginSettings` + `Messages.site` |
| A "leave a message" form at `data-widget="demo-feedback/<instance>"`, posting without a CSRF token | visitors | `ContentWidget` + an **anonymous** `POST` route |
| A "leave a message" form at `data-widget="demo-feedback/<instance>"`, posting without a CSRF token, with the site's CAPTCHA when it has one | visitors | `ContentWidget` + an **anonymous** `POST` route + `CaptchaService` |
| `/demo/hello.txt`, `/demo/echo.json`, `/demo/notes.json` (permission-gated) | visitors / operators | `EndpointContributor` + `AccessCheck` + `Messages.site` |
| SEO advice in the page editor (long title, no description, no `<h1>`) | site managers | `PageQualityCheck` + `PluginSettings` |
| Per-site **notes** (operator notes, visitors' messages, a settings audit note), personal data | operators | `PluginSiteFiles` + `siteData.personal` |
@@ -125,7 +125,7 @@ are not here: they bind through `@ConfigurationProperties` under `runway.plugin.
`started(PluginInfo self)` runs once the platform is up, in plugin load order; `stopping()` at shutdown, in reverse
order, only if `started` returned normally. Both block the host's thread — keep them short. The demo logs
`runway-demo 2.1.0 started — install dir …; built against SPI 1.0.0, running on SPI 1.0.0`:
`runway-demo 2.1.1 started — install dir …; built against SPI 1.0.0, running on SPI 1.1.0`:
`RunwaySpi.VERSION` is a compile-time constant (what the plugin was **built against**, copied into the plugin's
classes), `RunwaySpi.runtimeVersion()` is the running kernel's. **Use it** to open an
index, start your own executor, warm a cache — and to close them again.
@@ -303,11 +303,18 @@ A form on a page every visitor shares (and caches) cannot carry a per-session CS
has no session. Declaring the route `anonymous` exempts **exactly that method and path** from CSRF; the kernel
makes that safe by running the handler with **no principal** (`AccessCheck.may` is `false` even for a signed-in
administrator) and accepting only an `application/x-www-form-urlencoded` body (`415` otherwise). The handler keeps
its own guards — a honeypot field, a length cap, five messages per minute per `req.clientIp()` (the address after
the kernel's trusted-proxy gate; never a header) — reads the fields from `req.form()` only (personal text never in
its own guards — a honeypot field, a length cap, the site's CAPTCHA, five messages per minute per `req.clientIp()`
(the address after the kernel's trusted-proxy gate; never a header) — reads the fields from `req.form()` only (personal text never in
a URL), and answers `303` back with only an outcome flag the widget renders. **Use it** only for a form any visitor
may submit with no account; never for an action on something a signed-in user owns.
**The site's CAPTCHA.** A public form asks the site's challenge through `CaptchaService`, a platform service every
plugin can inject. The widget appends `captcha.widgetForSite(siteId).html()` inside its form, and the route, after the
honeypot and length checks, calls `captcha.verify(siteId, <the widget's tokenField()>, req.clientIp())` when
`widgetForSite(siteId).active()`; an unsolved challenge answers `?demo-feedback=captcha` and keeps nothing. A site
with no CAPTCHA configured gets an inactive widget (no markup) and every message through, so the form works either
way; the site manager turns the challenge on in the site's protection settings, not in this plugin.
---
## 5. The axes (pure functions of their inputs)
@@ -359,11 +366,11 @@ and counted on the plugins screen.
## 8. Tests
`mvn verify` runs 82 tests over `runway-spi-testkit` (no kernel, no Spring Boot):
`mvn verify` runs 84 tests over `runway-spi-testkit` (no kernel, no Spring Boot):
| Class | Covers |
|---|---|
| `DemoSpiUnitTest` | head, both widgets, quality check, every endpoint route incl. the anonymous feedback POST (honeypot, blank, query ignored, rate limit, foreign return path), lowercase header names |
| `DemoSpiUnitTest` | head, both widgets, quality check, every endpoint route incl. the anonymous feedback POST (honeypot, blank, the site's CAPTCHA, query ignored, rate limit, foreign return path), lowercase header names |
| `DemoNotesStoreTest` | the notes over `TempDirSiteFiles`: a read shows the welcome and writes nothing, the first append keeps it, order, caps, isolation, lenient reads, an unreadable file never overwritten, a missing site, unsafe ids |
| `DemoShowcaseTest` | publish/unpublish announce through `EventDispatch`, the source's refs/body/resolve, `updatedAt`, the TTL backstop, eviction on a replayed change and on wholesale events only, the kernel's refusal from inside a callback |
| `DemoActivityTest` | own vs other plugins' settings, `local`, URLs before/after, the bound, wholesale drops, failures contained |
@@ -371,7 +378,7 @@ and counted on the plugins screen.
| `DemoTemplatesTest` | every `POST` action has a form carrying the CSRF field; no link points at an action; no repeated id; every selector matches |
| `DemoPluginConfigTest` | wiring from SPI fakes alone, bean names, forbidden Spring types, the controller's gates and mappings, template bean references, descriptor (floor, version, personal data, menu, secrets), i18n, **the compiled classes link no `mx.quest.runway` class outside `.spi`**, the removed classes are gone |
Mutation-checked: 20 deliberate breaks (the `local` gate, each eviction, each announcement, the honeypot, the rate
Mutation-checked: 21 deliberate breaks (the `local` gate, each eviction, each announcement, the honeypot, the CAPTCHA, the rate
limit boundary, the permission gates, body-only fields, a missing `@PreAuthorize`, the notes bound, the
personal-data declaration, the TTL boundary, escaping, the open-redirect guard, a form's CSRF field, an
unprefixed bean name, the clamp) — each makes a test fail.
@@ -391,12 +398,12 @@ JAVA_HOME=/path/to/jdk-25 HOST_JAR=…/runway-app-1.0.0-exec.jar VERIFY_TMPDIR=
The first build downloads its Maven dependencies, and needs the `runway-spi` jars installed in `~/.m2` as the
[authoring guide §2](../../docs/PLUGIN-AUTHORING-GUIDE.md#2-prerequisites) describes.
The verify script never runs `mvn install`. Its result for 2.1.0: **58 passed, 0 failed**.
The verify script never runs `mvn install`. Its result for 2.1.1, against Runway 1.1.0: **58 passed, 0 failed**.
From the host log:
```
plugins: 1 registered, 0 blocked
runway-demo 2.1.0 started — install dir …/plugins/runway-demo; built against SPI 1.0.0, running on SPI 1.0.0
runway-demo 2.1.1 started — install dir …/plugins/runway-demo; built against SPI 1.0.0, running on SPI 1.1.0
runway-demo settings changed for site 'default': audit note appended (now 4 notes)
transfer export: blanked 1 secret value(s) in runway-demo.yml: [analytics.site-token]
```
+1
View File
@@ -41,6 +41,7 @@ runwaydemo.feedback.send=Send
runwaydemo.feedback.thanks=Thank you — your message was kept.
runwaydemo.feedback.invalid=Please write a message first.
runwaydemo.feedback.limited=Too many messages from your address — please try again in a minute.
runwaydemo.feedback.captcha=Please complete the challenge and try again.
runwaydemo.showcase.title=Showcase
runwaydemo.page.title=Runway demo
+1
View File
@@ -33,6 +33,7 @@ runwaydemo.feedback.send=Enviar
runwaydemo.feedback.thanks=Gracias — guardamos tu mensaje.
runwaydemo.feedback.invalid=Escribe un mensaje primero.
runwaydemo.feedback.limited=Demasiados mensajes desde tu dirección — inténtalo de nuevo en un minuto.
runwaydemo.feedback.captcha=Completa el desafío e inténtalo de nuevo.
runwaydemo.showcase.title=Escaparate
runwaydemo.page.title=Demo de Runway
+1 -1
View File
@@ -7,7 +7,7 @@
# =============================================================================
id: runway-demo
name: Runway Demo (Kitchen-Sink Plugin)
version: 2.1.0
version: 2.1.1
# The lowest SPI level this plugin needs; a kernel below it BLOCKS the plugin at startup with a reason. Declare the
# floor of the NEWEST type you use: without it, an older kernel would load the plugin and fail at the first request
+4 -2
View File
@@ -21,7 +21,7 @@
<!-- runway-plugin-<plugin id>, as for every plugin in this repository: the release zip is named after it
(runway-plugin-runway-demo-<version>.zip under the tag runway-demo-<version>). -->
<artifactId>runway-plugin-runway-demo</artifactId>
<version>2.1.0</version>
<version>2.1.1</version>
<packaging>jar</packaging>
<name>Runway Demo Plugin</name>
<licenses>
@@ -47,7 +47,7 @@
<!-- Reproducible builds: pins every archive entry's timestamp so two builds of the same source
produce byte-identical artifacts. Without it a jar embeds the build time, so a rebuild can
never match what was published. Bump at each release. -->
<project.build.outputTimestamp>2026-10-21T17:23:00Z</project.build.outputTimestamp>
<project.build.outputTimestamp>2026-10-29T00:00:00Z</project.build.outputTimestamp>
<!-- The Runway SPI this plugin compiles against: a RELEASED kernel (its SPI jars installed
from that release's assets). The plugin's runtime floor is plugin.yml's
requiresSpi, not this number. -->
@@ -169,6 +169,8 @@
<dirset dir="${stage}"/>
<dirset dir="${project.build.directory}" includes="runway-demo"/>
</touch>
<!-- The stamped files predate any earlier zip, so <zip> would skip the rebuild. -->
<delete file="${project.build.directory}/${project.artifactId}-${project.version}.zip"/>
<zip destfile="${project.build.directory}/${project.artifactId}-${project.version}.zip">
<zipfileset dir="${project.build.directory}" includes="runway-demo/**"/>
</zip>
@@ -11,8 +11,10 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.TimeUnit;
import java.util.function.LongSupplier;
import mx.quest.runway.spi.CaptchaService;
import mx.quest.runway.spi.EndpointContributor;
import mx.quest.runway.spi.model.Capabilities;
import mx.quest.runway.spi.model.CaptchaWidget;
import mx.quest.runway.spi.model.Realm;
import mx.quest.runway.spi.model.Route;
import mx.quest.runway.spi.model.RouteRequest;
@@ -46,8 +48,9 @@ import tools.jackson.databind.json.JsonMapper;
* exempts exactly this method and path from CSRF and makes that safe by running the handler with <b>no
* principal</b> ({@code AccessCheck.may} is {@code false} even for a signed-in administrator) and accepting only
* an {@code application/x-www-form-urlencoded} body. Keep your own abuse guards: here a honeypot field, a length
* cap and a per-address rate limit keyed by {@link RouteRequest#clientIp()} (the address after the kernel's
* trusted-proxy gate — never a header). Never use the flag for an action on something a signed-in user owns;
* cap, the site's CAPTCHA through {@link CaptchaService} when the site has configured one, and a per-address
* rate limit keyed by {@link RouteRequest#clientIp()} (the address after the kernel's trusted-proxy gate —
* never a header). Never use the flag for an action on something a signed-in user owns;
* those are CSRF-checked {@code POST}s (the demo's console screen, {@link DemoConsoleController}).</li>
* </ul>
*/
@@ -68,20 +71,23 @@ public class DemoEndpoints implements EndpointContributor {
private final DemoNotesStore notes;
private final Messages messages;
private final PluginSettings settings;
private final CaptchaService captcha;
private final LongSupplier clockMillis;
private final JsonMapper json = JsonMapper.builder().build();
private final ConcurrentMap<String, Deque<Long>> recentFeedback = new ConcurrentHashMap<>();
public DemoEndpoints(AccessCheck access, DemoNotesStore notes, Messages messages, PluginSettings settings) {
this(access, notes, messages, settings, System::currentTimeMillis);
public DemoEndpoints(AccessCheck access, DemoNotesStore notes, Messages messages, PluginSettings settings,
CaptchaService captcha) {
this(access, notes, messages, settings, captcha, System::currentTimeMillis);
}
DemoEndpoints(AccessCheck access, DemoNotesStore notes, Messages messages, PluginSettings settings,
LongSupplier clockMillis) {
CaptchaService captcha, LongSupplier clockMillis) {
this.access = access;
this.notes = notes;
this.messages = messages;
this.settings = settings;
this.captcha = captcha;
this.clockMillis = clockMillis;
}
@@ -166,6 +172,12 @@ public class DemoEndpoints implements EndpointContributor {
if (message.isEmpty()) {
return redirect(back, "invalid");
}
// The site's challenge, when it has one (the kernel's default answers "inactive"); verified with the gated
// client address, as the provider expects the visitor's.
CaptchaWidget challenge = captcha.widgetForSite(siteId);
if (challenge.active() && !captcha.verify(siteId, formField(req, challenge.tokenField()), req.clientIp())) {
return redirect(back, "captcha");
}
if (!allow(req.clientIp())) {
return redirect(back, "limited");
}
@@ -1,6 +1,7 @@
package mx.quest.demo;
import java.util.Locale;
import mx.quest.runway.spi.CaptchaService;
import mx.quest.runway.spi.ContentWidget;
import mx.quest.runway.spi.model.Capabilities;
import mx.quest.runway.spi.model.RenderFragment;
@@ -18,7 +19,8 @@ import mx.quest.runway.spi.service.PluginSettings;
* <p>The form carries <b>no CSRF token</b> on purpose: it sits on a page every visitor shares (and caches), and an
* anonymous visitor has no session. That is exactly the case the anonymous-route flag exists for — see
* {@link DemoEndpoints}. Its abuse guards are a honeypot field (hidden from people, filled by naive bots), a length
* cap and a per-address rate limit on the server.
* cap, the site's CAPTCHA challenge ({@link CaptchaService}: rendered here, verified by the route; nothing when the
* site has none) and a per-address rate limit on the server.
*
* <p>A widget stays a pure function of its view: it only <i>reads</i> the query; storing the message is the
* endpoint's job. All text comes from {@link Messages#site} in the visitor's locale and is escaped here.
@@ -30,10 +32,12 @@ public class DemoFeedbackWidget implements ContentWidget {
private final PluginSettings settings;
private final Messages messages;
private final CaptchaService captcha;
public DemoFeedbackWidget(PluginSettings settings, Messages messages) {
public DemoFeedbackWidget(PluginSettings settings, Messages messages, CaptchaService captcha) {
this.settings = settings;
this.messages = messages;
this.captcha = captcha;
}
@Override
@@ -68,6 +72,8 @@ public class DemoFeedbackWidget implements ContentWidget {
// The honeypot: off-screen for people and assistive technology, tempting for a form-filling bot.
.append("<div class=\"rw-demo-hp\" aria-hidden=\"true\"><label>Website <input type=\"text\" ")
.append("name=\"website\" tabindex=\"-1\" autocomplete=\"off\"></label></div>")
// The site's CAPTCHA challenge when it has one: trusted markup from the platform, empty otherwise.
.append(captcha.widgetForSite(siteId).html())
.append("<button type=\"submit\">")
.append(Html.escape(text(siteId, locale, "runwaydemo.feedback.send", "Send")))
.append("</button></form></div>");
@@ -83,6 +89,8 @@ public class DemoFeedbackWidget implements ContentWidget {
case "invalid" -> text(siteId, locale, "runwaydemo.feedback.invalid", "Please write a message first.");
case "limited" -> text(siteId, locale, "runwaydemo.feedback.limited",
"Too many messages from your address — please try again in a minute.");
case "captcha" -> text(siteId, locale, "runwaydemo.feedback.captcha",
"Please complete the challenge and try again.");
default -> "";
};
}
@@ -1,5 +1,6 @@
package mx.quest.demo;
import mx.quest.runway.spi.CaptchaService;
import mx.quest.runway.spi.model.PluginInfo;
import mx.quest.runway.spi.service.AccessCheck;
import mx.quest.runway.spi.service.ContentCatalogView;
@@ -99,8 +100,9 @@ public class DemoPluginConfig {
}
@Bean
public DemoFeedbackWidget runwayDemoFeedbackWidget(PluginSettings settings, Messages messages) {
return new DemoFeedbackWidget(settings, messages);
public DemoFeedbackWidget runwayDemoFeedbackWidget(PluginSettings settings, Messages messages,
CaptchaService captcha) {
return new DemoFeedbackWidget(settings, messages, captcha);
}
@Bean
@@ -110,8 +112,8 @@ public class DemoPluginConfig {
@Bean
public DemoEndpoints runwayDemoEndpoints(AccessCheck access, DemoNotesStore notes, Messages messages,
PluginSettings settings) {
return new DemoEndpoints(access, notes, messages, settings);
PluginSettings settings, CaptchaService captcha) {
return new DemoEndpoints(access, notes, messages, settings, captcha);
}
/** A content source AND a SOURCE-phase listener (it drops its own cache before consumers re-read). */
@@ -28,6 +28,7 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import mx.quest.runway.spi.CaptchaService;
import mx.quest.runway.spi.ContentSource;
import mx.quest.runway.spi.ContentWidget;
import mx.quest.runway.spi.EndpointContributor;
@@ -95,6 +96,7 @@ class DemoPluginConfigTest {
ctx.registerBean(ContentChanges.class, () -> new EventDispatch("runway-demo", Set.of("runway-demo")));
ctx.registerBean(PluginInfo.class, () -> new PluginInfo("runway-demo", "2.0.1", sites));
ctx.registerBean(FakeSiteServices.class, () -> kernel);
ctx.registerBean(CaptchaService.class, () -> DemoSpiUnitTest.captcha(false, ""));
ctx.registerBean(FakeContentCatalog.class, () -> new FakeContentCatalog().site("acme"));
ctx.register(DemoPluginConfig.class);
ctx.refresh();
@@ -236,10 +238,10 @@ class DemoPluginConfigTest {
Matcher version = Pattern.compile("<artifactId>runway-plugin-runway-demo</artifactId>\\s*<version>([^<]+)")
.matcher(pom);
assertTrue(version.find());
assertEquals("2.1.0", version.group(1));
assertEquals("2.1.1", version.group(1));
assertEquals(version.group(1), String.valueOf(yml.get("version")), "plugin.yml and pom.xml agree");
assertFalse(pom.contains("<artifactId>runway-app</artifactId>"), "no runway-app dependency in any scope");
assertTrue(pom.contains("<project.build.outputTimestamp>2026-10-21T17:23:00Z</project.build.outputTimestamp>"));
assertTrue(pom.contains("<project.build.outputTimestamp>2026-10-29T00:00:00Z</project.build.outputTimestamp>"));
@SuppressWarnings("unchecked")
List<Map<String, Object>> menu = (List<Map<String, Object>>) yml.get("menu");
assertEquals(DemoConsoleController.BASE, menu.get(0).get("path"), "the menu opens the console screen");
@@ -12,6 +12,8 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;
import mx.quest.runway.spi.CaptchaService;
import mx.quest.runway.spi.model.CaptchaWidget;
import mx.quest.runway.spi.model.Finding;
import mx.quest.runway.spi.model.HeadContext;
import mx.quest.runway.spi.model.PageMeta;
@@ -56,6 +58,22 @@ class DemoSpiUnitTest {
return new FakePluginSettings().site("acme", stored);
}
/** A site's CAPTCHA: inactive (the kernel's default), or active and accepting one token only. */
static CaptchaService captcha(boolean active, String accepted) {
return new CaptchaService() {
@Override
public CaptchaWidget widgetForSite(String siteId) {
return active ? new CaptchaWidget(true, "g-recaptcha-response", "<div class=\"challenge\"></div>")
: CaptchaWidget.inactive();
}
@Override
public boolean verify(String siteId, String token, String clientIp) {
return !active || accepted.equals(token);
}
};
}
// --- HeadContributor -------------------------------------------------------------------------------
@Test
@@ -151,7 +169,7 @@ class DemoSpiUnitTest {
@Test
void feedbackFormPostsToTheAnonymousRouteWithReturnPathHoneypotAndNoCsrfField() {
String html = new DemoFeedbackWidget(settings(Map.of()), kernel).render(feedbackView(Map.of(), "/demo"))
String html = new DemoFeedbackWidget(settings(Map.of()), kernel, captcha(false, "")).render(feedbackView(Map.of(), "/demo"))
.html();
assertTrue(html.contains("<form method=\"post\" action=\"/demo/feedback\">"), html);
assertTrue(html.contains("name=\"return\" value=\"/demo\""), html);
@@ -159,11 +177,22 @@ class DemoSpiUnitTest {
assertTrue(html.contains("name=\"website\"") && html.contains("rw-demo-hp"), "honeypot present");
assertFalse(html.contains("_csrf"), "a shared, cacheable page carries no per-session token");
assertFalse(html.contains("role=\"status\""), "no outcome without the flag");
assertFalse(html.contains("challenge"), "no CAPTCHA markup when the site has none");
}
@Test
void feedbackFormCarriesTheSitesChallengeWhenItHasOne() {
DemoFeedbackWidget widget = new DemoFeedbackWidget(settings(Map.of()), kernel, captcha(true, "solved"));
String html = widget.render(feedbackView(Map.of(), "/demo")).html();
assertTrue(html.indexOf("<div class=\"challenge\"></div>") > html.indexOf("<form")
&& html.indexOf("<div class=\"challenge\"></div>") < html.indexOf("</form>"), html);
assertTrue(widget.render(feedbackView(Map.of("demo-feedback", "captcha"), "/demo")).html()
.contains("Please complete the challenge and try again."));
}
@Test
void feedbackShowsTheOutcomeFlagAndEscapesTheReturnPath() {
DemoFeedbackWidget widget = new DemoFeedbackWidget(settings(Map.of()), kernel);
DemoFeedbackWidget widget = new DemoFeedbackWidget(settings(Map.of()), kernel, captcha(false, ""));
assertTrue(widget.render(feedbackView(Map.of("demo-feedback", "thanks"), "/x")).html()
.contains("Thank you"));
assertTrue(widget.render(feedbackView(Map.of("demo-feedback", "invalid"), "/x")).html()
@@ -180,7 +209,8 @@ class DemoSpiUnitTest {
@Test
void feedbackIsEmptyWhenTheSiteTurnedItOff() {
assertTrue(new DemoFeedbackWidget(settings(Map.of("feedback.enabled", false)), kernel)
assertTrue(new DemoFeedbackWidget(settings(Map.of("feedback.enabled", false)), kernel,
captcha(true, "solved"))
.render(feedbackView(Map.of(), "/demo")).isEmpty());
}
@@ -217,7 +247,11 @@ class DemoSpiUnitTest {
// --- EndpointContributor ---------------------------------------------------------------------------
private DemoEndpoints endpoints(FakePluginSettings settings, AtomicLong clock) {
return new DemoEndpoints(kernel, notes, kernel, settings, clock::get);
return endpoints(settings, clock, captcha(false, ""));
}
private DemoEndpoints endpoints(FakePluginSettings settings, AtomicLong clock, CaptchaService captcha) {
return new DemoEndpoints(kernel, notes, kernel, settings, captcha, clock::get);
}
private static RouteRequest get(String path) {
@@ -309,6 +343,20 @@ class DemoSpiUnitTest {
assertEquals(before, notes.count("acme"), "neither was stored");
}
@Test
void aSiteWithACaptchaKeepsNoMessageWithoutTheSolvedChallenge() {
DemoEndpoints ep = endpoints(settings(Map.of()), new AtomicLong(), captcha(true, "solved"));
int before = notes.count("acme");
assertEquals("/demo?demo-feedback=captcha", ep.handle(post("/demo/feedback", Map.of("message",
List.of("hi"), "return", List.of("/demo")), "198.51.100.4")).headers().get("Location"));
assertEquals("/?demo-feedback=captcha", ep.handle(post("/demo/feedback", Map.of("message", List.of("hi"),
"g-recaptcha-response", List.of("wrong")), "198.51.100.4")).headers().get("Location"));
assertEquals(before, notes.count("acme"), "an unsolved challenge keeps nothing");
assertEquals("/?demo-feedback=thanks", ep.handle(post("/demo/feedback", Map.of("message", List.of("hi"),
"g-recaptcha-response", List.of("solved")), "198.51.100.4")).headers().get("Location"));
assertEquals(before + 1, notes.count("acme"));
}
@Test
void feedbackReadsTheBodyOnlyNeverTheQueryString() {
DemoEndpoints ep = endpoints(settings(Map.of()), new AtomicLong());