Files
mattermost/tools/sharedchannel-test/main.go
T
Jesse HallamandClaude 71ca373de7 Generate instead of hard-coding test passwords, enforce new minimum for FIPS, shard CI, fix FIPS builds (#35905)
* Replace hardcoded test passwords with model.NewTestPassword()

Add model.NewTestPassword() utility that generates 14+ character
passwords meeting complexity requirements for FIPS compliance. Replace
all short hardcoded test passwords across the test suite with calls to
this function.

* Enforce FIPS compliance for passwords and HMAC keys

FIPS OpenSSL requires HMAC keys to be at least 14 bytes. PBKDF2 uses
the password as the HMAC key internally, so short passwords cause
PKCS5_PBKDF2_HMAC to fail.

- Add FIPSEnabled and PasswordFIPSMinimumLength build-tag constants
- Raise the password minimum length floor to 14 when compiled with
  requirefips, applied in SetDefaults only when unset and validated
  independently in IsValid
- Return ErrMismatchedHashAndPassword for too-short passwords in
  PBKDF2 CompareHashAndPassword rather than a cryptic OpenSSL error
- Validate atmos/camo HMAC key length under FIPS and lengthen test
  keys accordingly
- Adjust password validation tests to use PasswordFIPSMinimumLength
  so they work under both FIPS and non-FIPS builds

* CI: shard FIPS test suite and extract merge template

Run FIPS tests on PRs that touch go.mod or have 'fips' in the branch
name. Shard FIPS tests across 4 runners matching the normal Postgres
suite. Extract the test result merge logic into a reusable workflow
template to deduplicate the normal and FIPS merge jobs.

* more

* Fix email test helper to respect FIPS minimum password length

* Fix test helpers to respect FIPS minimum password length

* Remove unnecessary "disable strict password requirements" blocks from test helpers

* Fix CodeRabbit review comments on PR #35905

- Add server-test-merge-template.yml to server-ci.yml pull_request.paths
  so changes to the reusable merge workflow trigger Server CI validation
- Skip merge-postgres-fips-test-results job when test-postgres-normal-fips
  was skipped, preventing failures due to missing artifacts
- Set guest.Password on returned guest in CreateGuestAndClient helper
  to keep contract consistent with CreateUserWithClient
- Use shared LowercaseLetters/UppercaseLetters/NUMBERS/PasswordFIPSMinimumLength
  constants in NewTestPassword() to avoid drift if FIPS floor changes

https://claude.ai/code/session_01HmE9QkZM3cAoXn2J7XrK2f

* Rename FIPS test artifact to match server-ci-report pattern

The server-ci-report job searches for artifacts matching "*-test-logs",
so rename from postgres-server-test-logs-fips to
postgres-server-fips-test-logs to be included in the report.

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-04-08 16:49:43 -03:00

118 lines
3.3 KiB
Go

// sharedchannel-test is an integration test tool that validates shared channel
// synchronization between two real Mattermost server instances.
//
// It can either manage the server lifecycle itself (build, start, stop) or
// connect to already-running instances.
//
// Usage:
//
// go run . --license /path/to/license.mattermost-license
// go run . --server-a http://already:9065 --server-b http://running:9066 --manage=false
package main
import (
"context"
"encoding/json"
"flag"
"fmt"
"os"
"os/signal"
"syscall"
"github.com/mattermost/mattermost/server/public/shared/mlog"
)
type Config struct {
ServerAURL string
ServerBURL string
LicensePath string
ServerDir string
Manage bool
AdminUser string
AdminPass string
}
func main() {
cfg := Config{}
flag.StringVar(&cfg.ServerAURL, "server-a", "http://localhost:9065", "Server A URL")
flag.StringVar(&cfg.ServerBURL, "server-b", "http://localhost:9066", "Server B URL")
flag.StringVar(&cfg.LicensePath, "license", "", "Path to enterprise license file (required)")
flag.StringVar(&cfg.ServerDir, "server-dir", "", "Path to server directory (for managed mode)")
flag.BoolVar(&cfg.Manage, "manage", true, "Manage server lifecycle (build/start/stop)")
flag.StringVar(&cfg.AdminUser, "admin-user", "admin", "Admin username to create")
flag.StringVar(&cfg.AdminPass, "admin-pass", "Admin1234567890", "Admin password")
flag.Parse()
if cfg.LicensePath == "" {
fmt.Fprintln(os.Stderr, "error: --license is required")
flag.Usage()
os.Exit(1)
}
logger, err := newLogger()
if err != nil {
fmt.Fprintf(os.Stderr, "error creating logger: %v\n", err)
os.Exit(1)
}
defer logger.Flush()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
sigCh := make(chan os.Signal, 1)
signal.Notify(sigCh, syscall.SIGINT, syscall.SIGTERM)
go func() {
<-sigCh
logger.Info("Received signal, shutting down...")
cancel()
}()
runner := NewTestRunner(cfg, logger)
if err := runner.Run(ctx); err != nil {
logger.Error("Test run failed", mlog.Err(err))
logger.Flush()
os.Exit(1)
}
}
// newLogger creates an mlog.Logger with two console targets:
// - stdout: info, warn, and debug (progress messages, PASS results)
// - stderr: error, fatal, panic (FAIL results, fatal errors)
//
// Both use the plain formatter with color enabled so level names
// are visually distinct (cyan=info, yellow=warn, red=error).
func newLogger() (*mlog.Logger, error) {
logger, err := mlog.NewLogger()
if err != nil {
return nil, err
}
formatOpts := json.RawMessage(`{"enable_color": true, "enable_caller": false}`)
logCfg := mlog.LoggerConfiguration{
"stdout": mlog.TargetCfg{
Type: "console",
Format: "plain",
Levels: []mlog.Level{mlog.LvlInfo, mlog.LvlWarn, mlog.LvlDebug},
Options: json.RawMessage(`{"out": "stdout"}`),
FormatOptions: formatOpts,
MaxQueueSize: 1000,
},
"stderr": mlog.TargetCfg{
Type: "console",
Format: "plain",
Levels: []mlog.Level{mlog.LvlError, mlog.LvlFatal, mlog.LvlPanic},
Options: json.RawMessage(`{"out": "stderr"}`),
FormatOptions: formatOpts,
MaxQueueSize: 1000,
},
}
if err := logger.ConfigureTargets(logCfg, nil); err != nil {
return nil, fmt.Errorf("configure log targets: %w", err)
}
return logger, nil
}