Skip to content
This repository has been archived by the owner on Jul 19, 2022. It is now read-only.

Allow SSL validation to be skipped #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ cat > .config
"pass": "abc123",
"org": "cf-sli",
"space": "dev",
"domain": "example.com"
"domain": "example.com",
"skip_ssl_validation": false
}
```

Expand Down
13 changes: 7 additions & 6 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import (
)

type Config struct {
Api string `json:"api"`
User string `json:"user"`
Password string `json:"pass"`
Domain string `json:"domain"`
Org string `json:"org"`
Space string `json:"space"`
Api string `json:"api"`
User string `json:"user"`
Password string `json:"pass"`
Domain string `json:"domain"`
Org string `json:"org"`
Space string `json:"space"`
SkipSslValidation bool `json:"skip_ssl_validation"`
}

func (c *Config) LoadConfig(filename string) error {
Expand Down
1 change: 1 addition & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var _ = Describe("LoadConfig", func() {
Expect(c.Org).To(Equal("fake_org"))
Expect(c.Space).To(Equal("fake_space"))
Expect(c.Domain).To(Equal("fake_domain"))
Expect(c.SkipSslValidation).To(Equal(false))
})

It("returns an error reading a none-existing file", func() {
Expand Down
10 changes: 7 additions & 3 deletions sli_executor/sli_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ func (s SliExecutor) cf(commands ...string) error {
return s.Cf_wrapper.RunCF(commands...)
}

func (s SliExecutor) Prepare(api string, user string, password string, org string, space string) error {
err := s.cf("api", api)
func (s SliExecutor) Prepare(api string, user string, password string, org string, space string, skipSslValidation bool) error {
cfApiArgs := []string{"api", api}
if skipSslValidation {
cfApiArgs = append(cfApiArgs, "--skip-ssl-validation")
}
err := s.cf(cfApiArgs...)
if err != nil {
return err
}
Expand Down Expand Up @@ -87,7 +91,7 @@ func (s SliExecutor) CleanupSli(app_name string) error {
func (s SliExecutor) RunTest(app_name string, app_buildpack string, path string, c config.Config) (*Result, error) {
defer s.CleanupSli(app_name)

err := s.Prepare(c.Api, c.User, c.Password, c.Org, c.Space)
err := s.Prepare(c.Api, c.User, c.Password, c.Org, c.Space, c.SkipSslValidation)
if err != nil {
result := &Result{
StartStatus: 0,
Expand Down
31 changes: 27 additions & 4 deletions sli_executor/sli_executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

var _ = Describe("SliExecutor", func() {
var expected_api_calls = []string{"api", "fake_api"}
var expected_api_without_ssl_validation_calls = []string{"api", "fake_api", "--skip-ssl-validation"}
var expected_auth_calls = []string{"auth", "fake_user", "fake_pass"}
var expected_target_calls = []string{"target", "-o", "fake_org", "-s", "fake_space"}
var expected_push_calls = []string{"push", "-p", "./fake_path", "-b", "fake_buildpack", "fake_app_name", "-d", "fake_domain", "--no-start"}
Expand All @@ -35,29 +36,38 @@ var _ = Describe("SliExecutor", func() {

Context("#Prepare", func() {
It("returns nil if cf command executes successfully", func() {
err := sli.Prepare("fake_api", "fake_user", "fake_pass", "fake_org", "fake_space")
err := sli.Prepare("fake_api", "fake_user", "fake_pass", "fake_org", "fake_space", false)
Expect(err).NotTo(HaveOccurred())

Expect(fakeCf).To(HaveReceived("RunCF").With(expected_api_calls))
Expect(fakeCf).To(HaveReceived("RunCF").With(expected_auth_calls))
Expect(fakeCf).To(HaveReceived("RunCF").With(expected_target_calls))
})

It("skips SSL validation on `cf api` if skipSslValidation is true", func() {
err := sli.Prepare("fake_api", "fake_user", "fake_pass", "fake_org", "fake_space", true)
Expect(err).NotTo(HaveOccurred())

Expect(fakeCf).To(HaveReceived("RunCF").With(expected_api_without_ssl_validation_calls))
Expect(fakeCf).To(HaveReceived("RunCF").With(expected_auth_calls))
Expect(fakeCf).To(HaveReceived("RunCF").With(expected_target_calls))
})

It("returns err when cf api fails", func() {
fakeCf.StubFailingCF("api")
err := sli.Prepare("fake_api", "fake_user", "fake_pass", "fake_org", "fake_space")
err := sli.Prepare("fake_api", "fake_user", "fake_pass", "fake_org", "fake_space", false)
Expect(err).To(HaveOccurred())
})

It("returns err when cf auth fails", func() {
fakeCf.StubFailingCF("auth")
err := sli.Prepare("fake_api", "fake_user", "fake_pass", "fake_org", "fake_space")
err := sli.Prepare("fake_api", "fake_user", "fake_pass", "fake_org", "fake_space", false)
Expect(err).To(HaveOccurred())
})

It("returns err when cf target fails", func() {
fakeCf.StubFailingCF("target")
err := sli.Prepare("fake_api", "fake_user", "fake_pass", "fake_org", "fake_space")
err := sli.Prepare("fake_api", "fake_user", "fake_pass", "fake_org", "fake_space", false)
Expect(err).To(HaveOccurred())
})
})
Expand Down Expand Up @@ -154,6 +164,19 @@ var _ = Describe("SliExecutor", func() {
Expect(fakeCf).To(HaveReceived("RunCF").With(expected_logout_calls))
})

Context("when skipSslValidation is true", func() {
BeforeEach(func() {
config.SkipSslValidation = true
})

It("skips SSL validation on `cf api`", func() {
_, err := sli.RunTest("fake_app_name", "fake_buildpack", "./fake_path", config)
Expect(err).NotTo(HaveOccurred())

Expect(fakeCf).To(HaveReceived("RunCF").With(expected_api_without_ssl_validation_calls))
})
})

Context("When something in the prepare step fails", func() {
It("Cleans up the app", func() {
fakeCf.StubFailingCF("api")
Expand Down