Skip to content

Commit

Permalink
Fix ca file err (#460)
Browse files Browse the repository at this point in the history
* Fix missing error handling while loading a given ca_file

(cherry picked from commit 469cc0a)

* Fix missing error handling for ca_file option
  • Loading branch information
Marcel Ludwig authored Mar 29, 2022
1 parent 5f8e1d3 commit 2c4207a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

Unreleased changes are available as `avenga/couper:edge` container.

* **Fixed**
* missing error handling while loading a given `ca_file` ([#460](https://github.com/avenga/couper/pull/460))

---

## [1.8.0](https://github.com/avenga/couper/releases/tag/v1.8.0)
Expand Down
3 changes: 3 additions & 0 deletions command/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ func (r *Run) Execute(args Args, config *config.Couper, logEntry *logrus.Entry)

if config.Settings.CAFile != "" {
config.Settings.Certificate, err = readCertificateFile(config.Settings.CAFile)
if err != nil {
return err
}
logEntry.Infof("configured with ca-certificate: %s", config.Settings.CAFile)
}

Expand Down
39 changes: 39 additions & 0 deletions command/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,45 @@ func TestArgs_CAFile(t *testing.T) {
//}
}

func TestCAFile_Run(t *testing.T) {
helper := test.New(t)

couperHCL := `server {}
settings {
ca_file = "/tmp/not-there.pem"
}
`

couperFile, err := configload.LoadBytes([]byte(couperHCL), "ca-file-test.hcl")
helper.Must(err)

port := couperFile.Settings.DefaultPort

ctx, shutdown := context.WithDeadline(context.Background(), time.Now().Add(time.Second))
defer shutdown()

runCmd := NewRun(ctx)
if runCmd == nil {
t.Error("create run cmd failed")
return
}

log, _ := test.NewLogger()

// ensure the previous tests aren't listening
test.WaitForClosedPort(port)

execErr := runCmd.Execute(Args{}, couperFile, log.WithContext(ctx))
if execErr == nil {
t.Error("expected a ca read error")
} else {
want := "error reading ca-certificate: open /tmp/not-there.pem: no such file or directory"
if execErr.Error() != want {
t.Errorf("want: %q, got: %q", want, execErr.Error())
}
}
}

func TestReadCAFile(t *testing.T) {
helper := test.New(t)

Expand Down

0 comments on commit 2c4207a

Please sign in to comment.