commit cc6c39167778dd5c304aa31a090aa1671bf4a167
parent ec4ca6792ceafa415f57a2ec2d5e9f83c35f78c2
Author: Bharatvaj Hemanth <bharatvaj@yahoo.com>
Date: Sun, 22 Nov 2026 20:05:52 +0530
parent ec4ca6792ceafa415f57a2ec2d5e9f83c35f78c2
Author: Bharatvaj Hemanth <bharatvaj@yahoo.com>
Date: Sun, 22 Nov 2026 20:05:52 +0530
Run FxA CLI regressions in Go and document browser acceptance
4 files changed, 232 insertions(+), 154 deletions(-)
M
|
313
+++++++++++++++++++++++++++++++++++++++++++------------------------------------
diff --git a/Unix/minimal-fxa-server/APKBUILD b/Unix/minimal-fxa-server/APKBUILD @@ -1,6 +1,6 @@ pkgname=minimal-fxa-server pkgver=0_git20260225 -pkgrel=6 +pkgrel=7 # Explicit Debian output opt-in; upstream's underscore version is not Debian-valid. deb_pkgver=0+git20260225 deb_postinst=debian.postinst @@ -18,8 +18,8 @@ source="$url/archive/$_commit.tar.gz debian.postinst" sha256sums=" d336c2d13f58b915dca33a3cd20a9d44239d800fa02b38a19b1ee7fd5efbc08a $_commit.tar.gz -12162d02df485ec02e668f6b9591458c44c5fd2a7823908f8f620956e0a60348 enforce-pkce.patch -2d4ea552beb7ba97fb78393e6deac70ac79066aa35ce998c6b7bb283132be052 cli-rpc-timeout.patch +c7fab781228057577951fa1e61030d305b19035dcdbd7800232ffc32e925ee04 enforce-pkce.patch +c2f1d4240c86a0337dc0b56f268bdeacfe0976ba55592ef647cc2223cc649c82 cli-rpc-timeout.patch 2082b30dae3fdb4f7afa1b00b1623e94c264f80d1d22897ad6a3f1f7ad83adab debian.postinst " builddir="$srcdir/$pkgname-$_commit"
diff --git a/Unix/minimal-fxa-server/cli-rpc-timeout.patch b/Unix/minimal-fxa-server/cli-rpc-timeout.patch @@ -1,25 +1,3 @@ -diff --git a/README.md b/README.md -index 8f9cc46..431117f 100644 ---- a/README.md -+++ b/README.md -@@ -64,6 +64,17 @@ fxa-user passwd user@example.com - fxa-user list - ``` - -+The CLI's RPC timeout starts after interactive input, not while typing passwords -+or confirming deletion. Override it at runtime with a positive Go duration: -+ -+```sh -+FXA_TIMEOUT=30s fxa-user create user@example.com -+``` -+ -+The default is `10s`; packagers can change it with -+`go build -ldflags="-X main.defaultRPCTimeout=30s" ./cmd/fxa-user`. -+`FXA_TIMEOUT` takes precedence over that build-time default. -+ - The CLI connects via Unix socket for security. In Docker/Kubernetes: - ```bash - kubectl exec -it <pod> -- fxa-user create admin@example.com diff --git a/cmd/fxa-user/main.go b/cmd/fxa-user/main.go index e6cc367..2aff785 100644 --- a/cmd/fxa-user/main.go @@ -170,133 +148,184 @@ index e6cc367..2aff785 100644 resp, err := client.ListUsers(ctx, &usermgmt.ListUsersRequest{}) if err != nil { fmt.Fprintf(os.Stderr, "Failed to list users: %v\n", err) -diff --git a/cmd/fxa-user/tests/prompt_timeout.py b/cmd/fxa-user/tests/prompt_timeout.py +diff --git a/cmd/fxa-user/main_test.go b/cmd/fxa-user/main_test.go new file mode 100644 -index 0000000..eb4b6e5 +index 0000000..23ae485 --- /dev/null -+++ b/cmd/fxa-user/tests/prompt_timeout.py -@@ -0,0 +1,124 @@ -+#!/usr/bin/env python3 -+"""Regression: interactive time must not consume the CLI's 10-second RPC deadline. -+ -+Run from the repository root: python3 cmd/fxa-user/tests/prompt_timeout.py -+Uses a disposable local gRPC stub and PTYs, not real accounts. Requires Go. -+""" -+import os -+import pathlib -+import pty -+import select -+import subprocess -+import tempfile -+import time ++++ b/cmd/fxa-user/main_test.go +@@ -0,0 +1,175 @@ ++package main + -+STUB = r'''package main +import ( -+ "context" -+ "net" -+ "os" -+ "time" -+ "fmt" -+ "github.com/ahyattdev/minimal-fxa-server/usermgmt" -+ "google.golang.org/grpc" ++ "bufio" ++ "bytes" ++ "context" ++ "fmt" ++ "io" ++ "net" ++ "os" ++ "os/exec" ++ "path/filepath" ++ "strings" ++ "testing" ++ "time" ++ ++ "github.com/ahyattdev/minimal-fxa-server/usermgmt" ++ "google.golang.org/grpc" +) -+type server struct { usermgmt.UnimplementedUserManagementServer } -+func checkDeadline(ctx context.Context) error { -+ expected,err:=time.ParseDuration(os.Getenv("EXPECTED_TIMEOUT"));if err!=nil{return err} -+ deadline,ok:=ctx.Deadline();remaining:=time.Until(deadline) -+ if !ok || remaining > expected || remaining < expected*3/4 {return fmt.Errorf("unexpected RPC deadline")};return nil ++ ++// Run the real CLI entry point in a child so os.Exit cannot terminate the suite. ++func TestCLIProcess(t *testing.T) { ++ if os.Getenv("FXA_CLI_TEST_PROCESS") != "1" { ++ return ++ } ++ for i, arg := range os.Args { ++ if arg == "--" { ++ os.Args = append([]string{"fxa-user"}, os.Args[i+1:]...) ++ main() ++ os.Exit(0) ++ } ++ } ++ os.Exit(2) ++} ++ ++func cliCommand(t *testing.T, timeout, socket string, args ...string) *exec.Cmd { ++ t.Helper() ++ binary, err := os.Executable() ++ if err != nil { ++ t.Fatal(err) ++ } ++ ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) ++ t.Cleanup(cancel) ++ cmd := exec.CommandContext(ctx, binary, append([]string{"-test.run=^TestCLIProcess$", "--"}, args...)...) ++ for _, entry := range os.Environ() { ++ if !strings.HasPrefix(entry, "FXA_TIMEOUT=") && !strings.HasPrefix(entry, "FXA_SOCKET=") && !strings.HasPrefix(entry, "FXA_CLI_TEST_PROCESS=") { ++ cmd.Env = append(cmd.Env, entry) ++ } ++ } ++ cmd.Env = append(cmd.Env, "FXA_CLI_TEST_PROCESS=1", "FXA_TIMEOUT="+timeout, "FXA_SOCKET="+socket) ++ return cmd ++} ++ ++type timeoutServer struct { ++ usermgmt.UnimplementedUserManagementServer ++ timeout time.Duration ++ block bool ++} ++ ++func (s timeoutServer) DeleteUser(ctx context.Context, _ *usermgmt.DeleteUserRequest) (*usermgmt.DeleteUserResponse, error) { ++ deadline, ok := ctx.Deadline() ++ remaining := time.Until(deadline) ++ if !ok || remaining <= s.timeout/2 || remaining > s.timeout { ++ return nil, fmt.Errorf("RPC did not receive a fresh deadline: %v", remaining) ++ } ++ return &usermgmt.DeleteUserResponse{Success: true}, nil +} -+func (server) CreateUser(ctx context.Context,_ *usermgmt.CreateUserRequest)(*usermgmt.CreateUserResponse,error){return &usermgmt.CreateUserResponse{Email:"fixture@example.invalid",UserId:"fixture"},checkDeadline(ctx)} -+func (server) ChangePassword(ctx context.Context,_ *usermgmt.ChangePasswordRequest)(*usermgmt.ChangePasswordResponse,error){return &usermgmt.ChangePasswordResponse{Success:true},checkDeadline(ctx)} -+func (server) DeleteUser(ctx context.Context,_ *usermgmt.DeleteUserRequest)(*usermgmt.DeleteUserResponse,error){return &usermgmt.DeleteUserResponse{Success:true},checkDeadline(ctx)} -+func (server) ListUsers(ctx context.Context,_ *usermgmt.ListUsersRequest)(*usermgmt.ListUsersResponse,error){return &usermgmt.ListUsersResponse{},checkDeadline(ctx)} -+func main(){l,e:=net.Listen("unix",os.Args[1]);if e!=nil{panic(e)};s:=grpc.NewServer();usermgmt.RegisterUserManagementServer(s,server{});if e=s.Serve(l);e!=nil{panic(e)}} -+''' + ++func (s timeoutServer) ListUsers(ctx context.Context, _ *usermgmt.ListUsersRequest) (*usermgmt.ListUsersResponse, error) { ++ if s.block { ++ <-ctx.Done() ++ return nil, ctx.Err() ++ } ++ deadline, ok := ctx.Deadline() ++ remaining := time.Until(deadline) ++ if !ok || remaining <= s.timeout/2 || remaining > s.timeout { ++ return nil, fmt.Errorf("unexpected RPC deadline: %v", remaining) ++ } ++ return &usermgmt.ListUsersResponse{}, nil ++} + -+def check_command(binary, socket, command): -+ master, slave = pty.openpty() -+ env = dict(os.environ, FXA_SOCKET=str(socket), FXA_TIMEOUT="2s") -+ process = subprocess.Popen( -+ [str(binary), command, "fixture@example.invalid"], -+ stdin=slave, stdout=slave, stderr=slave, env=env, -+ ) -+ os.close(slave) -+ output, sent = b"", 0 -+ try: -+ deadline = time.monotonic() + 35 -+ while time.monotonic() < deadline: -+ ready, _, _ = select.select([master], [], [], 0.2) -+ if ready: -+ try: -+ chunk = os.read(master, 4096) -+ except OSError: -+ break -+ if not chunk: -+ break -+ output += chunk -+ prompts = output.count(b"assword:") if command != "delete" else output.count(b"[y/N]:") -+ while sent < prompts: -+ if sent == 0: -+ time.sleep(11) -+ value = b"synthetic-password-only\n" if command != "delete" else b"y\n" -+ os.write(master, value) -+ sent += 1 -+ if process.poll() is not None: -+ break -+ result = process.wait(timeout=5) -+ assert b"DeadlineExceeded" not in output, command + ": deadline expired during user input" -+ expected = {"create": b"User created:", "passwd": b"Password changed for:", "delete": b"User deleted:"}[command] -+ assert result == 0 and expected in output, command + ": command failed" -+ print("PASS:", command, "accepts an 11-second pause at its prompt") -+ finally: -+ if process.poll() is None: -+ process.kill() -+ process.wait() -+ os.close(master) ++func startTimeoutServer(t *testing.T, server timeoutServer) string { ++ t.Helper() ++ // Keep Unix socket paths below the macOS limit, even with a long TMPDIR. ++ dir, err := os.MkdirTemp("/tmp", "fxa-cli-") ++ if err != nil { ++ t.Fatal(err) ++ } ++ t.Cleanup(func() { os.RemoveAll(dir) }) ++ socket := filepath.Join(dir, "rpc.sock") ++ listener, err := net.Listen("unix", socket) ++ if err != nil { ++ t.Fatal(err) ++ } ++ grpcServer := grpc.NewServer() ++ usermgmt.RegisterUserManagementServer(grpcServer, server) ++ t.Cleanup(grpcServer.Stop) ++ go grpcServer.Serve(listener) ++ return socket ++} + ++func TestDeleteDeadlineStartsAfterConfirmation(t *testing.T) { ++ const timeout = 500 * time.Millisecond ++ socket := startTimeoutServer(t, timeoutServer{timeout: timeout}) ++ cmd := cliCommand(t, timeout.String(), socket, "delete", "fixture@example.invalid") ++ stdin, err := cmd.StdinPipe() ++ if err != nil { ++ t.Fatal(err) ++ } ++ stdout, err := cmd.StdoutPipe() ++ if err != nil { ++ t.Fatal(err) ++ } ++ var stderr bytes.Buffer ++ cmd.Stderr = &stderr ++ if err := cmd.Start(); err != nil { ++ t.Fatal(err) ++ } ++ t.Cleanup(func() { cmd.Process.Kill(); cmd.Wait() }) ++ reader := bufio.NewReader(stdout) ++ prompt, err := reader.ReadString(':') ++ if err != nil || !strings.Contains(prompt, "[y/N]") { ++ t.Fatalf("missing confirmation prompt: %q, %v", prompt, err) ++ } ++ // Longer than the entire RPC budget: a deadline created before input fails. ++ time.Sleep(3 * timeout) ++ if _, err := io.WriteString(stdin, "y\n"); err != nil { ++ t.Fatal(err) ++ } ++ stdin.Close() ++ output, err := io.ReadAll(reader) ++ if err != nil { ++ t.Fatal(err) ++ } ++ if err := cmd.Wait(); err != nil || !bytes.Contains(output, []byte("User deleted:")) { ++ t.Fatalf("delete after delayed input: %v, stdout=%s, stderr=%s", err, output, &stderr) ++ } ++} + -+root = pathlib.Path(__file__).resolve().parents[3] -+go = os.environ.get("GO", "go") -+with tempfile.TemporaryDirectory(prefix="fxa-cli-timeout-", dir="/tmp") as directory: -+ work = pathlib.Path(directory) -+ (work / "server.go").write_text(STUB) -+ subprocess.run([go, "build", "-o", str(work / "stub"), str(work / "server.go")], cwd=root, check=True) -+ subprocess.run([go, "build", "-ldflags=-X main.defaultRPCTimeout=1s", "-o", str(work / "fxa-user"), "./cmd/fxa-user"], cwd=root, check=True) -+ env = dict(os.environ) -+ env.pop("FXA_TIMEOUT", None) -+ help_text = subprocess.check_output([str(work / "fxa-user"), "--help"], env=env) -+ assert b"(default: 1s)" in help_text, "build-time override missing from help" -+ for invalid in ["0s", "-1s", "invalid"]: -+ result = subprocess.run([str(work / "fxa-user"), "list"], env=dict(env, FXA_TIMEOUT=invalid), capture_output=True) -+ assert result.returncode != 0 and b"Invalid RPC timeout" in result.stderr -+ print("PASS: build-time default and invalid timeout validation") -+ socket = work / "rpc.sock" -+ server = subprocess.Popen([str(work / "stub"), str(socket)], env=dict(env, EXPECTED_TIMEOUT="1s")) -+ try: -+ for _ in range(100): -+ if socket.exists(): -+ break -+ assert server.poll() is None, "stub server exited" -+ time.sleep(0.05) -+ assert socket.exists(), "stub server did not start" -+ subprocess.run([str(work / "fxa-user"), "list"], env=dict(env, FXA_SOCKET=str(socket)), check=True, capture_output=True) -+ print("PASS: RPC uses the build-time default when FXA_TIMEOUT is unset") -+ finally: -+ server.terminate() -+ server.wait(timeout=5) -+ socket.unlink(missing_ok=True) -+ server = subprocess.Popen([str(work / "stub"), str(socket)], env=dict(env, EXPECTED_TIMEOUT="2s")) -+ try: -+ for _ in range(100): -+ if socket.exists(): -+ break -+ assert server.poll() is None, "stub server exited" -+ time.sleep(0.05) -+ assert socket.exists(), "stub server did not start" -+ for command in ["create", "passwd", "delete"]: -+ check_command(work / "fxa-user", socket, command) -+ print("PASS: FXA_TIMEOUT overrides the build-time default") -+ finally: -+ server.terminate() -+ server.wait(timeout=5) ++func TestCLITimeout(t *testing.T) { ++ buildTimeout, err := time.ParseDuration(defaultRPCTimeout) ++ if err != nil || buildTimeout <= 0 { ++ t.Fatalf("invalid build-time default: %q", defaultRPCTimeout) ++ } ++ for _, invalid := range []string{"0s", "-1s", "invalid"} { ++ t.Run(invalid, func(t *testing.T) { ++ output, err := cliCommand(t, invalid, "", "list").CombinedOutput() ++ if err == nil || !bytes.Contains(output, []byte("Invalid RPC timeout")) { ++ t.Fatalf("invalid timeout accepted: %v, %s", err, output) ++ } ++ }) ++ } ++ for _, tc := range []struct { ++ name string ++ value string ++ timeout time.Duration ++ block bool ++ }{ ++ {"default", "", buildTimeout, false}, ++ {"runtime override", "2s", 2 * time.Second, false}, ++ {"deadline enforced", "100ms", 100 * time.Millisecond, true}, ++ } { ++ t.Run(tc.name, func(t *testing.T) { ++ socket := startTimeoutServer(t, timeoutServer{timeout: tc.timeout, block: tc.block}) ++ output, err := cliCommand(t, tc.value, socket, "list").CombinedOutput() ++ if tc.block { ++ if err == nil || !bytes.Contains(output, []byte("DeadlineExceeded")) { ++ t.Fatalf("RPC deadline not enforced: %v, %s", err, output) ++ } ++ } else if err != nil || !bytes.Contains(output, []byte("No users found")) { ++ t.Fatalf("list failed: %v, %s", err, output) ++ } ++ }) ++ } ++}
diff --git a/Unix/minimal-fxa-server/enforce-pkce.patch b/Unix/minimal-fxa-server/enforce-pkce.patch @@ -59,10 +59,10 @@ index cfb8862..49998c3 100644 if err := tx.Delete(&authCode).Error; err != nil { diff --git a/oauth/handler_test.go b/oauth/handler_test.go new file mode 100644 -index 0000000..ed6286a +index 0000000..8b1be2a --- /dev/null +++ b/oauth/handler_test.go -@@ -0,0 +1,156 @@ +@@ -0,0 +1,166 @@ +package oauth + +import ( @@ -212,6 +212,16 @@ index 0000000..ed6286a + if response["access_token"] == nil || remaining != 0 || tokens != 1 { + t.Fatal("valid exchange must issue a token and consume the code") + } ++ replay := httptest.NewRequest(http.MethodPost, endpoint, strings.NewReader(body)) ++ replay.Header.Set("Content-Type", contentType) ++ replayResponse := httptest.NewRecorder() ++ mux.ServeHTTP(replayResponse, replay) ++ if replayResponse.Code != http.StatusBadRequest { ++ t.Fatal("consumed authorization code must not be reusable") ++ } ++ if err := tx.Model(&database.OAuthToken{}).Where("user_id = ?", code.UserID).Count(&tokens).Error; err != nil || tokens != 1 { ++ t.Fatalf("replay issued another token: count=%d, error=%v", tokens, err) ++ } + } else if response["error"] != "invalid_grant" || remaining != 1 || tokens != 0 { + t.Fatal("invalid exchange must preserve the code and issue no tokens") + }
diff --git a/docs/firefox-sync.md b/docs/firefox-sync.md @@ -3,8 +3,8 @@ ## Deployment `Unix/minimal-fxa-server/APKBUILD` packages upstream commit -`8ec5f0d160269f5079431d2b75574337f0552940` as `0_git20260225-r4` -(Debian version `0+git20260225-4`), with: +`8ec5f0d160269f5079431d2b75574337f0552940` as `0_git20260225-r7` +(Debian version `0+git20260225-7`), with: - `enforce-pkce.patch`: 27 production lines enforce S256 PKCE and client-ID binding in both authorization-code exchange endpoints, plus regression tests. @@ -32,6 +32,16 @@ the one-time configuration described below. Previous r2/r3 deployments used APK staging plus copied binaries, not package ownership. The APT installation supersedes that manual-copy upgrade path. +Live verification on 2026-11-22 found `0+git20260225-6` installed and APT-owned, +with clean `dpkg --verify minimal-fxa-server`, the running server matching the +installed binary, all three services active, and `check-syncserver` passing. +The account socket remains private (directory 0700, socket 0600) and the secret +environment file remains root-only (0600). No reinstall or configuration change +was needed. Revision 7 refreshes tests and documentation only; production Go +source is unchanged from revision 6, so it does not require a service restart +for browser testing. Its CLI regression tests now run in ordinary package checks +without Python, and its PostgreSQL tests additionally reject code replay. + The original deployed **r0 tarball** (not replaced merely by publishing an APK) was published by CI for repository revision `0fea439e434b278805ab3aaaa8fd4c39fc5a3ff3`, build key @@ -169,11 +179,40 @@ The patch's unit tests run during package checks. Its PostgreSQL endpoint tests require `FXA_TEST_DATABASE_URI` pointing at a disposable database (never the live Accounts database); each case rolls back its transaction. Run against the patched source with `FXA_TEST_DATABASE_URI='...' go test -race ./oauth`. -The separate CLI regression test uses synthetic responses from a disposable -Unix-socket gRPC stub, not live accounts: -`python3 cmd/fxa-user/tests/prompt_timeout.py`. It checks linker/runtime timeout -overrides and 11-second pauses at create/password/delete prompts; this Python -integration test is a manual release check, not part of the Go-only package checks. +The native Go CLI regression tests use synthetic responses from a disposable +Unix-socket gRPC server, not live accounts: + +```sh +go test -race ./cmd/fxa-user +go test -ldflags='-X main.defaultRPCTimeout=3s' ./cmd/fxa-user +``` + +They check default/runtime timeout selection, invalid values, actual RPC timeout +enforcement, and confirmation delayed longer than the RPC budget. They run in +ordinary Go package checks. Password-prompt terminal interaction remains an +interactive check; the old Python-only helper has been removed from the patch. + +### Owner-run browser acceptance + +Use disposable profiles and non-sensitive test data because the security +limitations above remain. No browser profile or permanent account was changed +as part of the 2026-11-22 verification. + +1. Create your local account with the interactive command above, if needed. +2. Set the two HTTPS preferences above in a fresh Firefox profile and restart. +3. Sign in and trigger Sync. Confirm that the expected engines report success. +4. Configure a second fresh profile/device for the same server and local account. +5. Create a distinctive test bookmark on the first device; manually sync both + and confirm it arrives on the second. Edit/delete it there and check the + reverse direction. Repeat with whichever engines you intend to rely on. +6. Restart Firefox and confirm sign-in and subsequent manual sync still work. + +Do not use send-tab/push delivery as the pass criterion: push is disabled. +If a step fails, record the Firefox version, engine, step, and time, and inspect +`about:sync-log`. Logs can contain identifiers and tokens; redact before sharing. +Real-browser key handling and multi-device sync remain unverified until this +acceptance succeeds. Account recovery, mobile behavior, and full Mozilla network +independence are separate unverified capabilities, not implied by this checklist. Back up all three databases (`minimal_fxa`, `syncstorage_rs`, `tokenserver_rs`) and both secret configuration files before upgrades. Preserve signing/master
: nply/foundationpkgs