javascript-solid-server 0.0.187 → 0.0.188
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/ui/server-root.html +90 -29
- package/src/ui/server-root.js +35 -86
- package/test/server-root.test.js +147 -90
package/package.json
CHANGED
package/src/ui/server-root.html
CHANGED
|
@@ -3,68 +3,129 @@
|
|
|
3
3
|
<head>
|
|
4
4
|
<meta charset="UTF-8">
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
-
<title>
|
|
7
|
-
<meta name="description" content="A
|
|
6
|
+
<title>JSS Solid pod</title>
|
|
7
|
+
<meta name="description" content="A Solid pod server powered by JSS">
|
|
8
8
|
<style>
|
|
9
9
|
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
10
10
|
body {
|
|
11
|
-
font-family:
|
|
11
|
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
|
|
12
12
|
background: #fafaf8;
|
|
13
13
|
color: #2c2c2c;
|
|
14
|
-
line-height: 1.
|
|
14
|
+
line-height: 1.6;
|
|
15
15
|
min-height: 100vh;
|
|
16
16
|
display: flex;
|
|
17
17
|
align-items: center;
|
|
18
18
|
justify-content: center;
|
|
19
19
|
padding: 2rem;
|
|
20
20
|
}
|
|
21
|
-
.container { max-width:
|
|
22
|
-
h1 { font-size: 2.2rem; font-weight:
|
|
23
|
-
.
|
|
24
|
-
|
|
25
|
-
.
|
|
21
|
+
.container { max-width: 600px; width: 100%; }
|
|
22
|
+
h1 { font-size: 2.2rem; font-weight: 500; margin-bottom: 1rem; }
|
|
23
|
+
.lede { font-size: 1.05rem; margin-bottom: 1rem; color: #2c2c2c; }
|
|
24
|
+
.lede a { color: #2c2c2c; text-decoration: none; border-bottom: 1px dashed #aaa; }
|
|
25
|
+
.lede a:hover { border-bottom-color: #2c2c2c; }
|
|
26
|
+
.explainer { color: #666; font-size: 0.95rem; margin-bottom: 2rem; padding-bottom: 1.5rem; border-bottom: 1px solid #ddd; }
|
|
27
|
+
.actions { display: flex; gap: 0.75rem; margin: 0 0 2rem; flex-wrap: wrap; }
|
|
26
28
|
.btn {
|
|
27
29
|
display: inline-block;
|
|
28
30
|
padding: 0.6rem 1.2rem;
|
|
29
31
|
border-radius: 4px;
|
|
30
32
|
text-decoration: none;
|
|
31
|
-
font-family: Georgia, serif;
|
|
32
33
|
font-size: 0.95rem;
|
|
33
34
|
border: 1px solid transparent;
|
|
34
35
|
cursor: pointer;
|
|
35
|
-
transition:
|
|
36
|
+
transition: background 0.1s, border-color 0.1s;
|
|
36
37
|
}
|
|
37
|
-
.btn
|
|
38
|
-
|
|
38
|
+
/* The .btn { display: inline-block } above otherwise overrides the
|
|
39
|
+
browser's UA `[hidden] { display: none }` rule (equal specificity,
|
|
40
|
+
author rule wins because it's later in the cascade). Without this,
|
|
41
|
+
the Sign up / Sign in buttons would flash visible before the HEAD
|
|
42
|
+
probe runs. !important keeps the [hidden] attribute authoritative. */
|
|
43
|
+
[hidden] { display: none !important; }
|
|
44
|
+
.btn-primary { background: #2c2c2c; color: #fff; }
|
|
45
|
+
.btn-primary:hover { background: #000; }
|
|
39
46
|
.btn-secondary { background: #fff; color: #2c2c2c; border-color: #ccc; }
|
|
40
47
|
.btn-secondary:hover { background: #f0efeb; }
|
|
41
|
-
.info { background: #f5f4f0; border-radius: 4px; padding: 1rem; font-size: 0.85rem; color: #666; margin-top: 1.5rem; }
|
|
42
|
-
.info .row { display: flex; justify-content: space-between; padding: 0.2rem 0; }
|
|
43
|
-
.info .label { color: #999; }
|
|
44
|
-
.info code { font-family: 'SFMono-Regular', Consolas, monospace; font-size: 0.9em; color: #555; }
|
|
45
48
|
footer { margin-top: 2rem; padding-top: 1rem; border-top: 1px solid #ddd; color: #999; font-size: 0.8rem; text-align: center; }
|
|
46
49
|
footer a { color: #888; }
|
|
47
|
-
|
|
48
|
-
|
|
50
|
+
footer small { display: block; margin-top: 0.5rem; }
|
|
51
|
+
footer code { font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace; }
|
|
49
52
|
</style>
|
|
50
53
|
</head>
|
|
51
54
|
<body>
|
|
52
55
|
<div class="container">
|
|
53
|
-
<h1>
|
|
54
|
-
|
|
55
|
-
|
|
56
|
+
<h1>Welcome</h1>
|
|
57
|
+
<!-- The fallback href="./" is page-relative so it stays inside any
|
|
58
|
+
reverse-proxy mount even if the script below doesn't run
|
|
59
|
+
(CSP, JS disabled). The script will replace it with the
|
|
60
|
+
absolute URL of the document base on load. -->
|
|
61
|
+
<p class="lede">Your JSS Solid pod is running at <a id="server-url" href="./">this server</a>.</p>
|
|
62
|
+
<p class="explainer">This is a Solid pod server. Solid is an open standard for personal data — your data lives in pods you own, and apps connect to it.</p>
|
|
56
63
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
64
|
+
<div class="actions">
|
|
65
|
+
<a href="https://jss.live/docs/getting-started/introduction" class="btn btn-primary">Get started →</a>
|
|
66
|
+
<!-- IdP links are written page-relative (no leading slash) so they
|
|
67
|
+
resolve against document base, surviving reverse-proxy mounts
|
|
68
|
+
at a path prefix (e.g. https://example/jss/). Origin-root
|
|
69
|
+
absolute paths like /idp would jump out of the mount point.
|
|
70
|
+
Same rationale as the relative ACL targets from #428. -->
|
|
71
|
+
<a href="./idp/register" class="btn btn-secondary" data-cond="register" hidden>Sign up</a>
|
|
72
|
+
<a href="./idp" class="btn btn-secondary" data-cond="login" hidden>Sign in</a>
|
|
63
73
|
</div>
|
|
64
74
|
|
|
75
|
+
<!-- Version, mode, and enabled-feature pills used to live here.
|
|
76
|
+
All three would go stale on the next mode change or upgrade
|
|
77
|
+
because the seed is skip-if-exists. The CLI banner already
|
|
78
|
+
lists them at startup. Surface them via a runtime probe in
|
|
79
|
+
a follow-up if needed. See #435. -->
|
|
80
|
+
|
|
81
|
+
|
|
65
82
|
<footer>
|
|
66
|
-
Powered by <a href="https://jss.live">JSS</a>
|
|
83
|
+
Powered by <a href="https://jss.live">JSS</a> · <a href="https://github.com/JavaScriptSolidServer/JavaScriptSolidServer">GitHub</a>
|
|
84
|
+
<small>Customise this page: edit <code>/index.html</code> in your data dir</small>
|
|
67
85
|
</footer>
|
|
68
86
|
</div>
|
|
87
|
+
|
|
88
|
+
<script>
|
|
89
|
+
// Render the live server URL the visitor actually used. Adapts to
|
|
90
|
+
// whichever hostname/port they hit (localhost / 127.0.0.1 / LAN-IP
|
|
91
|
+
// / public domain) and — importantly — preserves any reverse-proxy
|
|
92
|
+
// path prefix the server is mounted under. `window.location.origin`
|
|
93
|
+
// alone would drop a /jss/ mount and display the proxy origin
|
|
94
|
+
// instead. `new URL('./', window.location.href)` resolves to the
|
|
95
|
+
// current document's directory, which is the JSS server root.
|
|
96
|
+
(function () {
|
|
97
|
+
var el = document.getElementById('server-url');
|
|
98
|
+
if (!el) return;
|
|
99
|
+
var base = new URL('./', window.location.href).href;
|
|
100
|
+
el.textContent = base;
|
|
101
|
+
el.href = base;
|
|
102
|
+
})();
|
|
103
|
+
|
|
104
|
+
// HEAD-adaptive Sign up / Sign in. Reveals each button based on what
|
|
105
|
+
// the IDP currently exposes — the same seeded HTML works for
|
|
106
|
+
// single-user, multi-user-with-IDP, and no-IDP modes without
|
|
107
|
+
// regeneration on mode change.
|
|
108
|
+
// 200 → registration open: show both Sign up and Sign in
|
|
109
|
+
// 403 → IDP enabled but registration disabled (single-user mode):
|
|
110
|
+
// Sign in only
|
|
111
|
+
// 404 / network error → no IDP: hide both
|
|
112
|
+
(function () {
|
|
113
|
+
// Relative URL resolves against document base, same as the
|
|
114
|
+
// anchor hrefs above — preserves the path-prefix mount point.
|
|
115
|
+
fetch('./idp/register', { method: 'HEAD', cache: 'no-store' })
|
|
116
|
+
.then(function (res) {
|
|
117
|
+
var register = document.querySelector('[data-cond="register"]');
|
|
118
|
+
var login = document.querySelector('[data-cond="login"]');
|
|
119
|
+
if (res.status === 200) {
|
|
120
|
+
if (register) register.hidden = false;
|
|
121
|
+
if (login) login.hidden = false;
|
|
122
|
+
} else if (res.status === 403) {
|
|
123
|
+
if (login) login.hidden = false;
|
|
124
|
+
}
|
|
125
|
+
// 404 / other / network error: leave both hidden
|
|
126
|
+
})
|
|
127
|
+
.catch(function () { /* network error: leave both hidden */ });
|
|
128
|
+
})();
|
|
129
|
+
</script>
|
|
69
130
|
</body>
|
|
70
131
|
</html>
|
package/src/ui/server-root.js
CHANGED
|
@@ -18,100 +18,49 @@ const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
|
18
18
|
const TEMPLATE_PATH = join(__dirname, 'server-root.html');
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
|
-
*
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return f;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Build an HTML snippet of action buttons based on server mode.
|
|
21
|
+
* Read the landing page template and return it as an HTML string.
|
|
22
|
+
*
|
|
23
|
+
* The seeded HTML is fully static — no template substitution. Anything
|
|
24
|
+
* we used to render in (mode, enabled features, version) would have
|
|
25
|
+
* gone stale on the next mode change or upgrade because the seed is
|
|
26
|
+
* skip-if-exists. They've been dropped from the template; the CLI
|
|
27
|
+
* banner lists them at startup, and Sign up / Sign in adapt at load
|
|
28
|
+
* time via the inline HEAD probe (see decideRevealForRegisterStatus
|
|
29
|
+
* below for the matrix that the inline script implements).
|
|
30
|
+
*
|
|
31
|
+
* The function still takes (and ignores) a `_ctx` arg for forward
|
|
32
|
+
* compatibility — callers (seedServerRoot, server.js) pass one.
|
|
33
|
+
*
|
|
34
|
+
* @param {object} [_ctx] - Reserved; currently unused.
|
|
35
|
+
* @returns {string} HTML
|
|
41
36
|
*/
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
buttons.push('<a href="/idp/register" class="btn btn-primary">Create a pod</a>');
|
|
46
|
-
buttons.push('<a href="/idp" class="btn btn-secondary">Sign in</a>');
|
|
47
|
-
} else if (singleUser && idp) {
|
|
48
|
-
buttons.push('<a href="/idp" class="btn btn-primary">Sign in</a>');
|
|
49
|
-
}
|
|
50
|
-
buttons.push('<a href="https://javascriptsolidserver.github.io/docs/" class="btn btn-secondary">Docs</a>');
|
|
51
|
-
return `<div class="actions">${buttons.join('\n ')}</div>`;
|
|
37
|
+
// eslint-disable-next-line no-unused-vars
|
|
38
|
+
export function renderServerRoot(_ctx = {}) {
|
|
39
|
+
return readFileSync(TEMPLATE_PATH, 'utf8');
|
|
52
40
|
}
|
|
53
41
|
|
|
54
42
|
/**
|
|
55
|
-
*
|
|
43
|
+
* Decide which conditional buttons (Sign up, Sign in) to reveal based
|
|
44
|
+
* on the response status of `HEAD /idp/register`. Pure function so the
|
|
45
|
+
* 200 / 403 / 404 matrix can be unit-tested without DOM. The inline
|
|
46
|
+
* script in server-root.html implements the same matrix literally;
|
|
47
|
+
* keep them in sync.
|
|
56
48
|
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
* @param {
|
|
63
|
-
*
|
|
49
|
+
* 200 → registration open: reveal both Sign up and Sign in
|
|
50
|
+
* 403 → IDP enabled but registration disabled (single-user mode):
|
|
51
|
+
* reveal Sign in only
|
|
52
|
+
* anything else (404, network error) → reveal neither (no IDP)
|
|
53
|
+
*
|
|
54
|
+
* @param {number|undefined} status - HTTP status code, or undefined for
|
|
55
|
+
* network error.
|
|
56
|
+
* @returns {{ register: boolean, login: boolean }}
|
|
64
57
|
*/
|
|
65
|
-
export function
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const mode = singleUser ? 'single-user' : 'multi-user';
|
|
70
|
-
const features = listFeatures(enabled)
|
|
71
|
-
.map(f => `<span>${f}</span>`)
|
|
72
|
-
.join(' ');
|
|
73
|
-
|
|
74
|
-
const heading = 'JSS';
|
|
75
|
-
const subtitle = singleUser
|
|
76
|
-
? `Personal pod${singleUserName && singleUserName !== '/' ? ` for ${escape(singleUserName)}` : ''}`
|
|
77
|
-
: 'A personal data server';
|
|
78
|
-
const description = singleUser
|
|
79
|
-
? 'This server hosts a personal data pod. Apps come to the data rather than the other way around.'
|
|
80
|
-
: 'This server hosts personal data pods on the web. Each pod is a space you own, with your own identity and access control.';
|
|
81
|
-
|
|
82
|
-
// Single-pass token substitution. Sequential .replace() calls would
|
|
83
|
-
// re-scan already-substituted values, so a `singleUserName` of e.g.
|
|
84
|
-
// `{{actions}}` would land inside `subtitle`, then get expanded by
|
|
85
|
-
// the later `.replace(/{{actions}}/g, …)` — letting a pod owner
|
|
86
|
-
// inject other template fragments via their name. With a single
|
|
87
|
-
// pass over the original template, each {{token}} is matched once
|
|
88
|
-
// and replaced with its value; `$` inside any value is also harmless
|
|
89
|
-
// because the function form of replace skips substitution patterns.
|
|
90
|
-
// See #433 review thread.
|
|
91
|
-
const values = {
|
|
92
|
-
title: heading,
|
|
93
|
-
heading,
|
|
94
|
-
subtitle,
|
|
95
|
-
description,
|
|
96
|
-
actions: renderActions({ singleUser, idp }),
|
|
97
|
-
version: escape(version),
|
|
98
|
-
mode,
|
|
99
|
-
features
|
|
100
|
-
};
|
|
101
|
-
return tpl.replace(/{{(\w+)}}/g, (match, key) =>
|
|
102
|
-
Object.prototype.hasOwnProperty.call(values, key) ? values[key] : match
|
|
103
|
-
);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function escape(s = '') {
|
|
107
|
-
return String(s)
|
|
108
|
-
.replace(/&/g, '&')
|
|
109
|
-
.replace(/</g, '<')
|
|
110
|
-
.replace(/>/g, '>')
|
|
111
|
-
.replace(/"/g, '"');
|
|
58
|
+
export function decideRevealForRegisterStatus(status) {
|
|
59
|
+
if (status === 200) return { register: true, login: true };
|
|
60
|
+
if (status === 403) return { register: false, login: true };
|
|
61
|
+
return { register: false, login: false };
|
|
112
62
|
}
|
|
113
63
|
|
|
114
|
-
|
|
115
64
|
/**
|
|
116
65
|
* Seed DATA_ROOT/index.html, DATA_ROOT/.acl and DATA_ROOT/index.html.acl
|
|
117
66
|
* if they don't already exist. Operator's own files are never overwritten.
|
package/test/server-root.test.js
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Server-root landing page seed (#276).
|
|
2
|
+
* Server-root landing page seed (#276 / #433 / #435).
|
|
3
|
+
*
|
|
4
|
+
* Phase 3 (#433) seeded a mode-specific landing page that went stale on
|
|
5
|
+
* mode change. Phase 3 refinement (#435) replaced the mode-specific copy
|
|
6
|
+
* with a single mode-agnostic page that adapts at load time via a HEAD
|
|
7
|
+
* probe against /idp/register, so the same seeded HTML keeps working
|
|
8
|
+
* across modes without regenerating the file.
|
|
3
9
|
*/
|
|
4
10
|
|
|
5
11
|
import { describe, it, before, after } from 'node:test';
|
|
6
12
|
import assert from 'node:assert';
|
|
7
13
|
import fs from 'fs-extra';
|
|
8
14
|
import { createServer } from '../src/server.js';
|
|
9
|
-
import { renderServerRoot } from '../src/ui/server-root.js';
|
|
15
|
+
import { renderServerRoot, decideRevealForRegisterStatus } from '../src/ui/server-root.js';
|
|
10
16
|
import { startTestServer, stopTestServer, request, assertStatus } from './helpers.js';
|
|
11
17
|
|
|
12
18
|
describe('Server-root landing page', () => {
|
|
@@ -22,8 +28,8 @@ describe('Server-root landing page', () => {
|
|
|
22
28
|
const res = await request('/', { headers: { Accept: 'text/html' } });
|
|
23
29
|
assertStatus(res, 200);
|
|
24
30
|
const body = await res.text();
|
|
25
|
-
assert.match(body, /<title>JSS<\/title>/);
|
|
26
|
-
assert.match(body, /
|
|
31
|
+
assert.match(body, /<title>JSS Solid pod<\/title>/);
|
|
32
|
+
assert.match(body, /Your JSS Solid pod is running/);
|
|
27
33
|
});
|
|
28
34
|
|
|
29
35
|
it('landing page is publicly readable (no auth required)', async () => {
|
|
@@ -97,96 +103,147 @@ describe('Server-root landing — operator override', () => {
|
|
|
97
103
|
});
|
|
98
104
|
});
|
|
99
105
|
|
|
100
|
-
describe('renderServerRoot
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
+
describe('renderServerRoot', () => {
|
|
107
|
+
// The seeded HTML is fully static — no template substitution, no
|
|
108
|
+
// values vary by request. This is deliberate: anything dynamic
|
|
109
|
+
// (mode, features, version) goes stale on the next mode change or
|
|
110
|
+
// upgrade because the seed is skip-if-exists. Static = honest.
|
|
111
|
+
it('renders byte-identical HTML regardless of the ctx passed', () => {
|
|
112
|
+
const a = renderServerRoot({ version: '1.0.0', singleUser: true, enabled: { idp: true } });
|
|
113
|
+
const b = renderServerRoot({ version: '99.0.0', singleUser: false, enabled: {} });
|
|
114
|
+
const c = renderServerRoot();
|
|
115
|
+
assert.strictEqual(a, b);
|
|
116
|
+
assert.strictEqual(b, c);
|
|
117
|
+
assert.match(a, /<h1>Welcome<\/h1>/);
|
|
118
|
+
assert.match(a, /Your JSS Solid pod is running/);
|
|
119
|
+
assert.match(a, /open standard for personal data/);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('does not bake mode, feature, or version pills into the seeded HTML', () => {
|
|
123
|
+
// All three would go stale across mode changes / upgrades because
|
|
124
|
+
// the seed is skip-if-exists. The CLI banner already lists them
|
|
125
|
+
// at startup. Excluded from the seed entirely.
|
|
126
|
+
const html = renderServerRoot({ version: '1.2.3', singleUser: true, enabled: { idp: true, nostr: true } });
|
|
127
|
+
assert.doesNotMatch(html, /<code>single-user<\/code>/);
|
|
128
|
+
assert.doesNotMatch(html, /<span>idp<\/span>/);
|
|
129
|
+
assert.doesNotMatch(html, /<span>nostr<\/span>/);
|
|
130
|
+
assert.doesNotMatch(html, /<code>1\.2\.3<\/code>/);
|
|
131
|
+
// No info box at all — there's nothing left to put in it.
|
|
132
|
+
assert.doesNotMatch(html, /class="info"/);
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it('always emits the Get started button pointing at the docs introduction', () => {
|
|
136
|
+
const html = renderServerRoot({ version: '1.0.0' });
|
|
137
|
+
// The canonical URL is the introduction page, not the category.
|
|
138
|
+
// Docusaurus 3 doesn't auto-generate a category index page, so
|
|
139
|
+
// /docs/getting-started/ would 404. Link to the real document.
|
|
140
|
+
assert.match(html, /href="https:\/\/jss\.live\/docs\/getting-started\/introduction"/);
|
|
141
|
+
assert.match(html, /Get started/);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it('emits Sign up + Sign in buttons hidden for the HEAD probe to reveal, with page-relative hrefs', () => {
|
|
145
|
+
const html = renderServerRoot({ version: '1.0.0' });
|
|
146
|
+
// Page-relative (./idp/...) so a reverse-proxy mount under a path
|
|
147
|
+
// prefix sends visitors into the correct prefix instead of the
|
|
148
|
+
// origin root. Same rationale as the ./ ACL targets from #428.
|
|
149
|
+
assert.match(html, /<a href="\.\/idp\/register"[^>]*data-cond="register"[^>]*hidden/);
|
|
150
|
+
assert.match(html, /<a href="\.\/idp"[^>]*data-cond="login"[^>]*hidden/);
|
|
151
|
+
assert.doesNotMatch(html, /<a href="\/idp\/register"/,
|
|
152
|
+
'Sign up href must be page-relative for path-prefix portability');
|
|
153
|
+
assert.doesNotMatch(html, /<a href="\/idp"/,
|
|
154
|
+
'Sign in href must be page-relative for path-prefix portability');
|
|
155
|
+
assert.match(html, /Sign up/);
|
|
106
156
|
assert.match(html, /Sign in/);
|
|
107
157
|
});
|
|
108
158
|
|
|
109
|
-
it('
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
assert.match(html, /
|
|
159
|
+
it('overrides the .btn display rule for the [hidden] attribute so the buttons actually start hidden', () => {
|
|
160
|
+
// Without an explicit !important [hidden] rule, the .btn class's
|
|
161
|
+
// display:inline-block beats the UA stylesheet's [hidden]{display:none}
|
|
162
|
+
// and the Sign up / Sign in anchors flash visible before the HEAD probe
|
|
163
|
+
// finishes. The CSS rule is the load-bearing piece; assert it's there.
|
|
164
|
+
const html = renderServerRoot({ version: '1.0.0' });
|
|
165
|
+
assert.match(html, /\[hidden\]\s*\{[^}]*display:\s*none\s*!important/);
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it('includes the HEAD-adaptive script targeting ./idp/register (page-relative)', () => {
|
|
169
|
+
const html = renderServerRoot({ version: '1.0.0' });
|
|
170
|
+
// Same path-prefix portability concern as the anchor hrefs.
|
|
171
|
+
assert.match(html, /fetch\(['"]\.\/idp\/register['"]/);
|
|
172
|
+
assert.doesNotMatch(html, /fetch\(['"]\/idp\/register['"]/,
|
|
173
|
+
'HEAD probe URL must be page-relative for path-prefix portability');
|
|
174
|
+
assert.match(html, /method:\s*['"]HEAD['"]/);
|
|
175
|
+
assert.match(html, /res\.status === 200/);
|
|
176
|
+
assert.match(html, /res\.status === 403/);
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it('includes the live-URL script that resolves the document base, not just origin', () => {
|
|
180
|
+
const html = renderServerRoot({ version: '1.0.0' });
|
|
181
|
+
assert.match(html, /id="server-url"/);
|
|
182
|
+
// Must use new URL('./', window.location.href) so a reverse-proxy
|
|
183
|
+
// mount at a path prefix is preserved. window.location.origin alone
|
|
184
|
+
// would drop the prefix and display the proxy origin instead.
|
|
185
|
+
assert.match(html, /new URL\(['"]\.\/['"],\s*window\.location\.href\)/);
|
|
186
|
+
assert.doesNotMatch(html, /textContent\s*=\s*window\.location\.origin/,
|
|
187
|
+
'live-URL must not display origin-only — it would drop the path prefix on reverse-proxy mounts');
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
it('uses a page-relative fallback href on the live-URL anchor', () => {
|
|
191
|
+
// Before the script runs (or if scripts are blocked / blocked by CSP),
|
|
192
|
+
// the anchor is still clickable. A href="/" fallback would escape
|
|
193
|
+
// any reverse-proxy path prefix; use href="./" so the link stays
|
|
194
|
+
// inside the mount.
|
|
195
|
+
const html = renderServerRoot({ version: '1.0.0' });
|
|
196
|
+
assert.match(html, /<a id="server-url" href="\.\/"/);
|
|
197
|
+
assert.doesNotMatch(html, /<a id="server-url" href="\/"/,
|
|
198
|
+
'fallback href must be page-relative for path-prefix portability');
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
it('points the footer at the GitHub repo and the customise hint', () => {
|
|
202
|
+
const html = renderServerRoot({ version: '1.0.0' });
|
|
203
|
+
assert.match(html, /href="https:\/\/github\.com\/JavaScriptSolidServer\/JavaScriptSolidServer"/);
|
|
204
|
+
assert.match(html, /Customise this page/);
|
|
205
|
+
assert.match(html, /<code>\/index\.html<\/code>/);
|
|
125
206
|
});
|
|
207
|
+
});
|
|
126
208
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
assert.
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
it('
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
assert.
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
});
|
|
167
|
-
assert.match(html, /Personal pod for evil\{\{actions\}\}name/,
|
|
168
|
-
'singleUserName containing a template token should appear as plain text, not be re-templated');
|
|
169
|
-
// Sanity: the real {{actions}} slot is still resolved (Docs link is always present).
|
|
170
|
-
assert.match(html, /href="https:\/\/javascriptsolidserver\.github\.io\/docs/);
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
// Regression for the `$&` substitution gotcha (#433): a string used as
|
|
174
|
-
// the second argument of String.prototype.replace interprets `$&`,
|
|
175
|
-
// `$1`, etc. as substitution patterns. Interpolated values can contain
|
|
176
|
-
// `$` (notably a singleUserName), so the renderer uses the function
|
|
177
|
-
// form of replace instead. Asserting the literal `$&` survives the
|
|
178
|
-
// round-trip would mean it survived as plain text.
|
|
179
|
-
it('preserves $-patterns in singleUserName instead of treating them as replacement specials', () => {
|
|
180
|
-
const html = renderServerRoot({
|
|
181
|
-
version: '1.0.0',
|
|
182
|
-
singleUser: true,
|
|
183
|
-
idp: false,
|
|
184
|
-
singleUserName: 'foo$&bar'
|
|
185
|
-
});
|
|
186
|
-
// The HTML escape converts `&` to `&`; the rest must stay verbatim,
|
|
187
|
-
// not be replaced by the matched template token.
|
|
188
|
-
assert.match(html, /Personal pod for foo\$&bar/,
|
|
189
|
-
'singleUserName containing "$&" should land as-is, not trigger String.replace substitution');
|
|
190
|
-
assert.doesNotMatch(html, /\{\{subtitle\}\}/, 'subtitle token should be fully consumed');
|
|
209
|
+
// Pure-function unit tests for the HEAD response → button-reveal matrix.
|
|
210
|
+
// The inline script in server-root.html implements the same matrix by
|
|
211
|
+
// hand; a regex check on the script text (above) catches outright drops
|
|
212
|
+
// of the literals, but only this helper test pins down the *behaviour*
|
|
213
|
+
// of the matrix without needing a DOM.
|
|
214
|
+
describe('decideRevealForRegisterStatus', () => {
|
|
215
|
+
it('reveals both Sign up and Sign in for HTTP 200 (registration open)', () => {
|
|
216
|
+
assert.deepStrictEqual(
|
|
217
|
+
decideRevealForRegisterStatus(200),
|
|
218
|
+
{ register: true, login: true }
|
|
219
|
+
);
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
it('reveals only Sign in for HTTP 403 (single-user — registration disabled)', () => {
|
|
223
|
+
assert.deepStrictEqual(
|
|
224
|
+
decideRevealForRegisterStatus(403),
|
|
225
|
+
{ register: false, login: true }
|
|
226
|
+
);
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
it('reveals neither for HTTP 404 (no IDP)', () => {
|
|
230
|
+
assert.deepStrictEqual(
|
|
231
|
+
decideRevealForRegisterStatus(404),
|
|
232
|
+
{ register: false, login: false }
|
|
233
|
+
);
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
it('reveals neither for any other status (e.g. 500)', () => {
|
|
237
|
+
assert.deepStrictEqual(
|
|
238
|
+
decideRevealForRegisterStatus(500),
|
|
239
|
+
{ register: false, login: false }
|
|
240
|
+
);
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
it('reveals neither when status is undefined (network error)', () => {
|
|
244
|
+
assert.deepStrictEqual(
|
|
245
|
+
decideRevealForRegisterStatus(undefined),
|
|
246
|
+
{ register: false, login: false }
|
|
247
|
+
);
|
|
191
248
|
});
|
|
192
249
|
});
|