mirror of
https://github.com/cloudflare/cloudflared.git
synced 2025-08-03 07:50:14 +00:00

In the rare case that the updater downloads the same binary (validated via checksum) we want to make sure that the updater does not attempt to upgrade and restart the cloudflared process. The binaries are equivalent and this would provide no value. However, we are covering this case because there was an errant deployment of cloudflared that reported itself as an older version and was then stuck in an infinite loop attempting to upgrade to the latest version which didn't exist. By making sure that the binary is different ensures that the upgrade will be attempted and cloudflared will be restarted to run the new version. This change only affects cloudflared tunnels running with default settings or `--no-autoupdate=false` which allows cloudflared to auto-update itself in-place. Most distributions that handle package management at the operating system level are not affected by this change.
47 lines
1.2 KiB
Go
47 lines
1.2 KiB
Go
package updater
|
|
|
|
import (
|
|
"context"
|
|
"flag"
|
|
"testing"
|
|
|
|
"github.com/facebookgo/grace/gracenet"
|
|
"github.com/rs/zerolog"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/urfave/cli/v2"
|
|
|
|
"github.com/cloudflare/cloudflared/cmd/cloudflared/cliutil"
|
|
)
|
|
|
|
func init() {
|
|
Init(cliutil.GetBuildInfo("TEST", "TEST"))
|
|
}
|
|
|
|
func TestDisabledAutoUpdater(t *testing.T) {
|
|
listeners := &gracenet.Net{}
|
|
log := zerolog.Nop()
|
|
autoupdater := NewAutoUpdater(false, 0, listeners, &log)
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
errC := make(chan error)
|
|
go func() {
|
|
errC <- autoupdater.Run(ctx)
|
|
}()
|
|
|
|
assert.False(t, autoupdater.configurable.enabled)
|
|
assert.Equal(t, DefaultCheckUpdateFreq, autoupdater.configurable.freq)
|
|
|
|
cancel()
|
|
// Make sure that autoupdater terminates after canceling the context
|
|
assert.Equal(t, context.Canceled, <-errC)
|
|
}
|
|
|
|
func TestCheckInWithUpdater(t *testing.T) {
|
|
flagSet := flag.NewFlagSet(t.Name(), flag.PanicOnError)
|
|
cliCtx := cli.NewContext(cli.NewApp(), flagSet, nil)
|
|
|
|
warningChecker := StartWarningCheck(cliCtx)
|
|
warning := warningChecker.getWarning()
|
|
// Assuming this runs either on a release or development version, then the Worker will never have anything to tell us.
|
|
assert.Empty(t, warning)
|
|
}
|