Compare commits
37 changed files with 68 additions and 257 deletions
|
|
@ -1,5 +1,5 @@
|
||||||
# Runs on Forgejo Actions. The jobs ask for a runner labelled `docker` that runs each job in the
|
# Runs on Forgejo Actions (Codeberg). Enable Actions in the repository settings and make sure
|
||||||
# container named below; change `runs-on` if your runner is labelled differently.
|
# a runner with the `docker` label is available; change `runs-on` if yours is named differently.
|
||||||
name: ci
|
name: ci
|
||||||
|
|
||||||
on:
|
on:
|
||||||
|
|
@ -12,9 +12,6 @@ jobs:
|
||||||
runs-on: docker
|
runs-on: docker
|
||||||
container: golang:1.27
|
container: golang:1.27
|
||||||
steps:
|
steps:
|
||||||
# The checkout action runs on Node, which the golang image does not carry.
|
|
||||||
- name: Install Node
|
|
||||||
run: apt-get update -qq && apt-get install -y -qq nodejs git
|
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- run: make go-ci
|
- run: make go-ci
|
||||||
|
|
||||||
|
|
@ -31,8 +28,5 @@ jobs:
|
||||||
runs-on: docker
|
runs-on: docker
|
||||||
container: golang:1.27
|
container: golang:1.27
|
||||||
steps:
|
steps:
|
||||||
# The checkout action runs on Node, which the golang image does not carry.
|
|
||||||
- name: Install Node
|
|
||||||
run: apt-get update -qq && apt-get install -y -qq nodejs git
|
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- run: make vuln
|
- run: make vuln
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,5 @@
|
||||||
# The end-to-end test starts Postfix and parsimony in Docker, so it needs a runner that can run
|
# The end-to-end test starts Postfix and parsimony in Docker, so it needs a runner that can run
|
||||||
# Docker itself, with the job on the host network (it talks to published ports on 127.0.0.1 and
|
# Docker itself. Start it by hand from the Actions tab (or run `make e2e` locally).
|
||||||
# mounts temporary directories). A plain `docker` runner does not give a job a Docker daemon, and
|
|
||||||
# I have not run this workflow on a runner: use `make e2e` locally. Start it by hand from the
|
|
||||||
# Actions tab only once you have such a runner.
|
|
||||||
name: e2e
|
name: e2e
|
||||||
|
|
||||||
on:
|
on:
|
||||||
|
|
|
||||||
2
.gitignore
vendored
2
.gitignore
vendored
|
|
@ -1,4 +1,4 @@
|
||||||
/parsimony
|
parsimony
|
||||||
*.db
|
*.db
|
||||||
*.db-*
|
*.db-*
|
||||||
admin/node_modules
|
admin/node_modules
|
||||||
|
|
|
||||||
|
|
@ -1,35 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"reflect"
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestServeArgs(t *testing.T) {
|
|
||||||
cases := []struct {
|
|
||||||
name string
|
|
||||||
args []string
|
|
||||||
want []string
|
|
||||||
serve bool
|
|
||||||
}{
|
|
||||||
{"explicit serve", []string{"serve"}, []string{}, true},
|
|
||||||
{"explicit serve with flags", []string{"serve", "-config", "x.yaml"}, []string{"-config", "x.yaml"}, true},
|
|
||||||
{"legacy -config", []string{"-config", "x.yaml"}, []string{"-config", "x.yaml"}, true},
|
|
||||||
{"legacy --config", []string{"--config", "x.yaml"}, []string{"--config", "x.yaml"}, true},
|
|
||||||
{"legacy -config=", []string{"-config=x.yaml"}, []string{"-config=x.yaml"}, true},
|
|
||||||
{"legacy --config=", []string{"--config=x.yaml"}, []string{"--config=x.yaml"}, true},
|
|
||||||
{"admin command", []string{"list", "ls"}, nil, false},
|
|
||||||
{"global flag then admin command", []string{"--json", "list", "ls"}, nil, false},
|
|
||||||
{"url flag", []string{"--url", "http://x", "queue", "ls"}, nil, false},
|
|
||||||
{"help", []string{"help"}, nil, false},
|
|
||||||
{"nothing", nil, nil, false},
|
|
||||||
{"serve is only a command name in first position", []string{"list", "serve"}, nil, false},
|
|
||||||
{"a list called serve@x is not the serve command", []string{"list", "show", "serve@example.org"}, nil, false},
|
|
||||||
}
|
|
||||||
for _, c := range cases {
|
|
||||||
got, ok := serveArgs(c.args)
|
|
||||||
if ok != c.serve || (ok && !reflect.DeepEqual(got, c.want)) {
|
|
||||||
t.Errorf("%s: serveArgs(%v) = %v, %v; want %v, %v", c.name, c.args, got, ok, c.want, c.serve)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,75 +0,0 @@
|
||||||
// Command parsimony runs the mailing list daemon and administers it.
|
|
||||||
//
|
|
||||||
// parsimony serve [-config FILE] run the server
|
|
||||||
// parsimony list|member|... command-line client (see "parsimony help")
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"flag"
|
|
||||||
"log"
|
|
||||||
"os"
|
|
||||||
"os/signal"
|
|
||||||
"strings"
|
|
||||||
"syscall"
|
|
||||||
|
|
||||||
"git.kmalloc.org/squid/parsimony/internal/app"
|
|
||||||
"git.kmalloc.org/squid/parsimony/internal/cli"
|
|
||||||
"git.kmalloc.org/squid/parsimony/internal/config"
|
|
||||||
)
|
|
||||||
|
|
||||||
// serveArgs reports whether the invocation starts the server and returns its flags.
|
|
||||||
// "parsimony -config FILE" (before the serve subcommand existed) still works.
|
|
||||||
func serveArgs(args []string) ([]string, bool) {
|
|
||||||
if len(args) == 0 {
|
|
||||||
return nil, false
|
|
||||||
}
|
|
||||||
if args[0] == "serve" {
|
|
||||||
return args[1:], true
|
|
||||||
}
|
|
||||||
if a := args[0]; a == "-config" || a == "--config" || strings.HasPrefix(a, "-config=") || strings.HasPrefix(a, "--config=") {
|
|
||||||
return args, true
|
|
||||||
}
|
|
||||||
return nil, false
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
if args, ok := serveArgs(os.Args[1:]); ok {
|
|
||||||
serve(args)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
os.Exit(cli.Run(os.Args[1:], cli.IO{In: os.Stdin, Out: os.Stdout, Err: os.Stderr}, os.Getenv))
|
|
||||||
}
|
|
||||||
|
|
||||||
func serve(args []string) {
|
|
||||||
fs := flag.NewFlagSet("parsimony serve", flag.ExitOnError)
|
|
||||||
cfgPath := fs.String("config", "parsimony.yaml", "path to the YAML config file")
|
|
||||||
fs.Parse(args)
|
|
||||||
|
|
||||||
cfg, err := config.Load(*cfgPath)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatalf("config: %v", err)
|
|
||||||
}
|
|
||||||
token := os.Getenv("PARSIMONY_API_TOKEN")
|
|
||||||
if err := checkAPIToken(token); err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
a, err := app.Start(cfg, token)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
log.Printf("LMTP listening on %s %s", cfg.LMTP.Network, a.LMTPAddr)
|
|
||||||
if a.APIAddr != "" {
|
|
||||||
log.Printf("API listening on %s", a.APIAddr)
|
|
||||||
} else {
|
|
||||||
log.Println("PARSIMONY_API_TOKEN is not set: REST API disabled")
|
|
||||||
}
|
|
||||||
if a.WebAddr != "" {
|
|
||||||
log.Printf("web listening on %s", a.WebAddr)
|
|
||||||
}
|
|
||||||
|
|
||||||
stop := make(chan os.Signal, 1)
|
|
||||||
signal.Notify(stop, syscall.SIGINT, syscall.SIGTERM)
|
|
||||||
<-stop
|
|
||||||
log.Println("shutting down")
|
|
||||||
a.Close()
|
|
||||||
}
|
|
||||||
|
|
@ -1,28 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"unicode"
|
|
||||||
)
|
|
||||||
|
|
||||||
// minTokenLength keeps the bearer token out of reach of guessing: 24 random characters.
|
|
||||||
const minTokenLength = 24
|
|
||||||
|
|
||||||
// checkAPIToken refuses a weak or malformed API token. An empty token is fine: the API is then disabled.
|
|
||||||
func checkAPIToken(token string) error {
|
|
||||||
if token == "" {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
for _, r := range token {
|
|
||||||
switch {
|
|
||||||
case unicode.IsSpace(r):
|
|
||||||
return fmt.Errorf("PARSIMONY_API_TOKEN contains whitespace (a trailing newline from a file?): remove it")
|
|
||||||
case unicode.IsControl(r):
|
|
||||||
return fmt.Errorf("PARSIMONY_API_TOKEN contains a control character")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if len(token) < minTokenLength {
|
|
||||||
return fmt.Errorf("PARSIMONY_API_TOKEN is too short (%d characters): use at least %d random characters, for example the output of `openssl rand -hex 24`", len(token), minTokenLength)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
@ -1,42 +0,0 @@
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"strings"
|
|
||||||
"testing"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestCheckAPIToken(t *testing.T) {
|
|
||||||
good := strings.Repeat("a", 24)
|
|
||||||
for name, tc := range map[string]struct {
|
|
||||||
token string
|
|
||||||
wantErr string // substring; "" means the token is fine
|
|
||||||
}{
|
|
||||||
"not set (API disabled)": {"", ""},
|
|
||||||
"24 characters": {good, ""},
|
|
||||||
"long": {strings.Repeat("x", 100), ""},
|
|
||||||
"23 characters": {good[:23], "at least 24"},
|
|
||||||
"a short word": {"tok", "at least 24"},
|
|
||||||
"trailing newline": {good + "\n", "whitespace"},
|
|
||||||
"inner space": {good[:12] + " " + good[12:], "whitespace"},
|
|
||||||
"tab": {good + "\t", "whitespace"},
|
|
||||||
"control character": {good + "\x00", "control"},
|
|
||||||
} {
|
|
||||||
err := checkAPIToken(tc.token)
|
|
||||||
switch {
|
|
||||||
case tc.wantErr == "" && err != nil:
|
|
||||||
t.Errorf("%s: unexpected error %v", name, err)
|
|
||||||
case tc.wantErr != "" && (err == nil || !strings.Contains(err.Error(), tc.wantErr)):
|
|
||||||
t.Errorf("%s: want an error containing %q, got %v", name, tc.wantErr, err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestTheTokenErrorSaysHowToMakeOne(t *testing.T) {
|
|
||||||
err := checkAPIToken("Zq9Xv7Kp")
|
|
||||||
if err == nil || !strings.Contains(err.Error(), "openssl rand -hex 24") || !strings.Contains(err.Error(), "PARSIMONY_API_TOKEN") {
|
|
||||||
t.Fatalf("%v", err)
|
|
||||||
}
|
|
||||||
if strings.Contains(err.Error(), "Zq9Xv7Kp") {
|
|
||||||
t.Fatal("never echo the token")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
2
go.mod
2
go.mod
|
|
@ -1,4 +1,4 @@
|
||||||
module git.kmalloc.org/squid/parsimony
|
module codeberg.org/squidd/parsimony
|
||||||
|
|
||||||
go 1.27.3
|
go 1.27.3
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,8 @@ import (
|
||||||
"unicode"
|
"unicode"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
|
||||||
"git.kmalloc.org/squid/parsimony/internal/archive"
|
"codeberg.org/squidd/parsimony/internal/archive"
|
||||||
"git.kmalloc.org/squid/parsimony/internal/store"
|
"codeberg.org/squidd/parsimony/internal/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Releaser approves a held message: it delivers it to the list.
|
// Releaser approves a held message: it delivers it to the list.
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.kmalloc.org/squid/parsimony/internal/store"
|
"codeberg.org/squidd/parsimony/internal/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
const token = "s3cret"
|
const token = "s3cret"
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.kmalloc.org/squid/parsimony/internal/store"
|
"codeberg.org/squidd/parsimony/internal/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
type clock struct {
|
type clock struct {
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.kmalloc.org/squid/parsimony/internal/store"
|
"codeberg.org/squidd/parsimony/internal/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
type postJSON struct {
|
type postJSON struct {
|
||||||
|
|
|
||||||
|
|
@ -14,16 +14,16 @@ import (
|
||||||
|
|
||||||
"github.com/emersion/go-smtp"
|
"github.com/emersion/go-smtp"
|
||||||
|
|
||||||
"git.kmalloc.org/squid/parsimony/internal/adminui"
|
"codeberg.org/squidd/parsimony/internal/adminui"
|
||||||
"git.kmalloc.org/squid/parsimony/internal/api"
|
"codeberg.org/squidd/parsimony/internal/api"
|
||||||
"git.kmalloc.org/squid/parsimony/internal/config"
|
"codeberg.org/squidd/parsimony/internal/config"
|
||||||
"git.kmalloc.org/squid/parsimony/internal/dkimsign"
|
"codeberg.org/squidd/parsimony/internal/dkimsign"
|
||||||
"git.kmalloc.org/squid/parsimony/internal/ingest"
|
"codeberg.org/squidd/parsimony/internal/ingest"
|
||||||
"git.kmalloc.org/squid/parsimony/internal/outbound"
|
"codeberg.org/squidd/parsimony/internal/outbound"
|
||||||
"git.kmalloc.org/squid/parsimony/internal/queue"
|
"codeberg.org/squidd/parsimony/internal/queue"
|
||||||
"git.kmalloc.org/squid/parsimony/internal/router"
|
"codeberg.org/squidd/parsimony/internal/router"
|
||||||
"git.kmalloc.org/squid/parsimony/internal/store"
|
"codeberg.org/squidd/parsimony/internal/store"
|
||||||
"git.kmalloc.org/squid/parsimony/internal/web"
|
"codeberg.org/squidd/parsimony/internal/web"
|
||||||
)
|
)
|
||||||
|
|
||||||
// shutdownTimeout bounds how long Close waits for the sessions in flight before it cuts them.
|
// shutdownTimeout bounds how long Close waits for the sessions in flight before it cuts them.
|
||||||
|
|
|
||||||
|
|
@ -31,8 +31,8 @@ import (
|
||||||
"github.com/emersion/go-sasl"
|
"github.com/emersion/go-sasl"
|
||||||
"github.com/emersion/go-smtp"
|
"github.com/emersion/go-smtp"
|
||||||
|
|
||||||
"git.kmalloc.org/squid/parsimony/internal/config"
|
"codeberg.org/squidd/parsimony/internal/config"
|
||||||
"git.kmalloc.org/squid/parsimony/internal/store"
|
"codeberg.org/squidd/parsimony/internal/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
// sink is a fake SMTP relay that records what it receives.
|
// sink is a fake SMTP relay that records what it receives.
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,8 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.kmalloc.org/squid/parsimony/internal/mbox"
|
"codeberg.org/squidd/parsimony/internal/mbox"
|
||||||
"git.kmalloc.org/squid/parsimony/internal/store"
|
"codeberg.org/squidd/parsimony/internal/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.kmalloc.org/squid/parsimony/internal/store"
|
"codeberg.org/squidd/parsimony/internal/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
var importNow = time.Date(2031, 5, 6, 7, 8, 9, 0, time.UTC)
|
var importNow = time.Date(2031, 5, 6, 7, 8, 9, 0, time.UTC)
|
||||||
|
|
|
||||||
|
|
@ -20,9 +20,9 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.kmalloc.org/squid/parsimony/internal/api"
|
"codeberg.org/squidd/parsimony/internal/api"
|
||||||
"git.kmalloc.org/squid/parsimony/internal/dkimsign"
|
"codeberg.org/squidd/parsimony/internal/dkimsign"
|
||||||
"git.kmalloc.org/squid/parsimony/internal/store"
|
"codeberg.org/squidd/parsimony/internal/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
const token = "cli-token"
|
const token = "cli-token"
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import (
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"git.kmalloc.org/squid/parsimony/internal/dkimsign"
|
"codeberg.org/squidd/parsimony/internal/dkimsign"
|
||||||
)
|
)
|
||||||
|
|
||||||
// lookupTXT resolves DNS TXT records; tests replace it.
|
// lookupTXT resolves DNS TXT records; tests replace it.
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.kmalloc.org/squid/parsimony/internal/store"
|
"codeberg.org/squidd/parsimony/internal/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestPostsLs(t *testing.T) {
|
func TestPostsLs(t *testing.T) {
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ import (
|
||||||
|
|
||||||
"github.com/emersion/go-smtp"
|
"github.com/emersion/go-smtp"
|
||||||
|
|
||||||
"git.kmalloc.org/squid/parsimony/internal/router"
|
"codeberg.org/squidd/parsimony/internal/router"
|
||||||
)
|
)
|
||||||
|
|
||||||
const maxMessageBytes = 25 << 20
|
const maxMessageBytes = 25 << 20
|
||||||
|
|
|
||||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue