mirror of
				https://github.com/optim-enterprises-bv/vault.git
				synced 2025-10-30 18:17:55 +00:00 
			
		
		
		
	 6c836bcd9b
			
		
	
	6c836bcd9b
	
	
	
		
			
			Move audit.LogInput to sdk/logical. Allow the Data values in audited logical.Request and Response to implement OptMarshaler, in which case we delegate hashing/serializing responsibility to them. Add new ClientCertificateSerialNumber audit request field. SystemView can now be cast to ExtendedSystemView to expose the Auditor interface, which allows submitting requests and responses to the audit broker.
		
			
				
	
	
		
			73 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
			
		
		
	
	
			73 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Go
		
	
	
	
	
	
| package audit
 | |
| 
 | |
| import (
 | |
| 	"context"
 | |
| 	"io"
 | |
| 	"io/ioutil"
 | |
| 	"testing"
 | |
| 
 | |
| 	"github.com/hashicorp/vault/sdk/helper/salt"
 | |
| 	"github.com/hashicorp/vault/sdk/logical"
 | |
| )
 | |
| 
 | |
| type noopFormatWriter struct {
 | |
| 	salt     *salt.Salt
 | |
| 	SaltFunc func() (*salt.Salt, error)
 | |
| }
 | |
| 
 | |
| func (n *noopFormatWriter) WriteRequest(_ io.Writer, _ *AuditRequestEntry) error {
 | |
| 	return nil
 | |
| }
 | |
| 
 | |
| func (n *noopFormatWriter) WriteResponse(_ io.Writer, _ *AuditResponseEntry) error {
 | |
| 	return nil
 | |
| }
 | |
| 
 | |
| func (n *noopFormatWriter) Salt(ctx context.Context) (*salt.Salt, error) {
 | |
| 	if n.salt != nil {
 | |
| 		return n.salt, nil
 | |
| 	}
 | |
| 	var err error
 | |
| 	n.salt, err = salt.NewSalt(ctx, nil, nil)
 | |
| 	if err != nil {
 | |
| 		return nil, err
 | |
| 	}
 | |
| 	return n.salt, nil
 | |
| }
 | |
| 
 | |
| func TestFormatRequestErrors(t *testing.T) {
 | |
| 	config := FormatterConfig{}
 | |
| 	formatter := AuditFormatter{
 | |
| 		AuditFormatWriter: &noopFormatWriter{},
 | |
| 	}
 | |
| 
 | |
| 	if err := formatter.FormatRequest(context.Background(), ioutil.Discard, config, &logical.LogInput{}); err == nil {
 | |
| 		t.Fatal("expected error due to nil request")
 | |
| 	}
 | |
| 
 | |
| 	in := &logical.LogInput{
 | |
| 		Request: &logical.Request{},
 | |
| 	}
 | |
| 	if err := formatter.FormatRequest(context.Background(), nil, config, in); err == nil {
 | |
| 		t.Fatal("expected error due to nil writer")
 | |
| 	}
 | |
| }
 | |
| 
 | |
| func TestFormatResponseErrors(t *testing.T) {
 | |
| 	config := FormatterConfig{}
 | |
| 	formatter := AuditFormatter{
 | |
| 		AuditFormatWriter: &noopFormatWriter{},
 | |
| 	}
 | |
| 
 | |
| 	if err := formatter.FormatResponse(context.Background(), ioutil.Discard, config, &logical.LogInput{}); err == nil {
 | |
| 		t.Fatal("expected error due to nil request")
 | |
| 	}
 | |
| 
 | |
| 	in := &logical.LogInput{
 | |
| 		Request: &logical.Request{},
 | |
| 	}
 | |
| 	if err := formatter.FormatResponse(context.Background(), nil, config, in); err == nil {
 | |
| 		t.Fatal("expected error due to nil writer")
 | |
| 	}
 | |
| }
 |