aboutsummaryrefslogtreecommitdiff
path: root/internal/web/server_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'internal/web/server_test.go')
-rw-r--r--internal/web/server_test.go49
1 files changed, 49 insertions, 0 deletions
diff --git a/internal/web/server_test.go b/internal/web/server_test.go
index 57286d5..42de0b5 100644
--- a/internal/web/server_test.go
+++ b/internal/web/server_test.go
@@ -630,3 +630,52 @@ func TestCalendarPDF(t *testing.T) {
t.Errorf("not a pdf (len=%d)", len(b))
}
}
+
+// TestSourceOffer covers the AGPL-3.0 §13 obligation: a user interacting with
+// lectio-web over a network must be offered the corresponding source. That is
+// a licence term, not a feature, so it is pinned here -- if someone later
+// deletes the footer or the route, this fails rather than quietly putting the
+// operator out of compliance.
+func TestSourceOffer(t *testing.T) {
+ cfg := config.Default()
+ cfg.Offline = true // no network; the offer must not depend on readings
+ srv := NewServer(cfg)
+
+ t.Run("/source names the licence and where to get the code", func(t *testing.T) {
+ rec := httptest.NewRecorder()
+ srv.ServeHTTP(rec, httptest.NewRequest("GET", "/source", nil))
+ if rec.Code != http.StatusOK {
+ t.Fatalf("status = %d, want 200", rec.Code)
+ }
+ if ct := rec.Header().Get("Content-Type"); !strings.HasPrefix(ct, "text/plain") {
+ t.Errorf("content-type = %q, want text/plain", ct)
+ }
+ body := rec.Body.String()
+ for _, want := range []string{config.SourceURL, config.License, config.Version} {
+ if !strings.Contains(body, want) {
+ t.Errorf("body missing %q:\n%s", want, body)
+ }
+ }
+ })
+
+ // Every page a user can actually land on carries the link. Fragments
+ // (htmx partials) are excluded -- they render inside a full page that
+ // already has it.
+ for _, path := range []string{
+ "/?date=2026-07-22&v=wuj",
+ "/reader?v=wuj&book=John&chapter=1",
+ "/settings",
+ "/bookmarks",
+ } {
+ t.Run("footer on "+path, func(t *testing.T) {
+ rec := httptest.NewRecorder()
+ srv.ServeHTTP(rec, httptest.NewRequest("GET", path, nil))
+ if rec.Code != http.StatusOK {
+ t.Fatalf("status = %d, want 200", rec.Code)
+ }
+ if !strings.Contains(rec.Body.String(), `href="/source"`) {
+ t.Errorf("page has no source link (AGPL §13):\n%s", rec.Body.String())
+ }
+ })
+ }
+}