mirror of
https://github.com/optim-enterprises-bv/vault.git
synced 2025-11-03 12:07:54 +00:00
logical/testing: helper to test auth
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/hashicorp/vault/api"
|
||||
@@ -230,6 +231,21 @@ func Test(t TestT, c TestCase) {
|
||||
}
|
||||
}
|
||||
|
||||
// TestCheckAuth is a helper to check that a request generated an
|
||||
// auth token with the proper policies.
|
||||
func TestCheckAuth(policies []string) TestCheckFunc {
|
||||
return func(resp *logical.Response) error {
|
||||
if resp.Auth == nil {
|
||||
return fmt.Errorf("no auth in response")
|
||||
}
|
||||
if !reflect.DeepEqual(resp.Auth.Policies, policies) {
|
||||
return fmt.Errorf("invalid policies: %#v", resp.Auth.Policies)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// TestT is the interface used to handle the test lifecycle of a test.
|
||||
//
|
||||
// Users should just use a *testing.T object, which implements this.
|
||||
|
||||
Reference in New Issue
Block a user