mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-01 19:17:58 +00:00
Add some repcluster handling to audit and add some tests (#2384)
* Add some repcluster handling to audit and add some tests * Fix incorrect assumption about nil auth
This commit is contained in:
55
audit/format_test.go
Normal file
55
audit/format_test.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package audit
|
||||
|
||||
import (
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/vault/helper/salt"
|
||||
"github.com/hashicorp/vault/logical"
|
||||
)
|
||||
|
||||
type noopFormatWriter struct {
|
||||
}
|
||||
|
||||
func (n *noopFormatWriter) WriteRequest(_ io.Writer, _ *AuditRequestEntry) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n *noopFormatWriter) WriteResponse(_ io.Writer, _ *AuditResponseEntry) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func TestFormatRequestErrors(t *testing.T) {
|
||||
salter, _ := salt.NewSalt(nil, nil)
|
||||
config := FormatterConfig{
|
||||
Salt: salter,
|
||||
}
|
||||
formatter := AuditFormatter{
|
||||
AuditFormatWriter: &noopFormatWriter{},
|
||||
}
|
||||
|
||||
if err := formatter.FormatRequest(ioutil.Discard, config, nil, nil, nil); err == nil {
|
||||
t.Fatal("expected error due to nil request")
|
||||
}
|
||||
if err := formatter.FormatRequest(nil, config, nil, &logical.Request{}, nil); err == nil {
|
||||
t.Fatal("expected error due to nil writer")
|
||||
}
|
||||
}
|
||||
|
||||
func TestFormatResponseErrors(t *testing.T) {
|
||||
salter, _ := salt.NewSalt(nil, nil)
|
||||
config := FormatterConfig{
|
||||
Salt: salter,
|
||||
}
|
||||
formatter := AuditFormatter{
|
||||
AuditFormatWriter: &noopFormatWriter{},
|
||||
}
|
||||
|
||||
if err := formatter.FormatResponse(ioutil.Discard, config, nil, nil, nil, nil); err == nil {
|
||||
t.Fatal("expected error due to nil request")
|
||||
}
|
||||
if err := formatter.FormatResponse(nil, config, nil, &logical.Request{}, nil, nil); err == nil {
|
||||
t.Fatal("expected error due to nil writer")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user