Files
threshold/internal/servers/controller/handlers/outgoing_interceptor_test.go
T

26 lines
998 B
Go
Raw Normal View History

2020-09-01 09:23:41 -07:00
package handlers
import (
"context"
"net/http"
"net/http/httptest"
"testing"
pb "github.com/hashicorp/boundary/internal/gen/controller/api/resources/authtokens"
pbs "github.com/hashicorp/boundary/internal/gen/controller/api/services"
"github.com/stretchr/testify/assert"
2021-04-08 20:54:32 -04:00
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/types/known/structpb"
2020-09-01 09:23:41 -07:00
)
func TestOutgoingSplitCookie(t *testing.T) {
rec := httptest.NewRecorder()
2021-04-08 20:54:32 -04:00
attrs, err := ProtoToStruct(&pb.AuthToken{Token: "t_abc_1234567890"})
require.NoError(t, err)
attrs.GetFields()["token_type"] = structpb.NewStringValue("cookie")
require.NoError(t, OutgoingInterceptor(context.Background(), rec, &pbs.AuthenticateResponse{Attributes: attrs}))
2020-09-01 09:23:41 -07:00
assert.ElementsMatch(t, rec.Result().Cookies(), []*http.Cookie{
{Name: HttpOnlyCookieName, Value: "34567890", HttpOnly: true, Raw: "wt-http-token-cookie=34567890; HttpOnly"},
{Name: JsVisibleCookieName, Value: "t_abc_12", Raw: "wt-js-token-cookie=t_abc_12"},
})
}