Skip to content

Commit

Permalink
Add a test for nil-ing out request tokenentry
Browse files Browse the repository at this point in the history
  • Loading branch information
jefferai committed Jun 8, 2018
1 parent 6ec09a0 commit 8eee1da
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions vault/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ type NoopBackend struct {
}

func (n *NoopBackend) HandleRequest(ctx context.Context, req *logical.Request) (*logical.Response, error) {
if req.TokenEntry() != nil {
panic("got a non-nil TokenEntry")
}

var err error
resp := n.Response
if n.RequestHandler != nil {
Expand Down Expand Up @@ -171,13 +175,19 @@ func TestRouter_Mount(t *testing.T) {
req := &logical.Request{
Path: "prod/aws/foo",
}
req.SetTokenEntry(&logical.TokenEntry{
ID: "foo",
})
resp, err := r.Route(context.Background(), req)
if err != nil {
t.Fatalf("err: %v", err)
}
if resp != nil {
t.Fatalf("bad: %v", resp)
}
if req.TokenEntry() == nil || req.TokenEntry().ID != "foo" {
t.Fatalf("unexpected value for token entry: %v", req.TokenEntry())
}

// Verify the path
if len(n.Paths) != 1 || n.Paths[0] != "foo" {
Expand Down

0 comments on commit 8eee1da

Please sign in to comment.