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 ca file err #460

Merged
merged 2 commits into from
Mar 29, 2022
Merged
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: 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