test(server): speedup cert key generation in server tests (#4166)

Use shorter key size to speed up cert generation in TestServerStartInsecure.

Refactor: add const for default server-control username.
This commit is contained in:
Julio López
2024-10-10 10:22:34 -07:00
committed by GitHub
parent a848ab98e5
commit eb2ea5dddd
3 changed files with 21 additions and 9 deletions

View File

@@ -42,7 +42,7 @@ type serverClientFlags struct {
}
func (c *serverClientFlags) setup(svc appServices, cmd *kingpin.CmdClause) {
c.serverUsername = "server-control"
c.serverUsername = defaultServerControlUsername
cmd.Flag("address", "Address of the server to connect to").Envar(svc.EnvName("KOPIA_SERVER_ADDRESS")).Default("http://127.0.0.1:51515").StringVar(&c.serverAddress)
cmd.Flag("server-control-username", "Server control username").Envar(svc.EnvName("KOPIA_SERVER_USERNAME")).StringVar(&c.serverUsername)

View File

@@ -24,7 +24,10 @@
"github.com/kopia/kopia/repo"
)
const serverRandomPasswordLength = 32
const (
defaultServerControlUsername = "server-control"
serverRandomPasswordLength = 32
)
type commandServerStart struct {
co connectOptions
@@ -93,7 +96,7 @@ func (c *commandServerStart) setup(svc advancedAppServices, parent commandParent
cmd.Flag("htpasswd-file", "Path to htpasswd file that contains allowed user@hostname entries").Hidden().ExistingFileVar(&c.serverStartHtpasswdFile)
cmd.Flag("random-server-control-password", "Generate random server control password and print to stderr").Hidden().BoolVar(&c.randomServerControlPassword)
cmd.Flag("server-control-username", "Server control username").Default("server-control").Envar(svc.EnvName("KOPIA_SERVER_CONTROL_USER")).StringVar(&c.serverControlUsername)
cmd.Flag("server-control-username", "Server control username").Default(defaultServerControlUsername).Envar(svc.EnvName("KOPIA_SERVER_CONTROL_USER")).StringVar(&c.serverControlUsername)
cmd.Flag("server-control-password", "Server control password").PlaceHolder("PASSWORD").Envar(svc.EnvName("KOPIA_SERVER_CONTROL_PASSWORD")).StringVar(&c.serverControlPassword)
cmd.Flag("auth-cookie-signing-key", "Force particular auth cookie signing key").Envar(svc.EnvName("KOPIA_AUTH_COOKIE_SIGNING_KEY")).Hidden().StringVar(&c.serverAuthCookieSingingKey)

View File

@@ -30,6 +30,8 @@
"github.com/kopia/kopia/tests/testenv"
)
const defaultServerControlUsername = "server-control"
func TestServerStart(t *testing.T) {
ctx := testlogging.Context(t)
@@ -74,7 +76,7 @@ func TestServerStart(t *testing.T) {
controlClient, err := apiclient.NewKopiaAPIClient(apiclient.Options{
BaseURL: sp.BaseURL,
Username: "server-control",
Username: defaultServerControlUsername,
Password: sp.ServerControlPassword,
TrustedServerCertificateFingerprint: sp.SHA256Fingerprint,
LogRequests: true,
@@ -219,7 +221,7 @@ func TestServerStartAsyncRepoConnect(t *testing.T) {
controlClient, err := apiclient.NewKopiaAPIClient(apiclient.Options{
BaseURL: sp.BaseURL,
Username: "server-control",
Username: defaultServerControlUsername,
Password: sp.ServerControlPassword,
TrustedServerCertificateFingerprint: sp.SHA256Fingerprint,
LogRequests: true,
@@ -298,7 +300,7 @@ func TestServerCreateAndConnectViaAPI(t *testing.T) {
controlClient, err := apiclient.NewKopiaAPIClient(apiclient.Options{
BaseURL: sp.BaseURL,
Username: "server-control",
Username: defaultServerControlUsername,
Password: sp.ServerControlPassword,
TrustedServerCertificateFingerprint: sp.SHA256Fingerprint,
LogRequests: true,
@@ -377,7 +379,7 @@ func TestConnectToExistingRepositoryViaAPI(t *testing.T) {
controlClient, err := apiclient.NewKopiaAPIClient(apiclient.Options{
BaseURL: sp.BaseURL,
Username: "server-control",
Username: defaultServerControlUsername,
Password: sp.ServerControlPassword,
TrustedServerCertificateFingerprint: sp.SHA256Fingerprint,
})
@@ -530,8 +532,15 @@ func TestServerStartInsecure(t *testing.T) {
waitUntilServerStarted(ctx, t, cli)
// server fails to start with --without-password when `--insecure` is not specified
e.RunAndExpectFailure(t, "server", "start", "--ui", "--address=localhost:0", "--without-password") // without TLS
e.RunAndExpectFailure(t, "server", "start", "--ui", "--address=localhost:0", "--without-password", "--tls-generate-cert") // with TLS
e.RunAndExpectFailure(t, "server", "start", "--ui", "--address=localhost:0", "--without-password") // without TLS
// with TLS
e.RunAndExpectFailure(t, "server", "start", "--ui",
"--address=localhost:0",
"--without-password",
"--tls-generate-cert",
"--tls-generate-rsa-key-size=2048", // use shorter key size to speed up generation,
)
// server fails to start when TLS is not configured and `--insecure` is not specified
e.RunAndExpectFailure(t, "server", "start", "--ui", "--address=localhost:0")