2021-09-02 13:44:20 +01:00
|
|
|
package gosec_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"os"
|
|
|
|
|
2022-01-03 17:11:35 +00:00
|
|
|
. "github.com/onsi/ginkgo/v2"
|
2021-09-02 13:44:20 +01:00
|
|
|
. "github.com/onsi/gomega"
|
2023-03-30 08:31:24 +01:00
|
|
|
|
2021-09-02 13:44:20 +01:00
|
|
|
"github.com/securego/gosec/v2/cmd/vflag"
|
|
|
|
)
|
|
|
|
|
|
|
|
var _ = Describe("Cli", func() {
|
|
|
|
Context("vflag test", func() {
|
|
|
|
It("value must be empty as parameter value contains invalid character", func() {
|
2023-10-18 12:43:33 +01:00
|
|
|
os.Args = []string{"gosec", "-flag1=-incorrect"}
|
2021-09-02 13:44:20 +01:00
|
|
|
f := vflag.ValidatedFlag{}
|
2023-10-18 12:43:33 +01:00
|
|
|
flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ContinueOnError)
|
|
|
|
flag.Var(&f, "falg1", "")
|
|
|
|
flag.CommandLine.Init("flag1", flag.ContinueOnError)
|
2021-09-02 13:44:20 +01:00
|
|
|
flag.Parse()
|
2023-04-04 07:52:59 +01:00
|
|
|
Expect(flag.Parsed()).Should(BeTrue())
|
2021-09-02 13:44:20 +01:00
|
|
|
Expect(f.Value).Should(Equal(``))
|
|
|
|
})
|
|
|
|
It("value must be empty as parameter value contains invalid character without equal sign", func() {
|
|
|
|
os.Args = []string{"gosec", "-test2= -incorrect"}
|
|
|
|
f := vflag.ValidatedFlag{}
|
2023-10-18 12:43:33 +01:00
|
|
|
flag.CommandLine = flag.NewFlagSet(os.Args[0], flag.ContinueOnError)
|
2021-09-02 13:44:20 +01:00
|
|
|
flag.Var(&f, "test2", "")
|
|
|
|
flag.CommandLine.Init("test2", flag.ContinueOnError)
|
|
|
|
flag.Parse()
|
2023-04-04 07:52:59 +01:00
|
|
|
Expect(flag.Parsed()).Should(BeTrue())
|
2021-09-02 13:44:20 +01:00
|
|
|
Expect(f.Value).Should(Equal(``))
|
|
|
|
})
|
|
|
|
It("value must not be empty as parameter value contains valid character", func() {
|
|
|
|
os.Args = []string{"gosec", "-test3=correct"}
|
|
|
|
f := vflag.ValidatedFlag{}
|
|
|
|
flag.Var(&f, "test3", "")
|
|
|
|
flag.CommandLine.Init("test3", flag.ContinueOnError)
|
|
|
|
flag.Parse()
|
2023-04-04 07:52:59 +01:00
|
|
|
Expect(flag.Parsed()).Should(BeTrue())
|
2021-09-02 13:44:20 +01:00
|
|
|
Expect(f.Value).Should(Equal(`correct`))
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|