All checks were successful
check / check (push) Successful in 6s
## Summary Adds username and hostname support to sessions, enabling standard IRC hostmask format (`nick!user@host`) for WHOIS, WHO, and future `+b` ban matching. closes #81 ## Changes ### Schema (`001_initial.sql`) - Added `username TEXT NOT NULL DEFAULT ''` and `hostname TEXT NOT NULL DEFAULT ''` columns to the `sessions` table ### Database layer (`internal/db/`) - `CreateSession` now accepts `username` and `hostname` parameters; username defaults to nick if empty - `RegisterUser` now accepts `username` and `hostname` parameters - New `SessionHostInfo` type and `GetSessionHostInfo` query to retrieve username/hostname for a session - `MemberInfo` now includes `Username` and `Hostname` fields - `ChannelMembers` query updated to return username/hostname - New `FormatHostmask(nick, username, hostname)` helper that produces `nick!user@host` format - New `Hostmask()` method on `MemberInfo` ### Handler layer (`internal/handlers/`) - Session creation (`POST /api/v1/session`) accepts optional `username` field; resolves hostname via reverse DNS of connecting client IP (respects `X-Forwarded-For` and `X-Real-IP` headers) - Registration (`POST /api/v1/register`) accepts optional `username` field with the same hostname resolution - Username validation regex: `^[a-zA-Z0-9_\-\[\]\\^{}|` + "\`" + `]{1,32}$` - WHOIS (`311 RPL_WHOISUSER`) now returns the real username and hostname instead of nick/servername - WHO (`352 RPL_WHOREPLY`) now returns the real username and hostname instead of nick/servername - Extracted `validateHashcash` and `resolveUsername` helpers to keep functions under the linter's `funlen` limit - Extracted `executeRegister` helper for the same reason - Reverse DNS uses `(*net.Resolver).LookupAddr` with a 3-second timeout context ### Tests - `TestCreateSessionWithUserHost` — verifies username/hostname are stored and retrievable - `TestCreateSessionDefaultUsername` — verifies empty username defaults to nick - `TestGetSessionHostInfoNotFound` — verifies error on nonexistent session - `TestFormatHostmask` — verifies `nick!user@host` formatting - `TestFormatHostmaskDefaults` — verifies fallback when username/hostname empty - `TestMemberInfoHostmask` — verifies `Hostmask()` method on `MemberInfo` - `TestChannelMembersIncludeUserHost` — verifies `ChannelMembers` returns username/hostname - `TestRegisterUserWithUserHost` — verifies registration stores username/hostname - `TestRegisterUserDefaultUsername` — verifies registration defaults username to nick - `TestWhoisShowsHostInfo` — integration test verifying WHOIS returns the correct username - `TestWhoShowsHostInfo` — integration test verifying WHO returns the correct username - `TestSessionUsernameDefault` — integration test verifying default username in WHOIS - All existing tests updated for new `CreateSession`/`RegisterUser` signatures ### README - New "Hostmask" section documenting the `nick!user@host` format - Updated session creation and registration API docs with the new `username` field - Updated WHOIS/WHO numeric examples to show real username/hostname - Updated sessions schema table with new columns ## Docker build `docker build .` passes cleanly (lint, format, tests, build). Co-authored-by: user <user@Mac.lan guest wan> Co-authored-by: clawbot <clawbot@noreply.git.eeqj.de> Co-authored-by: clawbot <clawbot@eeqj.de> Reviewed-on: #82 Co-authored-by: clawbot <clawbot@noreply.example.org> Co-committed-by: clawbot <clawbot@noreply.example.org>
61 lines
1.9 KiB
Makefile
61 lines
1.9 KiB
Makefile
.PHONY: all build lint fmt fmt-check test check clean run debug docker hooks ensure-web-dist
|
|
|
|
BINARY := neoircd
|
|
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
|
|
BUILDARCH := $(shell go env GOARCH)
|
|
LDFLAGS := -X main.Version=$(VERSION) -X main.Buildarch=$(BUILDARCH)
|
|
|
|
all: check build
|
|
|
|
# ensure-web-dist creates placeholder files so //go:embed dist/* in
|
|
# web/embed.go resolves without a full Node.js build. The real SPA is
|
|
# built by the web-builder Docker stage; these placeholders let
|
|
# "make test" and "make build" work outside Docker.
|
|
ensure-web-dist:
|
|
@if [ ! -d web/dist ]; then \
|
|
mkdir -p web/dist && \
|
|
touch web/dist/index.html web/dist/style.css web/dist/app.js && \
|
|
echo "==> Created placeholder web/dist/ for go:embed"; \
|
|
fi
|
|
|
|
build: ensure-web-dist
|
|
go build -ldflags "$(LDFLAGS)" -o bin/$(BINARY) ./cmd/neoircd
|
|
|
|
lint: ensure-web-dist
|
|
golangci-lint run --config .golangci.yml ./...
|
|
|
|
fmt:
|
|
gofmt -s -w .
|
|
goimports -w .
|
|
|
|
fmt-check:
|
|
@test -z "$$(gofmt -l .)" || (echo "Files not formatted:" && gofmt -l . && exit 1)
|
|
|
|
test: ensure-web-dist
|
|
go test -timeout 30s -race -cover ./... || go test -timeout 30s -race -v ./...
|
|
|
|
# check runs all validation without making changes
|
|
# Used by CI and Docker build — fails if anything is wrong
|
|
check: test lint fmt-check
|
|
@echo "==> Building..."
|
|
go build -ldflags "$(LDFLAGS)" -o /dev/null ./cmd/neoircd
|
|
@echo "==> All checks passed!"
|
|
|
|
run: build
|
|
./bin/$(BINARY)
|
|
|
|
debug: build
|
|
DEBUG=1 GOTRACEBACK=all ./bin/$(BINARY)
|
|
|
|
clean:
|
|
rm -rf bin/ neoircd
|
|
|
|
docker:
|
|
docker build -t neoirc .
|
|
|
|
hooks:
|
|
@printf '#!/bin/sh\nset -e\n' > .git/hooks/pre-commit
|
|
@printf 'go mod tidy\ngo fmt ./...\ngit diff --exit-code -- go.mod go.sum || { echo "go mod tidy changed files; please stage and retry"; exit 1; }\n' >> .git/hooks/pre-commit
|
|
@printf 'make check\n' >> .git/hooks/pre-commit
|
|
@chmod +x .git/hooks/pre-commit
|