Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ linters:
- path: internal\/ci\/*
linters:
- forbidigo
- path: internal\/validation\/*
linters:
- forbidigo

formatters:
enable:
Expand Down
5 changes: 3 additions & 2 deletions cmd/extension/extension_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

"github.com/shopware/shopware-cli/extension"
"github.com/shopware/shopware-cli/internal/system"
"github.com/shopware/shopware-cli/internal/validation"
"github.com/shopware/shopware-cli/internal/verifier"
"github.com/shopware/shopware-cli/logging"
)
Expand All @@ -32,7 +33,7 @@ var extensionValidateCmd = &cobra.Command{
}

if reportingFormat == "" {
reportingFormat = verifier.DetectDefaultReporter()
reportingFormat = validation.DetectDefaultReporter()
}

if err != nil {
Expand Down Expand Up @@ -117,7 +118,7 @@ var extensionValidateCmd = &cobra.Command{
return err
}

return verifier.DoCheckReport(result.RemoveByIdentifier(toolCfg.ValidationIgnores), reportingFormat)
return validation.DoCheckReport(result.RemoveByIdentifier(toolCfg.ValidationIgnores), reportingFormat)
},
}

Expand Down
3 changes: 2 additions & 1 deletion cmd/extension/extension_zip.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/spf13/cobra"

"github.com/shopware/shopware-cli/extension"
"github.com/shopware/shopware-cli/internal/validation"
"github.com/shopware/shopware-cli/logging"
)

Expand Down Expand Up @@ -151,7 +152,7 @@ var extensionZipCmd = &cobra.Command{
}

if cmd.Flags().Changed("overwrite-app-backend-secret") {
extCfg.Validation.Ignore = append(extCfg.Validation.Ignore, extension.ConfigValidationIgnoreItem{Identifier: "metadata.setup"})
extCfg.Validation.Ignore = append(extCfg.Validation.Ignore, validation.ToolConfigIgnore{Identifier: "metadata.setup"})
if err := extCfg.Dump(extDir); err != nil {
return fmt.Errorf("dump extension config: %w", err)
}
Expand Down
7 changes: 5 additions & 2 deletions cmd/project/project_validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"golang.org/x/sync/errgroup"

"github.com/shopware/shopware-cli/internal/system"
"github.com/shopware/shopware-cli/internal/validation"
"github.com/shopware/shopware-cli/internal/verifier"
"github.com/shopware/shopware-cli/logging"
)
Expand Down Expand Up @@ -45,7 +46,7 @@ var projectValidateCmd = &cobra.Command{
}

if reportingFormat == "" {
reportingFormat = verifier.DetectDefaultReporter()
reportingFormat = validation.DetectDefaultReporter()
}

if !noCopy {
Expand Down Expand Up @@ -89,7 +90,9 @@ var projectValidateCmd = &cobra.Command{
return err
}

return verifier.DoCheckReport(result.RemoveByIdentifier(toolCfg.ValidationIgnores), reportingFormat)
filtered := result.RemoveByIdentifier(toolCfg.ValidationIgnores)

return validation.DoCheckReport(filtered, reportingFormat)
},
}

Expand Down
50 changes: 41 additions & 9 deletions extension/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"strings"

"github.com/shyim/go-version"

"github.com/shopware/shopware-cli/internal/validation"
)

type App struct {
Expand Down Expand Up @@ -150,38 +152,68 @@ func (a App) GetMetaData() *extensionMetadata {
}
}

func (a App) Validate(_ context.Context, ctx *ValidationContext) {
validateTheme(ctx)
func (a App) Validate(_ context.Context, check validation.Check) {
validateTheme(a, check)

validateExtensionIcon(ctx)
validateExtensionIcon(a, check)

allowedTwigLocations := []string{filepath.Join(a.GetRootDir(), "Resources", "views"), filepath.Join(a.GetRootDir(), "Resources", "scripts")}

_ = filepath.Walk(a.GetRootDir(), func(path string, info os.FileInfo, err error) error {
if filepath.Ext(path) == ".php" {
ctx.AddError("zip.disallowed_php_file", fmt.Sprintf("Found unexpected PHP file %s, PHP files are not allowed in Apps", path))
check.AddResult(validation.CheckResult{
Path: path,
Identifier: "zip.disallowed_php_file",
Message: fmt.Sprintf("Found unexpected PHP file %s, PHP files are not allowed in Apps", path),
Severity: validation.SeverityError,
})
}

if filepath.Ext(path) == ".twig" && (!strings.HasPrefix(path, allowedTwigLocations[0]) && !strings.HasPrefix(path, allowedTwigLocations[1])) {
ctx.AddError("zip.disallowed_twig_file", fmt.Sprintf("Found unexpected Twig file %s. Twig files should be at Resources/views or Resources/scripts", path))
check.AddResult(validation.CheckResult{
Path: path,
Identifier: "zip.disallowed_twig_file",
Message: fmt.Sprintf("Found unexpected Twig file %s. Twig files should be at Resources/views or Resources/scripts", path),
Severity: validation.SeverityError,
})
}

return nil
})

if a.manifest.Meta.Author == "" {
ctx.AddError("metadata.author", "The element meta:author was not found in the manifest.xml")
check.AddResult(validation.CheckResult{
Path: "manifest.xml",
Identifier: "metadata.author",
Message: "The element meta:author was not found in the manifest.xml",
Severity: validation.SeverityError,
})
}

if a.manifest.Meta.Copyright == "" {
ctx.AddError("metadata.copyright", "The element meta:copyright was not found in the manifest.xml")
check.AddResult(validation.CheckResult{
Path: "manifest.xml",
Identifier: "metadata.copyright",
Message: "The element meta:copyright was not found in the manifest.xml",
Severity: validation.SeverityError,
})
}

if a.manifest.Meta.License == "" {
ctx.AddError("metadata.license", "The element meta:license was not found in the manifest.xml")
check.AddResult(validation.CheckResult{
Path: "manifest.xml",
Identifier: "metadata.license",
Message: "The element meta:license was not found in the manifest.xml",
Severity: validation.SeverityError,
})
}

if a.manifest.Setup != nil && a.manifest.Setup.Secret != "" {
ctx.AddError("metadata.setup", "The xml element setup:secret is only for local development, please remove it. You can find your generated app secret on your extension detail page in the master data section. For more information see https://docs.shopware.com/en/shopware-platform-dev-en/app-system-guide/setup#authorisation")
check.AddResult(validation.CheckResult{
Path: "manifest.xml",
Identifier: "metadata.setup",
Message: "The xml element setup:secret is only for local development, please remove it. You can find your generated app secret on your extension detail page in the master data section. For more information see https://docs.shopware.com/en/shopware-platform-dev-en/app-system-guide/setup#authorisation",
Severity: validation.SeverityError,
})
}
}
68 changes: 34 additions & 34 deletions extension/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,11 @@ func TestIconNotExists(t *testing.T) {
assert.Equal(t, "MyExampleApp", app.manifest.Meta.Name)
assert.Equal(t, "", app.manifest.Meta.Icon)

ctx := newValidationContext(app)
app.Validate(getTestContext(), ctx)
check := &testCheck{}
app.Validate(getTestContext(), check)

assert.Equal(t, 1, len(ctx.errors))
assert.Equal(t, "The extension icon Resources/config/plugin.png does not exist", ctx.errors[0].Message)
assert.Equal(t, 1, len(check.Results))
assert.Equal(t, "The extension icon Resources/config/plugin.png does not exist", check.Results[0].Message)
}

func TestAppNoLicense(t *testing.T) {
Expand All @@ -147,11 +147,11 @@ func TestAppNoLicense(t *testing.T) {

assert.NoError(t, err)

ctx := newValidationContext(app)
app.Validate(getTestContext(), ctx)
check := &testCheck{}
app.Validate(getTestContext(), check)

assert.Equal(t, 1, len(ctx.errors))
assert.Equal(t, "The element meta:license was not found in the manifest.xml", ctx.errors[0].Message)
assert.Equal(t, 1, len(check.Results))
assert.Equal(t, "The element meta:license was not found in the manifest.xml", check.Results[0].Message)
}

func TestAppNoCopyright(t *testing.T) {
Expand All @@ -165,11 +165,11 @@ func TestAppNoCopyright(t *testing.T) {

assert.NoError(t, err)

ctx := newValidationContext(app)
app.Validate(getTestContext(), ctx)
check := &testCheck{}
app.Validate(getTestContext(), check)

assert.Equal(t, 1, len(ctx.errors))
assert.Equal(t, "The element meta:copyright was not found in the manifest.xml", ctx.errors[0].Message)
assert.Equal(t, 1, len(check.Results))
assert.Equal(t, "The element meta:copyright was not found in the manifest.xml", check.Results[0].Message)
}

func TestAppNoAuthor(t *testing.T) {
Expand All @@ -183,11 +183,11 @@ func TestAppNoAuthor(t *testing.T) {

assert.NoError(t, err)

ctx := newValidationContext(app)
app.Validate(getTestContext(), ctx)
check := &testCheck{}
app.Validate(getTestContext(), check)

assert.Equal(t, 1, len(ctx.errors))
assert.Equal(t, "The element meta:author was not found in the manifest.xml", ctx.errors[0].Message)
assert.Equal(t, 1, len(check.Results))
assert.Equal(t, "The element meta:author was not found in the manifest.xml", check.Results[0].Message)
}

func TestAppHasSecret(t *testing.T) {
Expand All @@ -201,11 +201,11 @@ func TestAppHasSecret(t *testing.T) {

assert.NoError(t, err)

ctx := newValidationContext(app)
app.Validate(getTestContext(), ctx)
check := &testCheck{}
app.Validate(getTestContext(), check)

assert.Equal(t, 1, len(ctx.errors))
assert.Equal(t, "The xml element setup:secret is only for local development, please remove it. You can find your generated app secret on your extension detail page in the master data section. For more information see https://docs.shopware.com/en/shopware-platform-dev-en/app-system-guide/setup#authorisation", ctx.errors[0].Message)
assert.Equal(t, 1, len(check.Results))
assert.Equal(t, "The xml element setup:secret is only for local development, please remove it. You can find your generated app secret on your extension detail page in the master data section. For more information see https://docs.shopware.com/en/shopware-platform-dev-en/app-system-guide/setup#authorisation", check.Results[0].Message)
}

func TestIconExistsDefaultsPath(t *testing.T) {
Expand All @@ -223,10 +223,10 @@ func TestIconExistsDefaultsPath(t *testing.T) {
assert.Equal(t, "MyExampleApp", app.manifest.Meta.Name)
assert.Equal(t, "", app.manifest.Meta.Icon)

ctx := newValidationContext(app)
app.Validate(getTestContext(), ctx)
check := &testCheck{}
app.Validate(getTestContext(), check)

assert.Equal(t, 0, len(ctx.errors))
assert.Equal(t, 0, len(check.Results))
}

func TestIconExistsDifferentPath(t *testing.T) {
Expand All @@ -242,10 +242,10 @@ func TestIconExistsDifferentPath(t *testing.T) {
assert.Equal(t, "MyExampleApp", app.manifest.Meta.Name)
assert.Equal(t, "app.png", app.manifest.Meta.Icon)

ctx := newValidationContext(app)
app.Validate(getTestContext(), ctx)
check := &testCheck{}
app.Validate(getTestContext(), check)

assert.Equal(t, 0, len(ctx.errors))
assert.Equal(t, 0, len(check.Results))
}

func TestNoCompatibilityGiven(t *testing.T) {
Expand Down Expand Up @@ -291,11 +291,11 @@ func TestAppWithPHPFiles(t *testing.T) {

assert.NoError(t, err)

ctx := newValidationContext(app)
app.Validate(getTestContext(), ctx)
check := &testCheck{}
app.Validate(getTestContext(), check)

assert.Equal(t, 1, len(ctx.errors))
assert.Contains(t, ctx.errors[0].Message, "Found unexpected PHP file")
assert.Equal(t, 1, len(check.Results))
assert.Contains(t, check.Results[0].Message, "Found unexpected PHP file")
}

func TestAppWithTwigFiles(t *testing.T) {
Expand All @@ -317,9 +317,9 @@ func TestAppWithTwigFiles(t *testing.T) {

assert.NoError(t, err)

ctx := newValidationContext(app)
app.Validate(getTestContext(), ctx)
check := &testCheck{}
app.Validate(getTestContext(), check)

assert.Equal(t, 1, len(ctx.errors))
assert.Contains(t, ctx.errors[0].Message, "Twig files should be at")
assert.Equal(t, 1, len(check.Results))
assert.Contains(t, check.Results[0].Message, "Twig files should be at")
}
5 changes: 4 additions & 1 deletion extension/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"path"

"github.com/shyim/go-version"

"github.com/shopware/shopware-cli/internal/validation"
)

type ShopwareBundle struct {
Expand Down Expand Up @@ -177,5 +179,6 @@ func (p ShopwareBundle) GetMetaData() *extensionMetadata {
}
}

func (p ShopwareBundle) Validate(c context.Context, ctx *ValidationContext) {
func (p ShopwareBundle) Validate(c context.Context, check validation.Check) {
// ShopwareBundle validation is currently empty but signature updated to match interface
}
4 changes: 2 additions & 2 deletions extension/bundle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ func TestCreateBundle(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, "1.0.0", version.String())

// does notthing
bundle.Validate(getTestContext(), &ValidationContext{})
// does nothing
bundle.Validate(getTestContext(), &testCheck{})

assert.Equal(t, "FALLBACK", bundle.GetMetaData().Description.German)
}
Loading