feat(BRIDGE-309): Update to the bridge updater logic corresponding to the version file restructure

This commit is contained in:
Atanas Janeshliev
2025-01-21 12:34:04 +01:00
parent d711d9f562
commit da0f51ce5f
26 changed files with 2291 additions and 127 deletions

View File

@ -36,6 +36,8 @@ type API interface {
GetDomain() string
GetAppVersion() string
PushFeatureFlag(string)
Close()
}
@ -61,6 +63,10 @@ func (api *fakeAPI) GetAppVersion() string {
return proton.DefaultAppVersion
}
func (api *fakeAPI) PushFeatureFlag(flagName string) {
api.Server.PushFeatureFlag(flagName)
}
type liveAPI struct {
*server.Server

View File

@ -32,6 +32,7 @@ import (
"github.com/ProtonMail/proton-bridge/v3/internal/bridge"
"github.com/ProtonMail/proton-bridge/v3/internal/events"
"github.com/ProtonMail/proton-bridge/v3/internal/kb"
"github.com/ProtonMail/proton-bridge/v3/internal/unleash"
"github.com/ProtonMail/proton-bridge/v3/internal/vault"
"github.com/cucumber/godog"
"github.com/golang/mock/gomock"
@ -55,7 +56,7 @@ func (s *scenario) bridgeStops() error {
func (s *scenario) bridgeVersionIsAndTheLatestAvailableVersionIsReachableFrom(current, latest, minAuto string) error {
s.t.version = semver.MustParse(current)
s.t.mocks.Updater.SetLatestVersion(semver.MustParse(latest), semver.MustParse(minAuto))
s.t.mocks.Updater.SetLatestVersionLegacy(semver.MustParse(latest), semver.MustParse(minAuto))
return nil
}
@ -361,8 +362,8 @@ func (s *scenario) bridgeSendsAnUpdateAvailableEventForVersion(version string) e
return errors.New("expected update event to be installable")
}
if !event.Version.Version.Equal(semver.MustParse(version)) {
return fmt.Errorf("expected update event for version %s, got %s", version, event.Version.Version)
if !event.VersionLegacy.Version.Equal(semver.MustParse(version)) {
return fmt.Errorf("expected update event for version %s, got %s", version, event.VersionLegacy.Version)
}
return nil
@ -378,8 +379,8 @@ func (s *scenario) bridgeSendsAManualUpdateEventForVersion(version string) error
return errors.New("expected update event to not be installable")
}
if !event.Version.Version.Equal(semver.MustParse(version)) {
return fmt.Errorf("expected update event for version %s, got %s", version, event.Version.Version)
if !event.VersionLegacy.Version.Equal(semver.MustParse(version)) {
return fmt.Errorf("expected update event for version %s, got %s", version, event.VersionLegacy.Version)
}
return nil
@ -391,8 +392,8 @@ func (s *scenario) bridgeSendsAnUpdateInstalledEventForVersion(version string) e
return errors.New("expected update installed event, got none")
}
if !event.Version.Version.Equal(semver.MustParse(version)) {
return fmt.Errorf("expected update installed event for version %s, got %s", version, event.Version.Version)
if !event.VersionLegacy.Version.Equal(semver.MustParse(version)) {
return fmt.Errorf("expected update installed event for version %s, got %s", version, event.VersionLegacy.Version)
}
return nil
@ -483,3 +484,25 @@ func (s *scenario) bridgeSMTPPortIs(expectedPort int) error {
return nil
}
func (s *scenario) bridgeLegacyUpdateKillSwitchEnabled() error {
unleash.ModifyPollPeriodAndJitter(5*time.Second, 0)
s.t.api.PushFeatureFlag(unleash.UpdateUseNewVersionFileStructureDisabled)
return nil
}
func (s *scenario) bridgeLegacyUpdateEnabled() error {
return eventually(func() error {
res := s.t.bridge.GetFeatureFlagValue(unleash.UpdateUseNewVersionFileStructureDisabled)
fmt.Println("RES", res)
if res != true {
return fmt.Errorf("expected the %v kill-switch to be enabled", unleash.UpdateUseNewVersionFileStructureDisabled)
}
return nil
})
}
func (s *scenario) bridgeChecksForUpdates() error {
s.t.bridge.CheckForUpdates()
return nil
}

View File

@ -1,23 +1,34 @@
Feature: Bridge checks for updates
Background:
Given the legacy update kill switch is enabled
Scenario: Update not available
Given bridge is version "2.3.0" and the latest available version is "2.3.0" reachable from "2.3.0"
When bridge starts
And bridge verifies that the legacy update is enabled
And bridge checks for updates
Then bridge sends an update not available event
Scenario: Update available without automatic updates enabled
Given bridge is version "2.3.0" and the latest available version is "2.4.0" reachable from "2.3.0"
And the user has disabled automatic updates
When bridge starts
And bridge verifies that the legacy update is enabled
And bridge checks for updates
Then bridge sends an update available event for version "2.4.0"
Scenario: Update available with automatic updates enabled
Given bridge is version "2.3.0" and the latest available version is "2.4.0" reachable from "2.3.0"
When bridge starts
And bridge verifies that the legacy update is enabled
And bridge checks for updates
Then bridge sends an update installed event for version "2.4.0"
Scenario: Manual update available with automatic updates enabled
Given bridge is version "2.3.0" and the latest available version is "2.4.0" reachable from "2.4.0"
When bridge starts
And bridge verifies that the legacy update is enabled
And bridge checks for updates
Then bridge sends a manual update event for version "2.4.0"
Scenario: Update is required to continue using bridge

View File

@ -99,6 +99,9 @@ func (s *scenario) steps(ctx *godog.ScenarioContext) {
ctx.Step(`^bridge reports a message with "([^"]*)"$`, s.bridgeReportsMessage)
ctx.Step(`^bridge telemetry feature is enabled$`, s.bridgeTelemetryFeatureEnabled)
ctx.Step(`^bridge telemetry feature is disabled$`, s.bridgeTelemetryFeatureDisabled)
ctx.Step(`^the legacy update kill switch is enabled$`, s.bridgeLegacyUpdateKillSwitchEnabled)
ctx.Step(`^bridge verifies that the legacy update is enabled$`, s.bridgeLegacyUpdateEnabled)
ctx.Step(`^bridge checks for updates$`, s.bridgeChecksForUpdates)
// ==== FRONTEND ====
ctx.Step(`^frontend sees that bridge is version "([^"]*)"$`, s.frontendSeesThatBridgeIsVersion)