Recognize local app states (T-202)
This commit is contained in:
@@ -13,6 +13,8 @@ import (
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"softbox.local/core/domain"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -23,7 +25,6 @@ var (
|
||||
|
||||
var (
|
||||
appIDPattern = regexp.MustCompile(`^[a-z0-9-]+$`)
|
||||
semVerPattern = regexp.MustCompile(`^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?(\+[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$`)
|
||||
sha256Pattern = regexp.MustCompile(`^[0-9A-Fa-f]{64}$`)
|
||||
iconRefPattern = regexp.MustCompile(`^sha256:[0-9A-Fa-f]{64}$`)
|
||||
)
|
||||
@@ -97,7 +98,7 @@ func validateManifest(manifest Manifest, expectedChannel ManifestChannel) error
|
||||
if err != nil || offset != 0 {
|
||||
return invalidField("generated_at", "must be an RFC3339 UTC timestamp")
|
||||
}
|
||||
if !semVerPattern.MatchString(manifest.MinBoxVersion) {
|
||||
if _, err := domain.ParseSemVer(manifest.MinBoxVersion); err != nil {
|
||||
return invalidField("min_box_version", "must be SemVer")
|
||||
}
|
||||
if err := validateSignature(manifest.Signature); err != nil {
|
||||
@@ -127,7 +128,7 @@ func validateApp(app App) error {
|
||||
if strings.TrimSpace(app.Description) == "" {
|
||||
return invalidField("description", "must not be empty")
|
||||
}
|
||||
if !semVerPattern.MatchString(app.Version) {
|
||||
if _, err := domain.ParseSemVer(app.Version); err != nil {
|
||||
return invalidField("version", "must be SemVer")
|
||||
}
|
||||
if app.Channel != ReleaseStable {
|
||||
|
||||
@@ -8,7 +8,11 @@ import (
|
||||
)
|
||||
|
||||
func TestProtocolSchemasAreValidJSONObjects(t *testing.T) {
|
||||
for _, name := range []string{"manifest.schema.json", "app.schema.json"} {
|
||||
for _, name := range []string{
|
||||
"manifest.schema.json",
|
||||
"app.schema.json",
|
||||
"installed-app.schema.json",
|
||||
} {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
document, err := os.ReadFile(filepath.Join("..", "..", "schemas", name))
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user