console v2026.10.12.2 and webmail inbuxa-v2026.10.12-g6e1a1cb are the first releases to carry their tarballs; their checksums are pinned, from the releases' SHA256SUMS and checked against downloads (the webmail's two architectures are identical inside, with no native code). The console's and the webmail's images follow the same constants, so a container and a host install of either are the same release. Server 2026.10.12.1 (upstream 0.16.26, with inbuxa:FrontEnds) replaces 2026.10.12, checksums pinned the same way; still glibc 2.39. join's refusal of an older server, and the README, name it. The interface's components screen now also asks the whole plan, so a choice the machine could make but the other choices rule out -- the console as files on loopback, with no web server to serve them -- is refused there, not first at the plan. All e2e cases on the real downloads, no overrides: webmail-host 18/18, all-host 17/17, join 24/24 (against the released server), install-host 43/43, install-local 26/26, install-public 20/20, proxy-snippets 13/13, interface 22/22, status-export 16/16, topology 28/28.
121 lines
4.3 KiB
Go
121 lines
4.3 KiB
Go
// SPDX-FileCopyrightText: 2026 Coffey Labs LLC
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
package apply
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
|
|
"git.coffeylabs.org/inbuxa/inbuxa-installer/internal/plan"
|
|
)
|
|
|
|
// fakeServer answers as an inbuxa server would for join: a session for the
|
|
// right key, and inbuxa:FrontEnds/get with what frontEnds holds. A nil
|
|
// frontEnds is a server too old to have it.
|
|
func fakeServer(t *testing.T, frontEnds map[string]any) *httptest.Server {
|
|
t.Helper()
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
if r.Header.Get("Authorization") != "Bearer good-key" {
|
|
w.WriteHeader(http.StatusUnauthorized)
|
|
return
|
|
}
|
|
switch r.URL.Path {
|
|
case "/jmap/session":
|
|
w.Write([]byte(`{"capabilities":{"urn:ietf:params:jmap:core":{},"urn:inbuxa:jmap":{}},
|
|
"primaryAccounts":{"urn:inbuxa:jmap":"admin1"}}`))
|
|
case "/jmap/":
|
|
var req struct {
|
|
MethodCalls [][3]json.RawMessage `json:"methodCalls"`
|
|
}
|
|
json.NewDecoder(r.Body).Decode(&req)
|
|
var method string
|
|
json.Unmarshal(req.MethodCalls[0][0], &method)
|
|
if method != "inbuxa:FrontEnds/get" {
|
|
t.Errorf("join's check sent %s", method)
|
|
}
|
|
if frontEnds == nil {
|
|
w.Write([]byte(`{"methodResponses":[["error",{"type":"unknownMethod"},"0"]]}`))
|
|
return
|
|
}
|
|
b, _ := json.Marshal(map[string]any{"methodResponses": []any{
|
|
[]any{"inbuxa:FrontEnds/get", map[string]any{"list": []any{frontEnds}}, "0"},
|
|
}})
|
|
w.Write(b)
|
|
default:
|
|
w.WriteHeader(http.StatusNotFound)
|
|
}
|
|
}))
|
|
t.Cleanup(srv.Close)
|
|
return srv
|
|
}
|
|
|
|
func joinOptions(serverURL string, replace bool) plan.Options {
|
|
return plan.Options{
|
|
ServerURL: serverURL, Domain: "example.com", Replace: replace,
|
|
ConsoleHost: "admin.example.com", WebmailHost: "webmail.example.com",
|
|
Choices: []plan.Choice{
|
|
{Component: plan.Server, Shape: plan.Skip},
|
|
{Component: plan.Console, Shape: plan.Container},
|
|
{Component: plan.Webmail, Shape: plan.Container},
|
|
},
|
|
}
|
|
}
|
|
|
|
func TestJoinCheck(t *testing.T) {
|
|
ctx := context.Background()
|
|
for _, tc := range []struct {
|
|
name string
|
|
frontEnds map[string]any
|
|
key string
|
|
replace bool
|
|
want string // a word the refusal must contain; "" for none
|
|
}{
|
|
{"a fresh server takes them", map[string]any{"environmentWebmailClientSecret": false}, "good-key", false, ""},
|
|
{"the same addresses again", map[string]any{"adminUrl": "https://admin.example.com", "webmailUrl": "https://webmail.example.com"}, "good-key", false, ""},
|
|
{"a wrong key", map[string]any{}, "bad-key", false, "API key"},
|
|
{"a server too old", nil, "good-key", false, "or newer"},
|
|
{"another console listed", map[string]any{"adminUrl": "https://other.example.com"}, "good-key", false, "--replace"},
|
|
{"another console, replaced", map[string]any{"adminUrl": "https://other.example.com"}, "good-key", true, ""},
|
|
{"another webmail listed", map[string]any{"webmailUrl": "https://mail-ui.example.com"}, "good-key", false, "--replace"},
|
|
{"the server's environment holds the secret", map[string]any{"environmentWebmailClientSecret": true}, "good-key", true, "INBUXA_WEBMAIL_CLIENT_SECRET"},
|
|
} {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
srv := fakeServer(t, tc.frontEnds)
|
|
err := JoinCheck(ctx, joinOptions(srv.URL, tc.replace), tc.key)
|
|
switch {
|
|
case tc.want == "" && err != nil:
|
|
t.Errorf("refused: %v", err)
|
|
case tc.want != "" && err == nil:
|
|
t.Errorf("accepted, want a refusal naming %q", tc.want)
|
|
case tc.want != "" && !strings.Contains(err.Error(), tc.want):
|
|
t.Errorf("refusal %q does not name %q", err, tc.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestJoinWithoutAWebmailIgnoresItsSecret(t *testing.T) {
|
|
srv := fakeServer(t, map[string]any{"environmentWebmailClientSecret": true, "webmailUrl": "https://elsewhere.example.com"})
|
|
o := joinOptions(srv.URL, false)
|
|
o.Choices[2].Shape = plan.Skip
|
|
if err := JoinCheck(context.Background(), o, "good-key"); err != nil {
|
|
t.Errorf("a console-only join was refused over the webmail: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestJoinURLs(t *testing.T) {
|
|
o := joinOptions("https://mail.example.com", false)
|
|
if c, w := joinURLs(o); c != "https://admin.example.com" || w != "https://webmail.example.com" {
|
|
t.Errorf("urls = %s, %s", c, w)
|
|
}
|
|
o.Local = true
|
|
if c, w := joinURLs(o); c != "http://127.0.0.1:8082" || w != "http://127.0.0.1:8080" {
|
|
t.Errorf("local urls = %s, %s", c, w)
|
|
}
|
|
}
|