feat(authmethods): Add typed attributes to authenticate request and response

The AuthenticateRequest and AuthenticateResponse types have a
complex mapping rule system, which requires a pair of custom
callback functions.
This commit is contained in:
Johan Brandhorst-Satzkorn committed 2022-04-20 13:32:31 -04:00
1 parent 0e51f9cc92
commit a2bff4efdf
14 files changed
+1346 -678

No files matched your search

@@ -8,12 +8,15 @@ import (
"github.com/hashicorp/boundary/internal/gen/controller/api/services"
"github.com/hashicorp/boundary/sdk/pbs/controller/api"
"github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/authmethods"
"github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/authtokens"
"github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/scopes"
"github.com/hashicorp/boundary/sdk/wrapper"
"github.com/hashicorp/eventlogger"
"github.com/hashicorp/eventlogger/filters/encrypt"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
structpb "google.golang.org/protobuf/types/known/structpb"
"google.golang.org/protobuf/types/known/timestamppb"
)
// TestAuthenticate_Tags will test that the response filtering aligns with the
@@ -38,26 +41,31 @@ func TestAuthenticate_Tags(t *testing.T) {
CreatedAt: now,
Payload: &services.AuthenticateResponse{
Command: "public-command",
Attributes: &structpb.Struct{
Fields: map[string]*structpb.Value{
"account_id": structpb.NewStringValue("public-account_id"),
"approximate_last_used_time": structpb.NewStringValue("public-approximate_last_used_time"),
"auth_method_id": structpb.NewStringValue("public-auth_method_id"),
"authorized_actions": structpb.NewStringValue("public-authorized_actions"),
"created_time": structpb.NewStringValue("public-created_time"),
"expiration_time": structpb.NewStringValue("public-expiration_time"),
"id": structpb.NewStringValue("public-id"),
"scope": structpb.NewStringValue("public-scope"),
"type": structpb.NewStringValue("public-type"),
"updated_time": structpb.NewStringValue("public-updated_time"),
"user_id": structpb.NewStringValue("public-user_id"),
"status": structpb.NewStringValue("public-status"),
"auth_url": structpb.NewStringValue("public-auth_url"),
"token_id": structpb.NewStringValue("public-token_id"),
"final_redirect_url": structpb.NewStringValue("public-final_redirect_url"),
"token": structpb.NewStringValue("secret-token"),
Attrs: &services.AuthenticateResponse_AuthTokenResponse{
AuthTokenResponse: &authtokens.AuthToken{
AccountId: "public-account_id",
ApproximateLastUsedTime: timestamppb.New(now),
AuthMethodId: "public-auth_method_id",
AuthorizedActions: []string{
"public-authorized_actions",
},
CreatedTime: timestamppb.New(now),
ExpirationTime: timestamppb.New(now),
Id: "public-id",
ScopeId: "public-scope_id",
Scope: &scopes.ScopeInfo{
Id: "public-scope_id",
Type: "public-scope_type",
Name: "public-scope_name",
Description: "public-scope_description",
ParentScopeId: "public-parent_scope_id",
},
UpdatedTime: timestamppb.New(now),
UserId: "public-user_id",
Token: "secret-type",
},
},
Type: "public-type",
},
},
wantEvent: &eventlogger.Event{
@@ -66,26 +74,31 @@ func TestAuthenticate_Tags(t *testing.T) {
Payload: &services.AuthenticateResponse{
Command: "public-command",
// TODO(johanbrandhorst): update redaction once typed attributes are available
Attributes: &structpb.Struct{
Fields: map[string]*structpb.Value{
"account_id": structpb.NewStringValue(encrypt.RedactedData),
"approximate_last_used_time": structpb.NewStringValue(encrypt.RedactedData),
"auth_method_id": structpb.NewStringValue(encrypt.RedactedData),
"authorized_actions": structpb.NewStringValue(encrypt.RedactedData),
"created_time": structpb.NewStringValue(encrypt.RedactedData),
"expiration_time": structpb.NewStringValue(encrypt.RedactedData),
"id": structpb.NewStringValue(encrypt.RedactedData),
"scope": structpb.NewStringValue(encrypt.RedactedData),
"type": structpb.NewStringValue(encrypt.RedactedData),
"updated_time": structpb.NewStringValue(encrypt.RedactedData),
"user_id": structpb.NewStringValue(encrypt.RedactedData),
"status": structpb.NewStringValue(encrypt.RedactedData),
"auth_url": structpb.NewStringValue(encrypt.RedactedData),
"token_id": structpb.NewStringValue(encrypt.RedactedData),
"final_redirect_url": structpb.NewStringValue(encrypt.RedactedData),
"token": structpb.NewStringValue(encrypt.RedactedData),
Attrs: &services.AuthenticateResponse_AuthTokenResponse{
AuthTokenResponse: &authtokens.AuthToken{
AccountId: encrypt.RedactedData,
ApproximateLastUsedTime: timestamppb.New(now),
AuthMethodId: encrypt.RedactedData,
AuthorizedActions: []string{
encrypt.RedactedData,
},
CreatedTime: timestamppb.New(now),
ExpirationTime: timestamppb.New(now),
Id: encrypt.RedactedData,
ScopeId: encrypt.RedactedData,
Scope: &scopes.ScopeInfo{
Id: "public-scope_id",
Type: "public-scope_type",
Name: "public-scope_name",
Description: "public-scope_description",
ParentScopeId: "public-parent_scope_id",
},
UpdatedTime: timestamppb.New(now),
UserId: encrypt.RedactedData,
Token: encrypt.RedactedData,
},
},
Type: "public-type",
},
},
},
@@ -98,14 +111,9 @@ func TestAuthenticate_Tags(t *testing.T) {
AuthMethodId: "public-auth-method-id",
TokenType: "public-token-type",
Command: "public-command",
Attributes: &structpb.Struct{
Fields: map[string]*structpb.Value{
"login_name": structpb.NewStringValue("public-login_name"),
"auth_url": structpb.NewStringValue("public-auth_url"),
"token_id": structpb.NewStringValue("public-token_id"),
"state": structpb.NewStringValue("public-state"),
"password": structpb.NewStringValue("secret-password"),
"code": structpb.NewStringValue("secret-code"),
Attrs: &services.AuthenticateRequest_OidcAuthMethodAuthenticateTokenRequest{
OidcAuthMethodAuthenticateTokenRequest: &authmethods.OidcAuthMethodAuthenticateTokenRequest{
TokenId: "public-token-id",
},
},
},
@@ -118,14 +126,9 @@ func TestAuthenticate_Tags(t *testing.T) {
TokenType: "public-token-type",
Command: "public-command",
// TODO(johanbrandhorst): update redaction once typed attributes are available
Attributes: &structpb.Struct{
Fields: map[string]*structpb.Value{
"login_name": structpb.NewStringValue(encrypt.RedactedData),
"auth_url": structpb.NewStringValue(encrypt.RedactedData),
"token_id": structpb.NewStringValue(encrypt.RedactedData),
"state": structpb.NewStringValue(encrypt.RedactedData),
"password": structpb.NewStringValue(encrypt.RedactedData),
"code": structpb.NewStringValue(encrypt.RedactedData),
Attrs: &services.AuthenticateRequest_OidcAuthMethodAuthenticateTokenRequest{
OidcAuthMethodAuthenticateTokenRequest: &authmethods.OidcAuthMethodAuthenticateTokenRequest{
TokenId: encrypt.RedactedData,
},
},
},