Add a test for nil-ing out request tokenentry

This commit is contained in:
Jeff Mitchell 2018-06-08 19:55:39 -04:00
parent 743e31202d
commit e461b945a5
1 changed files with 10 additions and 0 deletions

View File

@ -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 {
@ -171,6 +175,9 @@ 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)
@ -178,6 +185,9 @@ func TestRouter_Mount(t *testing.T) {
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" {