Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!: Update npm.strictSSL behavior #935

Merged
merged 14 commits into from
Aug 15, 2024
2 changes: 1 addition & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ archives:
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ .Tag }}-next"
version_template: "{{ .Tag }}-next"
changelog:
sort: asc
filters:
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/docker/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func logPushProgress(reader io.ReadCloser) error {

// Create a progress spinner for statuses that don't have progress details, like 'Preparing'.
if msg.Progress == nil || msg.Progress.Total == 0 {
progress.Show(msg.Status)
progress.Show(msg.Status, nil)
continue
}

Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/ini/initializer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1629,7 +1629,7 @@ func Test_checkCredentials(t *testing.T) {
name: "Invalid credentials",
frameworkFn: func(ctx context.Context) ([]string, error) {
errMsg := "unexpected status '401' from test-composer: Unauthorized\n"
return []string{}, fmt.Errorf(errMsg)
return []string{}, errors.New(errMsg)
},
wantErr: errors.New("invalid credentials provided"),
},
Expand Down
19 changes: 16 additions & 3 deletions internal/cmd/run/cypress.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,14 @@ import (
"github.com/saucelabs/saucectl/internal/viper"
)

type cypressFlags struct {
npmStrictSSL bool
}

// NewCypressCmd creates the 'run' command for Cypress.
func NewCypressCmd() *cobra.Command {
sc := flags.SnakeCharmer{Fmap: map[string]*pflag.Flag{}}
var cflags cypressFlags

cmd := &cobra.Command{
Use: "cypress",
Expand All @@ -45,7 +50,7 @@ func NewCypressCmd() *cobra.Command {
// Test patterns are passed in via positional args.
viper.Set("suite::config::specPattern", args)

exitCode, err := runCypress(cmd, true)
exitCode, err := runCypress(cmd, cflags, true)
if err != nil {
log.Err(err).Msg("failed to execute run command")
}
Expand Down Expand Up @@ -84,12 +89,15 @@ func NewCypressCmd() *cobra.Command {
sc.String("npm.registry", "npm::registry", "", "Specify the npm registry URL")
sc.StringToString("npm.packages", "npm::packages", map[string]string{}, "Specify npm packages that are required to run tests")
sc.StringSlice("npm.dependencies", "npm::dependencies", []string{}, "Specify local npm dependencies for saucectl to upload. These dependencies must already be installed in the local node_modules directory.")
sc.Bool("npm.strictSSL", "npm::strictSSL", true, "Whether or not to do SSL key validation when making requests to the registry via https")
cmd.PersistentFlags().BoolVar(&cflags.npmStrictSSL, "npm.strictSSL", true, "Whether or not to do SSL key validation when making requests to the registry via https.")
tianfeng92 marked this conversation as resolved.
Show resolved Hide resolved

// Deprecated flags
_ = sc.Fset.MarkDeprecated("npm.registry", "please set the npm registries field in the Sauce configuration file")

return cmd
}

func runCypress(cmd *cobra.Command, isCLIDriven bool) (int, error) {
func runCypress(cmd *cobra.Command, cflags cypressFlags, isCLIDriven bool) (int, error) {
if !isCLIDriven {
config.ValidateSchema(gFlags.cfgFilePath)
}
Expand All @@ -103,6 +111,11 @@ func runCypress(cmd *cobra.Command, isCLIDriven bool) (int, error) {
if err := p.ApplyFlags(gFlags.selectedSuite); err != nil {
return 1, err
}

if cmd.Flags().Changed("npm.strictSSL") {
p.SetNpmStrictSSL(&cflags.npmStrictSSL)
}

p.SetDefaults()
if !gFlags.noAutoTagging {
p.AppendTags(ci.GetTags())
Expand Down
17 changes: 14 additions & 3 deletions internal/cmd/run/playwright.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,14 @@ import (
"github.com/saucelabs/saucectl/internal/viper"
)

type playwrightFlags struct {
npmStrictSSL bool
}

// NewPlaywrightCmd creates the 'run' command for Playwright.
func NewPlaywrightCmd() *cobra.Command {
sc := flags.SnakeCharmer{Fmap: map[string]*pflag.Flag{}}
var pf playwrightFlags

cmd := &cobra.Command{
Use: "playwright",
Expand All @@ -46,7 +51,7 @@ func NewPlaywrightCmd() *cobra.Command {
// Test patterns are passed in via positional args.
viper.Set("suite::testMatch", args)

exitCode, err := runPlaywright(cmd, true)
exitCode, err := runPlaywright(cmd, pf, true)
if err != nil {
log.Err(err).Msg("failed to execute run command")
}
Expand Down Expand Up @@ -92,12 +97,14 @@ func NewPlaywrightCmd() *cobra.Command {
sc.String("npm.registry", "npm::registry", "", "Specify the npm registry URL")
sc.StringToString("npm.packages", "npm::packages", map[string]string{}, "Specify npm packages that are required to run tests")
sc.StringSlice("npm.dependencies", "npm::dependencies", []string{}, "Specify local npm dependencies for saucectl to upload. These dependencies must already be installed in the local node_modules directory.")
sc.Bool("npm.strictSSL", "npm::strictSSL", true, "Whether or not to do SSL key validation when making requests to the registry via https")
cmd.PersistentFlags().BoolVar(&pf.npmStrictSSL, "npm.strictSSL", true, "Whether or not to do SSL key validation when making requests to the registry via https.")

// Deprecated flags
_ = sc.Fset.MarkDeprecated("npm.registry", "please set the npm registries field in the Sauce configuration file")
return cmd
}

func runPlaywright(cmd *cobra.Command, isCLIDriven bool) (int, error) {
func runPlaywright(cmd *cobra.Command, pf playwrightFlags, isCLIDriven bool) (int, error) {
if !isCLIDriven {
config.ValidateSchema(gFlags.cfgFilePath)
}
Expand All @@ -109,6 +116,10 @@ func runPlaywright(cmd *cobra.Command, isCLIDriven bool) (int, error) {

p.CLIFlags = flags.CaptureCommandLineFlags(cmd.Flags())

if cmd.Flags().Changed("npm.strictSSL") {
p.Npm.StrictSSL = &pf.npmStrictSSL
}

if err := applyPlaywrightFlags(&p); err != nil {
return 1, err
}
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,10 @@ func preRun() error {
// Run runs the command
func Run(cmd *cobra.Command) (int, error) {
if typeDef.Kind == cypress.Kind {
return runCypress(cmd, false)
return runCypress(cmd, cypressFlags{}, false)
}
if typeDef.Kind == playwright.Kind {
return runPlaywright(cmd, false)
return runPlaywright(cmd, playwrightFlags{}, false)
}
if typeDef.Kind == testcafe.Kind {
return runTestcafe(cmd, testcafeFlags{}, false)
Expand Down
10 changes: 9 additions & 1 deletion internal/cmd/run/testcafe.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
type testcafeFlags struct {
QuarantineMode flags.QuarantineMode
Simulator flags.Simulator
npmStrictSSL bool
}

// NewTestcafeCmd creates the 'run' command for TestCafe.
Expand Down Expand Up @@ -119,11 +120,14 @@ func NewTestcafeCmd() *cobra.Command {
sc.String("npm.registry", "npm::registry", "", "Specify the npm registry URL")
sc.StringToString("npm.packages", "npm::packages", map[string]string{}, "Specify npm packages that are required to run tests")
sc.StringSlice("npm.dependencies", "npm::dependencies", []string{}, "Specify local npm dependencies for saucectl to upload. These dependencies must already be installed in the local node_modules directory.")
sc.Bool("npm.strictSSL", "npm::strictSSL", true, "Whether or not to do SSL key validation when making requests to the registry via https")
cmd.PersistentFlags().BoolVar(&lflags.npmStrictSSL, "npm.strictSSL", true, "Whether or not to do SSL key validation when making requests to the registry via https.")

// Simulators
f.Var(&lflags.Simulator, "simulator", "Specifies the simulator to use for testing")

// Deprecated flags
_ = sc.Fset.MarkDeprecated("npm.registry", "please set the npm registries field in the Sauce configuration file")

return cmd
}

Expand All @@ -139,6 +143,10 @@ func runTestcafe(cmd *cobra.Command, tcFlags testcafeFlags, isCLIDriven bool) (i

p.CLIFlags = flags.CaptureCommandLineFlags(cmd.Flags())

if cmd.Flags().Changed("npm.strictSSL") {
p.Npm.StrictSSL = &tcFlags.npmStrictSSL
}

if err := applyTestcafeFlags(&p, tcFlags); err != nil {
return 1, err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ type Npm struct {
Registries []Registry `yaml:"registries" json:"registries,omitempty"`
Packages map[string]string `yaml:"packages,omitempty" json:"packages"`
Dependencies []string `yaml:"dependencies,omitempty" json:"dependencies"`
StrictSSL bool `yaml:"strictSSL,omitempty" json:"strictSSL"`
StrictSSL *bool `yaml:"strictSSL,omitempty" json:"strictSSL"`
}

// Defaults represents default suite settings.
Expand Down
1 change: 1 addition & 0 deletions internal/cypress/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type Project interface {
GetReporters() config.Reporters
GetNotifications() config.Notifications
GetNpm() config.Npm
SetNpmStrictSSL(strictSSL *bool)
SetCLIFlags(map[string]interface{})
GetSuites() []suite.Suite
GetKind() string
Expand Down
4 changes: 4 additions & 0 deletions internal/cypress/v1/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,10 @@ func (p *Project) GetNpm() config.Npm {
return p.Npm
}

func (p *Project) SetNpmStrictSSL(strictSSL *bool) {
p.Npm.StrictSSL = strictSSL
}

// SetCLIFlags sets cli flags
func (p *Project) SetCLIFlags(flags map[string]interface{}) {
p.CLIFlags = flags
Expand Down
2 changes: 1 addition & 1 deletion internal/http/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func doCheckProxy(scheme string) error {
rawProxyURL = strings.Replace(rawProxyURL, pass, "****", -1)
}
}
log.Info().Msgf(fmt.Sprintf("Using %s proxy: %s", strings.ToUpper(scheme), rawProxyURL))
log.Info().Msgf("Using %s proxy: %s", strings.ToUpper(scheme), rawProxyURL)
return nil
}

Expand Down