@@ -270,6 +270,52 @@ func Test_PrepareV1EnvironmentVariables_OnlyExplicitlySetValues(t *testing.T) {
270270 })
271271}
272272
273+ func Test_PrepareV1EnvironmentVariables_RequestConcurrency (t * testing.T ) {
274+ t .Run ("forwards resolved value to internal env when alt key is set via env" , func (t * testing.T ) {
275+ t .Setenv ("SNYK_REQUEST_CONCURRENCY" , "17" )
276+
277+ config := configuration .NewWithOpts (configuration .WithAutomaticEnv ())
278+ config .AddAlternativeKeys (cliv2 .ConfigKeyRequestConcurrency , []string {"snyk_request_concurrency" })
279+
280+ actual , err := cliv2 .PrepareV1EnvironmentVariables ([]string {}, "foo" , "bar" , "proxy" , "cacertlocation" , config , []string {})
281+
282+ assert .Nil (t , err )
283+ assert .Contains (t , actual , constants .SNYK_INTERNAL_REQUEST_CONCURRENCY_ENV + "=17" )
284+ })
285+
286+ t .Run ("does not set internal env when alt key is unset" , func (t * testing.T ) {
287+ // guard against a stray env var leaking into the test environment
288+ t .Setenv ("SNYK_REQUEST_CONCURRENCY" , "" )
289+ _ = os .Unsetenv ("SNYK_REQUEST_CONCURRENCY" )
290+
291+ config := configuration .NewWithOpts (configuration .WithAutomaticEnv ())
292+ config .AddAlternativeKeys (cliv2 .ConfigKeyRequestConcurrency , []string {"snyk_request_concurrency" })
293+
294+ actual , err := cliv2 .PrepareV1EnvironmentVariables ([]string {}, "foo" , "bar" , "proxy" , "cacertlocation" , config , []string {})
295+
296+ assert .Nil (t , err )
297+ for _ , kv := range actual {
298+ assert .NotContains (t , kv , constants .SNYK_INTERNAL_REQUEST_CONCURRENCY_ENV + "=" )
299+ }
300+ })
301+
302+ t .Run ("user-set internal env is stripped before Go reapplies it" , func (t * testing.T ) {
303+ t .Setenv ("SNYK_REQUEST_CONCURRENCY" , "9" )
304+
305+ config := configuration .NewWithOpts (configuration .WithAutomaticEnv ())
306+ config .AddAlternativeKeys (cliv2 .ConfigKeyRequestConcurrency , []string {"snyk_request_concurrency" })
307+
308+ // Simulate a user trying to bypass Go config by setting the internal var directly.
309+ input := []string {constants .SNYK_INTERNAL_REQUEST_CONCURRENCY_ENV + "=999" }
310+
311+ actual , err := cliv2 .PrepareV1EnvironmentVariables (input , "foo" , "bar" , "proxy" , "cacertlocation" , config , []string {})
312+
313+ assert .Nil (t , err )
314+ assert .Contains (t , actual , constants .SNYK_INTERNAL_REQUEST_CONCURRENCY_ENV + "=9" )
315+ assert .NotContains (t , actual , constants .SNYK_INTERNAL_REQUEST_CONCURRENCY_ENV + "=999" )
316+ })
317+ }
318+
273319func Test_PrepareV1EnvironmentVariables_Fail_DontOverrideExisting (t * testing.T ) {
274320 orgid := "orgid"
275321 testapi := "https://api.snyky.io"
0 commit comments