From f1873d623ddebe594ceafa5270b2c77c45e623a9 Mon Sep 17 00:00:00 2001 From: Todd Knight Date: Mon, 28 Sep 2020 09:55:44 -0700 Subject: [PATCH] Attach account to auth token response. (#480) --- .../authenticate/authenticate_service.go | 1 + .../authenticate/authenticate_service_test.go | 27 ++++++++++++++----- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/internal/servers/controller/handlers/authenticate/authenticate_service.go b/internal/servers/controller/handlers/authenticate/authenticate_service.go index 6a4e390715..b6f92f5f14 100644 --- a/internal/servers/controller/handlers/authenticate/authenticate_service.go +++ b/internal/servers/controller/handlers/authenticate/authenticate_service.go @@ -161,6 +161,7 @@ func toProto(t *authtoken.AuthToken) *pba.AuthToken { Token: t.GetToken(), UserId: t.GetIamUserId(), AuthMethodId: t.GetAuthMethodId(), + AccountId: t.GetAuthAccountId(), CreatedTime: t.GetCreateTime().GetTimestamp(), UpdatedTime: t.GetUpdateTime().GetTimestamp(), ApproximateLastUsedTime: t.GetApproximateLastAccessTime().GetTimestamp(), diff --git a/internal/servers/controller/handlers/authenticate/authenticate_service_test.go b/internal/servers/controller/handlers/authenticate/authenticate_service_test.go index 7c9116cd8e..2a545d1eda 100644 --- a/internal/servers/controller/handlers/authenticate/authenticate_service_test.go +++ b/internal/servers/controller/handlers/authenticate/authenticate_service_test.go @@ -11,7 +11,6 @@ import ( "github.com/hashicorp/boundary/internal/auth/password" "github.com/hashicorp/boundary/internal/authtoken" "github.com/hashicorp/boundary/internal/db" - pba "github.com/hashicorp/boundary/internal/gen/controller/api/resources/authtokens" pbs "github.com/hashicorp/boundary/internal/gen/controller/api/services" "github.com/hashicorp/boundary/internal/iam" "github.com/hashicorp/boundary/internal/kms" @@ -50,7 +49,7 @@ func TestAuthenticate(t *testing.T) { cases := []struct { name string request *pbs.AuthenticateRequest - want *pbs.AuthenticateResponse + wantType string wantErr error }{ { @@ -66,9 +65,22 @@ func TestAuthenticate(t *testing.T) { return &structpb.Struct{Fields: creds} }(), }, - want: &pbs.AuthenticateResponse{Item: &pba.AuthToken{ + wantType: "token", + }, + { + name: "cookie-type", + request: &pbs.AuthenticateRequest{ AuthMethodId: am.GetPublicId(), - }}, + TokenType: "cookie", + Credentials: func() *structpb.Struct { + creds := map[string]*structpb.Value{ + "login_name": {Kind: &structpb.Value_StringValue{StringValue: testLoginName}}, + "password": {Kind: &structpb.Value_StringValue{StringValue: testPassword}}, + } + return &structpb.Struct{Fields: creds} + }(), + }, + wantType: "cookie", }, { name: "no-token-type", @@ -82,9 +94,6 @@ func TestAuthenticate(t *testing.T) { return &structpb.Struct{Fields: creds} }(), }, - want: &pbs.AuthenticateResponse{Item: &pba.AuthToken{ - AuthMethodId: am.GetPublicId(), - }}, }, { name: "bad-token-type", @@ -166,6 +175,9 @@ func TestAuthenticate(t *testing.T) { assert.Equal(am.GetPublicId(), aToken.GetAuthMethodId()) assert.Equal(aToken.GetCreatedTime(), aToken.GetUpdatedTime()) assert.Equal(aToken.GetCreatedTime(), aToken.GetApproximateLastUsedTime()) + assert.Equal(acct.GetPublicId(), aToken.GetAccountId()) + assert.Equal(am.GetPublicId(), aToken.GetAuthMethodId()) + assert.Equal(tc.wantType, resp.GetTokenType()) }) } } @@ -214,6 +226,7 @@ func TestAuthenticate_AuthAccountConnectedToIamUser(t *testing.T) { aToken := resp.GetItem() assert.Equal(iamUser.GetPublicId(), aToken.GetUserId()) assert.Equal(am.GetPublicId(), aToken.GetAuthMethodId()) + assert.Equal(acct.GetPublicId(), aToken.GetAccountId()) assert.NotEmpty(aToken.GetId()) assert.NotEmpty(aToken.GetToken())