@@ -16,8 +16,10 @@ import (
1616 nomadapi "github.com/hashicorp/nomad/api"
1717 "github.com/hashicorp/vault/helper/testhelpers"
1818 "github.com/hashicorp/vault/sdk/helper/docker"
19+ "github.com/hashicorp/vault/sdk/helper/testhelpers/observations"
1920 "github.com/hashicorp/vault/sdk/logical"
2021 "github.com/mitchellh/mapstructure"
22+ "github.com/stretchr/testify/require"
2123)
2224
2325type Config struct {
@@ -159,6 +161,8 @@ func preprePolicies(nomadClient *nomadapi.Client) error {
159161func TestBackend_config_Bootstrap (t * testing.T ) {
160162 config := logical .TestBackendConfig ()
161163 config .StorageView = & logical.InmemStorage {}
164+ or := observations .NewTestObservationRecorder ()
165+ config .ObservationRecorder = or
162166 b , err := Factory (context .Background (), config )
163167 if err != nil {
164168 t .Fatal (err )
@@ -184,12 +188,16 @@ func TestBackend_config_Bootstrap(t *testing.T) {
184188 t .Fatalf ("failed to write configuration: resp:%#v err:%s" , resp , err )
185189 }
186190
191+ require .Equal (t , 1 , or .NumObservationsByType (ObservationTypeNomadConfigAccessWrite ))
192+
187193 confReq .Operation = logical .ReadOperation
188194 resp , err = b .HandleRequest (context .Background (), confReq )
189195 if err != nil || (resp != nil && resp .IsError ()) {
190196 t .Fatalf ("failed to write configuration: resp:%#v err:%s" , resp , err )
191197 }
192198
199+ require .Equal (t , 1 , or .NumObservationsByType (ObservationTypeNomadConfigAccessRead ))
200+
193201 expected := map [string ]interface {}{
194202 "address" : connData ["address" ].(string ),
195203 "max_token_name_length" : 0 ,
@@ -318,6 +326,8 @@ func TestBackend_config_access_with_certs(t *testing.T) {
318326func TestBackend_renew_revoke (t * testing.T ) {
319327 config := logical .TestBackendConfig ()
320328 config .StorageView = & logical.InmemStorage {}
329+ or := observations .NewTestObservationRecorder ()
330+ config .ObservationRecorder = or
321331 b , err := Factory (context .Background (), config )
322332 if err != nil {
323333 t .Fatal (err )
@@ -341,6 +351,7 @@ func TestBackend_renew_revoke(t *testing.T) {
341351 if err != nil {
342352 t .Fatal (err )
343353 }
354+ require .Equal (t , 1 , or .NumObservationsByType (ObservationTypeNomadConfigAccessWrite ))
344355
345356 req .Path = "role/test"
346357 req .Data = map [string ]interface {}{
@@ -351,6 +362,12 @@ func TestBackend_renew_revoke(t *testing.T) {
351362 if err != nil {
352363 t .Fatal (err )
353364 }
365+ require .Equal (t , 1 , or .NumObservationsByType (ObservationTypeNomadRoleWrite ))
366+ roleObs := or .ObservationsByType (ObservationTypeNomadRoleWrite )
367+ require .Len (t , roleObs , 1 )
368+ require .Equal (t , "test" , roleObs [0 ].Data ["role_name" ])
369+ require .Equal (t , "client" , roleObs [0 ].Data ["token_type" ])
370+ require .Equal (t , false , roleObs [0 ].Data ["global" ])
354371
355372 req .Operation = logical .ReadOperation
356373 req .Path = "creds/test"
@@ -364,6 +381,15 @@ func TestBackend_renew_revoke(t *testing.T) {
364381 if resp .IsError () {
365382 t .Fatalf ("resp is error: %v" , resp .Error ())
366383 }
384+ require .Equal (t , 1 , or .NumObservationsByType (ObservationTypeNomadCredentialCreateSuccess ))
385+ credObs := or .ObservationsByType (ObservationTypeNomadCredentialCreateSuccess )
386+ require .Len (t , credObs , 1 )
387+ require .Equal (t , "test" , credObs [0 ].Data ["role_name" ])
388+ require .Equal (t , "client" , credObs [0 ].Data ["token_type" ])
389+ require .Equal (t , false , credObs [0 ].Data ["global" ])
390+ require .Equal (t , "0s" , credObs [0 ].Data ["ttl" ])
391+ require .Equal (t , "0s" , credObs [0 ].Data ["max_ttl" ])
392+ require .NotEmpty (t , credObs [0 ].Data ["accessor_id" ])
367393
368394 generatedSecret := resp .Secret
369395 generatedSecret .TTL = 6 * time .Hour
@@ -402,12 +428,24 @@ func TestBackend_renew_revoke(t *testing.T) {
402428 t .Fatal ("got nil response from renew" )
403429 }
404430
431+ require .Equal (t , 1 , or .NumObservationsByType (ObservationTypeNomadCredentialRenew ))
432+ renewObs := or .ObservationsByType (ObservationTypeNomadCredentialRenew )
433+ require .Len (t , renewObs , 1 )
434+ require .Equal (t , d .Accessor , renewObs [0 ].Data ["accessor_id" ])
435+ require .Equal (t , "0s" , renewObs [0 ].Data ["ttl" ])
436+ require .Equal (t , "0s" , renewObs [0 ].Data ["max_ttl" ])
437+
405438 req .Operation = logical .RevokeOperation
406439 resp , err = b .HandleRequest (context .Background (), req )
407440 if err != nil {
408441 t .Fatal (err )
409442 }
410443
444+ require .Equal (t , 1 , or .NumObservationsByType (ObservationTypeNomadCredentialRevoke ))
445+ revokeObs := or .ObservationsByType (ObservationTypeNomadCredentialRevoke )
446+ require .Len (t , revokeObs , 1 )
447+ require .Equal (t , d .Accessor , revokeObs [0 ].Data ["accessor_id" ])
448+
411449 // Build a management client and verify that the token does not exist anymore
412450 nomadmgmtConfig := nomadapi .DefaultConfig ()
413451 nomadmgmtConfig .Address = connData ["address" ].(string )
0 commit comments