From de8fc6dd570e0c12101a211f6031d7110d6ee14f Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Mon, 15 Jul 2024 20:37:59 +0200 Subject: [PATCH] fix(services): prevent app name with number (#4249) * fix(services): prevent app name with number * changelog * updates --------- Co-authored-by: Danilo Pantani --- changelog.md | 1 + ignite/services/scaffolder/init.go | 8 ++++++++ integration/app/cmd_app_test.go | 18 ++++++++++++++++++ integration/chain/cmd_serve_test.go | 8 ++++---- integration/ibc/cmd_ibc_test.go | 2 +- 5 files changed, 32 insertions(+), 5 deletions(-) diff --git a/changelog.md b/changelog.md index 2dd6eb7a3f..f3eb606c0b 100644 --- a/changelog.md +++ b/changelog.md @@ -46,6 +46,7 @@ - [#4194](https://github.com/ignite/cli/pull/4194) Bump client/v2 to `v2.0.0-beta.2` - [#4189](https://github.com/ignite/cli/pull/4189) Deprecate `ignite node` for `ignite connect` app - [#4210](https://github.com/ignite/cli/pull/4210) Improve default home wiring +- [#4249](https://github.com/ignite/cli/pull/4249) Prevent creating a chain with number in the name - [#4253](https://github.com/ignite/cli/pull/4253) Bump cosmos-sdk to `v0.50.8` ### Fixes diff --git a/ignite/services/scaffolder/init.go b/ignite/services/scaffolder/init.go index 76270b6da9..66aca0aae9 100644 --- a/ignite/services/scaffolder/init.go +++ b/ignite/services/scaffolder/init.go @@ -7,6 +7,7 @@ import ( "strings" "github.com/ignite/cli/v29/ignite/pkg/cosmosgen" + "github.com/ignite/cli/v29/ignite/pkg/errors" "github.com/ignite/cli/v29/ignite/pkg/gomodulepath" "github.com/ignite/cli/v29/ignite/pkg/xgenny" "github.com/ignite/cli/v29/ignite/templates/app" @@ -28,6 +29,13 @@ func Init( return "", "", err } + // Check if the module name is valid (no numbers) + for _, r := range pathInfo.Package { + if r >= '0' && r <= '9' { + return "", "", errors.Errorf("invalid app name %s: cannot contain numbers", pathInfo.Package) + } + } + // Create a new folder named as the blockchain when a custom path is not specified var appFolder string if root == "" { diff --git a/integration/app/cmd_app_test.go b/integration/app/cmd_app_test.go index d576f32e1e..401f770f4e 100644 --- a/integration/app/cmd_app_test.go +++ b/integration/app/cmd_app_test.go @@ -3,6 +3,7 @@ package app_test import ( + "bytes" "os" "path/filepath" "testing" @@ -52,6 +53,23 @@ func TestGenerateAnAppWithName(t *testing.T) { app.EnsureSteady() } +// TestGenerateAnAppWithInvalidName tests scaffolding a new chain using an invalid name. +func TestGenerateAnAppWithInvalidName(t *testing.T) { + buf := new(bytes.Buffer) + + env := envtest.New(t) + env.Must(env.Exec("should prevent creating an app with an invalid name", + step.NewSteps(step.New( + step.Exec(envtest.IgniteApp, "s", "chain", "blog2"), + step.Stdout(buf), + step.Stderr(buf), + )), + envtest.ExecShouldError(), + )) + + require.Contains(t, buf.String(), "Invalid app name blog2: cannot contain numbers") +} + func TestGenerateAnAppWithNoDefaultModule(t *testing.T) { var ( env = envtest.New(t) diff --git a/integration/chain/cmd_serve_test.go b/integration/chain/cmd_serve_test.go index dd14f506fe..ba5b7e16e3 100644 --- a/integration/chain/cmd_serve_test.go +++ b/integration/chain/cmd_serve_test.go @@ -16,7 +16,7 @@ import ( func TestServeWithCustomHome(t *testing.T) { var ( env = envtest.New(t) - app = env.Scaffold("github.com/test/sgblog2") + app = env.Scaffold("github.com/test/sgbloga") servers = app.RandomizeServerPorts() ) @@ -36,7 +36,7 @@ func TestServeWithCustomHome(t *testing.T) { func TestServeWithConfigHome(t *testing.T) { var ( env = envtest.New(t) - app = env.Scaffold("github.com/test/sgblog3") + app = env.Scaffold("github.com/test/sgblogb") servers = app.RandomizeServerPorts() ) @@ -58,7 +58,7 @@ func TestServeWithCustomConfigFile(t *testing.T) { var ( env = envtest.New(t) - app = env.Scaffold("github.com/test/sgblog4") + app = env.Scaffold("github.com/test/sgblogc") ) // Move config newConfig := "new_config.yml" @@ -86,7 +86,7 @@ func TestServeWithCustomConfigFile(t *testing.T) { func TestServeWithName(t *testing.T) { var ( env = envtest.New(t) - app = env.Scaffold("sgblog5") + app = env.Scaffold("sgblogd") servers = app.RandomizeServerPorts() ) diff --git a/integration/ibc/cmd_ibc_test.go b/integration/ibc/cmd_ibc_test.go index c749797f92..f83be26617 100644 --- a/integration/ibc/cmd_ibc_test.go +++ b/integration/ibc/cmd_ibc_test.go @@ -109,7 +109,7 @@ func TestCreateModuleWithIBC(t *testing.T) { func TestCreateIBCPacket(t *testing.T) { var ( env = envtest.New(t) - app = env.Scaffold("github.com/test/blogibc2") + app = env.Scaffold("github.com/test/blogibcb") ) env.Must(env.Exec("create an IBC module",