Add integration with 5ab1cb61a36576623a318bafea1fef72c74fab6c so that we only serve binaries for updates if they have passed validation

This commit is contained in:
David Dworken 2023-11-08 20:08:42 -08:00
parent 73b1a76390
commit e0f629d0ee
No known key found for this signature in database
2 changed files with 18 additions and 8 deletions

View File

@ -5,7 +5,6 @@ import (
"fmt" "fmt"
"io" "io"
"net/http" "net/http"
"strconv"
"strings" "strings"
"github.com/ddworken/hishtory/shared" "github.com/ddworken/hishtory/shared"
@ -101,6 +100,14 @@ func assertValidUpdate(updateInfo shared.UpdateInfo) error {
updateInfo.DarwinArm64UnsignedUrl, updateInfo.DarwinArm64UnsignedUrl,
updateInfo.DarwinArm64AttestationUrl, updateInfo.DarwinArm64AttestationUrl,
} }
// TODO: Delete this version checking logic once v0.251 has been released
pv, err := shared.ParseVersionString(updateInfo.Version)
if err != nil {
return fmt.Errorf("failed to parse version string: %w", err)
}
if pv.GreaterThan(shared.ParsedVersion{MajorVersion: 0, MinorVersion: 246}) {
urls = append(urls, fmt.Sprintf("https://github.com/ddworken/hishtory/releases/download/%s/hishtory-release-validation-completed", updateInfo.Version))
}
for _, url := range urls { for _, url := range urls {
resp, err := http.Get(url) resp, err := http.Get(url)
if err != nil { if err != nil {
@ -118,13 +125,9 @@ func decrementVersion(version string) (string, error) {
if version == "UNKNOWN" { if version == "UNKNOWN" {
return "", fmt.Errorf("cannot decrement UNKNOWN") return "", fmt.Errorf("cannot decrement UNKNOWN")
} }
parts := strings.Split(version, ".") pv, err := shared.ParseVersionString(version)
if len(parts) != 2 {
return "", fmt.Errorf("invalid version: %s", version)
}
versionNumber, err := strconv.Atoi(parts[1])
if err != nil { if err != nil {
return "", fmt.Errorf("invalid version: %s", version) return "", fmt.Errorf("failed to parse version %#v to decrement it: %w", version, err)
} }
return parts[0] + "." + strconv.Itoa(versionNumber-1), nil return pv.Decrement().String(), nil
} }

View File

@ -5,6 +5,7 @@ import (
"testing" "testing"
"github.com/ddworken/hishtory/shared/testutils" "github.com/ddworken/hishtory/shared/testutils"
"github.com/stretchr/testify/require"
) )
func TestUpdateReleaseVersion(t *testing.T) { func TestUpdateReleaseVersion(t *testing.T) {
@ -32,3 +33,9 @@ func TestUpdateReleaseVersion(t *testing.T) {
t.Fatalf("ReleaseVersion wasn't updated to contain a version: %#v", Version) t.Fatalf("ReleaseVersion wasn't updated to contain a version: %#v", Version)
} }
} }
func TestDecrement(t *testing.T) {
pv, err := decrementVersion("v0.100")
require.NoError(t, err)
require.Equal(t, "v0.99", pv)
}