feat(authmethods): add well typed attribute options (#1972)
Add well typed attribute options to the authmethods proto definitions, while hiding them from being rendered in the openapiv2 spec.
This commit is contained in:
1 parent
ec25e7682c
commit
53481146fd
20 files changed
+1544
-1549
No files matched your search
@@ -80,13 +80,15 @@ func TestAuthenticate(t *testing.T) {
|
||||
assert.NotNil(tok)
|
||||
got := tests_api.CloudEventFromFile(t, eventConfig.AuditEvents.Name())
|
||||
|
||||
// All attribute fields are classified for now.
|
||||
// TODO(johanbrandhorst): revert this when classification is done for auth methods
|
||||
reqDetails := tests_api.GetEventDetails(t, got, "request")
|
||||
tests_api.AssertRedactedValues(t, reqDetails)
|
||||
tests_api.AssertRedactedValues(t, reqDetails["attributes"], "password")
|
||||
tests_api.AssertRedactedValues(t, reqDetails["attributes"], "password", "login_name")
|
||||
|
||||
respDetails := tests_api.GetEventDetails(t, got, "response")
|
||||
tests_api.AssertRedactedValues(t, respDetails)
|
||||
tests_api.AssertRedactedValues(t, respDetails["attributes"], "token")
|
||||
tests_api.AssertRedactedValues(t, respDetails["attributes"], "token", "approximate_last_used_time", "expiration_time", "token_type", "updated_time", "user_id", "account_id", "auth_method_id", "authorized_actions", "created_time", "id")
|
||||
|
||||
_ = os.WriteFile(eventConfig.AuditEvents.Name(), nil, 0o666) // clean out audit events from previous calls
|
||||
tok, err = methods.Authenticate(tc.Context(), tc.Server().DevPasswordAuthMethodId, "login", map[string]interface{}{"login_name": "user", "password": "bad-pass"})
|
||||
@@ -96,5 +98,5 @@ func TestAuthenticate(t *testing.T) {
|
||||
|
||||
reqDetails = tests_api.GetEventDetails(t, got, "request")
|
||||
tests_api.AssertRedactedValues(t, reqDetails)
|
||||
tests_api.AssertRedactedValues(t, reqDetails["attributes"], "password")
|
||||
tests_api.AssertRedactedValues(t, reqDetails["attributes"], "password", "login_name")
|
||||
}
|
||||
@@ -6,6 +6,8 @@ import (
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
"github.com/google/go-cmp/cmp/cmpopts"
|
||||
"github.com/hashicorp/boundary/api"
|
||||
"github.com/hashicorp/boundary/api/authmethods"
|
||||
"github.com/hashicorp/boundary/internal/auth/password"
|
||||
@@ -39,7 +41,7 @@ func TestCrud(t *testing.T) {
|
||||
tcConfig.Eventing = &eventConfig.EventerConfig
|
||||
|
||||
tc := controller.NewTestController(t, &controller.TestControllerOpts{Config: tcConfig})
|
||||
defer tc.Shutdown()
|
||||
t.Cleanup(tc.Shutdown)
|
||||
|
||||
client := tc.Client()
|
||||
token := tc.Token()
|
||||
@@ -58,84 +60,175 @@ func TestCrud(t *testing.T) {
|
||||
|
||||
require.NotNil(eventConfig.AuditEvents)
|
||||
_ = os.WriteFile(eventConfig.AuditEvents.Name(), nil, 0o666) // clean out audit events from previous calls
|
||||
u, err := amClient.Create(tc.Context(), "password", global,
|
||||
pw, err := amClient.Create(tc.Context(), "password", global,
|
||||
authmethods.WithName("bar"))
|
||||
require.NoError(err)
|
||||
checkAuthMethod("create", u.Item, "bar", 1)
|
||||
t.Cleanup(func() {
|
||||
_, err = amClient.Delete(tc.Context(), pw.Item.Id)
|
||||
require.NoError(err)
|
||||
})
|
||||
checkAuthMethod("create", pw.Item, "bar", 1)
|
||||
|
||||
got := tests_api.CloudEventFromFile(t, eventConfig.AuditEvents.Name())
|
||||
reqItem := tests_api.GetEventDetails(t, got, "request")["item"].(map[string]interface{})
|
||||
tests_api.AssertRedactedValues(t, reqItem)
|
||||
tests_api.AssertRedactedValues(t, reqItem["Attrs"])
|
||||
// TODO(johanbrandhorst): Not all of these fields will be redacted eventually
|
||||
tests_api.AssertRedactedValues(t, reqItem["Attrs"].(map[string]interface{})["PasswordAuthMethodAttributes"])
|
||||
|
||||
respItem := tests_api.GetEventDetails(t, got, "response")["item"].(map[string]interface{})
|
||||
tests_api.AssertRedactedValues(t, respItem)
|
||||
tests_api.AssertRedactedValues(t, respItem["attributes"])
|
||||
tests_api.AssertRedactedValues(t, respItem["Attrs"])
|
||||
// TODO(johanbrandhorst): Not all of these fields will be redacted eventually
|
||||
tests_api.AssertRedactedValues(t, respItem["Attrs"].(map[string]interface{})["PasswordAuthMethodAttributes"])
|
||||
|
||||
_ = os.WriteFile(eventConfig.AuditEvents.Name(), nil, 0o666) // clean out audit events from previous calls
|
||||
u, err = amClient.Read(tc.Context(), u.Item.Id)
|
||||
pw, err = amClient.Read(tc.Context(), pw.Item.Id)
|
||||
require.NoError(err)
|
||||
checkAuthMethod("read", u.Item, "bar", 1)
|
||||
checkAuthMethod("read", pw.Item, "bar", 1)
|
||||
|
||||
got = tests_api.CloudEventFromFile(t, eventConfig.AuditEvents.Name())
|
||||
tests_api.AssertRedactedValues(t, tests_api.GetEventDetails(t, got, "request"))
|
||||
|
||||
respItem = tests_api.GetEventDetails(t, got, "response")["item"].(map[string]interface{})
|
||||
tests_api.AssertRedactedValues(t, respItem)
|
||||
tests_api.AssertRedactedValues(t, respItem["attributes"])
|
||||
tests_api.AssertRedactedValues(t, respItem["Attrs"])
|
||||
// TODO(johanbrandhorst): Not all of these fields will be redacted eventually
|
||||
tests_api.AssertRedactedValues(t, respItem["Attrs"].(map[string]interface{})["PasswordAuthMethodAttributes"])
|
||||
|
||||
_ = os.WriteFile(eventConfig.AuditEvents.Name(), nil, 0o666) // clean out audit events from previous calls
|
||||
u, err = amClient.Update(tc.Context(), u.Item.Id, u.Item.Version, authmethods.WithName("buz"))
|
||||
pw, err = amClient.Update(tc.Context(), pw.Item.Id, pw.Item.Version, authmethods.WithName("buz"))
|
||||
require.NoError(err)
|
||||
checkAuthMethod("update", u.Item, "buz", 2)
|
||||
checkAuthMethod("update", pw.Item, "buz", 2)
|
||||
got = tests_api.CloudEventFromFile(t, eventConfig.AuditEvents.Name())
|
||||
|
||||
tests_api.AssertRedactedValues(t, tests_api.GetEventDetails(t, got, "request")["item"].(map[string]interface{}))
|
||||
|
||||
respItem = tests_api.GetEventDetails(t, got, "response")["item"].(map[string]interface{})
|
||||
tests_api.AssertRedactedValues(t, respItem)
|
||||
tests_api.AssertRedactedValues(t, respItem["attributes"])
|
||||
tests_api.AssertRedactedValues(t, respItem["Attrs"])
|
||||
// TODO(johanbrandhorst): Not all of these fields will be redacted eventually
|
||||
tests_api.AssertRedactedValues(t, respItem["Attrs"].(map[string]interface{})["PasswordAuthMethodAttributes"])
|
||||
|
||||
u, err = amClient.Update(tc.Context(), u.Item.Id, u.Item.Version, authmethods.DefaultName())
|
||||
require.NoError(err)
|
||||
checkAuthMethod("update", u.Item, "", 3)
|
||||
|
||||
_, err = amClient.Delete(tc.Context(), u.Item.Id)
|
||||
pw, err = amClient.Update(tc.Context(), pw.Item.Id, pw.Item.Version, authmethods.DefaultName())
|
||||
require.NoError(err)
|
||||
checkAuthMethod("update", pw.Item, "", 3)
|
||||
|
||||
_ = os.WriteFile(eventConfig.AuditEvents.Name(), nil, 0o666) // clean out audit events from previous calls
|
||||
// OIDC auth methods
|
||||
u, err = amClient.Create(tc.Context(), "oidc", global,
|
||||
oidc, err := amClient.Create(tc.Context(), "oidc", global,
|
||||
authmethods.WithName("foo"),
|
||||
authmethods.WithOidcAuthMethodApiUrlPrefix("https://api.com"),
|
||||
authmethods.WithOidcAuthMethodIssuer("https://example.com"),
|
||||
authmethods.WithOidcAuthMethodClientSecret("secret"),
|
||||
authmethods.WithOidcAuthMethodClientId("client-id"))
|
||||
require.NoError(err)
|
||||
checkAuthMethod("create", u.Item, "foo", 1)
|
||||
t.Cleanup(func() {
|
||||
_, err = amClient.Delete(tc.Context(), oidc.Item.Id)
|
||||
require.NoError(err)
|
||||
})
|
||||
checkAuthMethod("create", oidc.Item, "foo", 1)
|
||||
got = tests_api.CloudEventFromFile(t, eventConfig.AuditEvents.Name())
|
||||
|
||||
reqItem = tests_api.GetEventDetails(t, got, "request")["item"].(map[string]interface{})
|
||||
tests_api.AssertRedactedValues(t, reqItem)
|
||||
tests_api.AssertRedactedValues(t, reqItem["attributes"], "client_secret")
|
||||
tests_api.AssertRedactedValues(t, reqItem["Attrs"])
|
||||
// TODO(johanbrandhorst): Not all of these fields will be redacted eventually
|
||||
tests_api.AssertRedactedValues(t, reqItem["Attrs"].(map[string]interface{})["OidcAuthMethodsAttributes"], "callback_url", "state", "client_secret_hmac")
|
||||
|
||||
respItem = tests_api.GetEventDetails(t, got, "response")["item"].(map[string]interface{})
|
||||
tests_api.AssertRedactedValues(t, respItem)
|
||||
tests_api.AssertRedactedValues(t, respItem["attributes"])
|
||||
tests_api.AssertRedactedValues(t, respItem["Attrs"])
|
||||
// TODO(johanbrandhorst): Not all of these fields will be redacted eventually
|
||||
tests_api.AssertRedactedValues(t, respItem["Attrs"].(map[string]interface{})["OidcAuthMethodsAttributes"], "state", "client_secret_hmac", "callback_url")
|
||||
|
||||
u, err = amClient.Read(tc.Context(), u.Item.Id)
|
||||
oidc, err = amClient.Read(tc.Context(), oidc.Item.Id)
|
||||
require.NoError(err)
|
||||
checkAuthMethod("read", u.Item, "foo", 1)
|
||||
checkAuthMethod("read", oidc.Item, "foo", 1)
|
||||
|
||||
u, err = amClient.Update(tc.Context(), u.Item.Id, u.Item.Version, authmethods.WithName("bar"))
|
||||
oidc, err = amClient.Update(tc.Context(), oidc.Item.Id, oidc.Item.Version, authmethods.WithName("bar"))
|
||||
require.NoError(err)
|
||||
checkAuthMethod("update", u.Item, "bar", 2)
|
||||
checkAuthMethod("update", oidc.Item, "bar", 2)
|
||||
|
||||
u, err = amClient.Update(tc.Context(), u.Item.Id, u.Item.Version, authmethods.DefaultName())
|
||||
oidc, err = amClient.Update(tc.Context(), oidc.Item.Id, oidc.Item.Version, authmethods.DefaultName())
|
||||
require.NoError(err)
|
||||
checkAuthMethod("update", u.Item, "", 3)
|
||||
checkAuthMethod("update", oidc.Item, "", 3)
|
||||
}
|
||||
|
||||
_, err = amClient.Delete(tc.Context(), u.Item.Id)
|
||||
func TestList(t *testing.T) {
|
||||
assert, require := assert.New(t), require.New(t)
|
||||
tcConfig, err := config.DevController()
|
||||
require.NoError(err)
|
||||
|
||||
tc := controller.NewTestController(t, &controller.TestControllerOpts{Config: tcConfig})
|
||||
t.Cleanup(tc.Shutdown)
|
||||
|
||||
client := tc.Client()
|
||||
token := tc.Token()
|
||||
client.SetToken(token.Token)
|
||||
amClient := authmethods.NewClient(client)
|
||||
|
||||
result, err := amClient.List(tc.Context(), global)
|
||||
require.NoError(err)
|
||||
require.Len(result.Items, 2)
|
||||
genOIDCAM := result.Items[0]
|
||||
genPWAM := result.Items[1]
|
||||
|
||||
pwAM, err := amClient.Create(tc.Context(), "password", global,
|
||||
authmethods.WithName("bar"),
|
||||
authmethods.WithPasswordAuthMethodMinPasswordLength(10),
|
||||
)
|
||||
require.NoError(err)
|
||||
t.Cleanup(func() {
|
||||
_, err = amClient.Delete(tc.Context(), pwAM.Item.Id)
|
||||
require.NoError(err)
|
||||
})
|
||||
|
||||
result, err = amClient.List(tc.Context(), global)
|
||||
require.NoError(err)
|
||||
require.Len(result.Items, 3)
|
||||
assert.Empty(cmp.Diff(genOIDCAM, result.Items[0], cmpopts.IgnoreUnexported(authmethods.AuthMethod{})))
|
||||
assert.Empty(cmp.Diff(genPWAM, result.Items[1], cmpopts.IgnoreUnexported(authmethods.AuthMethod{})))
|
||||
assert.Empty(cmp.Diff(pwAM.Item, result.Items[2], cmpopts.IgnoreUnexported(authmethods.AuthMethod{})))
|
||||
|
||||
oidcAM, err := amClient.Create(tc.Context(), "oidc", global,
|
||||
authmethods.WithName("foo"),
|
||||
authmethods.WithOidcAuthMethodApiUrlPrefix("https://api.com"),
|
||||
authmethods.WithOidcAuthMethodIssuer("https://example.com"),
|
||||
authmethods.WithOidcAuthMethodClientSecret("secret"),
|
||||
authmethods.WithOidcAuthMethodClientId("client-id"))
|
||||
require.NoError(err)
|
||||
t.Cleanup(func() {
|
||||
_, err = amClient.Delete(tc.Context(), oidcAM.Item.Id)
|
||||
require.NoError(err)
|
||||
})
|
||||
|
||||
result, err = amClient.List(tc.Context(), global)
|
||||
require.NoError(err)
|
||||
require.Len(result.Items, 4)
|
||||
assert.Empty(cmp.Diff(genOIDCAM, result.Items[0], cmpopts.IgnoreUnexported(authmethods.AuthMethod{})))
|
||||
assert.Empty(cmp.Diff(oidcAM.Item, result.Items[1], cmpopts.IgnoreUnexported(authmethods.AuthMethod{})))
|
||||
assert.Empty(cmp.Diff(genPWAM, result.Items[2], cmpopts.IgnoreUnexported(authmethods.AuthMethod{})))
|
||||
assert.Empty(cmp.Diff(pwAM.Item, result.Items[3], cmpopts.IgnoreUnexported(authmethods.AuthMethod{})))
|
||||
|
||||
result, err = amClient.List(tc.Context(), global,
|
||||
authmethods.WithFilter(`"/item/attributes/client_id"=="client-id"`))
|
||||
require.NoError(err)
|
||||
require.Len(result.Items, 1)
|
||||
assert.Empty(cmp.Diff(oidcAM.Item, result.Items[0], cmpopts.IgnoreUnexported(authmethods.AuthMethod{})))
|
||||
|
||||
result, err = amClient.List(tc.Context(), global,
|
||||
authmethods.WithFilter(`"/item/attributes/min_login_name_length"==3`))
|
||||
require.NoError(err)
|
||||
require.Len(result.Items, 2)
|
||||
assert.Empty(cmp.Diff(genPWAM, result.Items[0], cmpopts.IgnoreUnexported(authmethods.AuthMethod{})))
|
||||
assert.Empty(cmp.Diff(pwAM.Item, result.Items[1], cmpopts.IgnoreUnexported(authmethods.AuthMethod{})))
|
||||
|
||||
result, err = amClient.List(tc.Context(), global,
|
||||
authmethods.WithFilter(`"/item/attributes/min_password_length"==10`))
|
||||
require.NoError(err)
|
||||
require.Len(result.Items, 1)
|
||||
assert.Empty(cmp.Diff(pwAM.Item, result.Items[0], cmpopts.IgnoreUnexported(authmethods.AuthMethod{})))
|
||||
}
|
||||
|
||||
func TestCustomMethods(t *testing.T) {
|
||||
@@ -193,11 +286,14 @@ func TestCustomMethods(t *testing.T) {
|
||||
|
||||
reqDetails := tests_api.GetEventDetails(t, got, "request")
|
||||
tests_api.AssertRedactedValues(t, reqDetails)
|
||||
tests_api.AssertRedactedValues(t, reqDetails["attributes"])
|
||||
tests_api.AssertRedactedValues(t, reqDetails["Attrs"])
|
||||
// TODO(johanbrandhorst): Not all of these fields will be redacted eventually
|
||||
tests_api.AssertRedactedValues(t, reqDetails["Attrs"].(map[string]interface{})["OidcChangeStateAttributes"], "state")
|
||||
|
||||
respItem := tests_api.GetEventDetails(t, got, "response")["item"].(map[string]interface{})
|
||||
tests_api.AssertRedactedValues(t, respItem)
|
||||
tests_api.AssertRedactedValues(t, respItem["attributes"])
|
||||
// TODO(johanbrandhorst): Not all of these fields will be redacted eventually
|
||||
tests_api.AssertRedactedValues(t, respItem["Attrs"].(map[string]interface{})["OidcAuthMethodsAttributes"], "signing_algorithms", "callback_url", "idp_ca_certs", "state", "client_secret_hmac")
|
||||
|
||||
_, err = amClient.ChangeState(tc.Context(), u.Item.Id, u.Item.Version, "", authmethods.WithOidcAuthMethodDisableDiscoveredConfigValidation(true))
|
||||
assert.Error(err)
|
||||
|
||||
@@ -0,0 +1,185 @@
|
||||
package authmethods_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/boundary/sdk/pbs/controller/api"
|
||||
pb "github.com/hashicorp/boundary/sdk/pbs/controller/api/resources/authmethods"
|
||||
"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"
|
||||
"google.golang.org/protobuf/types/known/structpb"
|
||||
"google.golang.org/protobuf/types/known/wrapperspb"
|
||||
)
|
||||
|
||||
func TestAuthMethod_Tags(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
now := time.Now()
|
||||
wrapper := wrapper.TestWrapper(t)
|
||||
testEncryptingFilter := api.NewEncryptFilter(t, wrapper)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
testEvent *eventlogger.Event
|
||||
wantEvent *eventlogger.Event
|
||||
}{
|
||||
{
|
||||
name: "validate-oidc-filtering",
|
||||
testEvent: &eventlogger.Event{
|
||||
Type: "test",
|
||||
CreatedAt: now,
|
||||
Payload: &pb.AuthMethod{
|
||||
Id: "id",
|
||||
ScopeId: "scope-id",
|
||||
Name: &wrapperspb.StringValue{Value: "name"},
|
||||
Description: &wrapperspb.StringValue{Value: "description"},
|
||||
Type: "oidc",
|
||||
Attrs: &pb.AuthMethod_OidcAuthMethodsAttributes{
|
||||
OidcAuthMethodsAttributes: &pb.OidcAuthMethodAttributes{
|
||||
State: "public-state",
|
||||
Issuer: wrapperspb.String("public-issuer"),
|
||||
ClientId: wrapperspb.String("public-client_id"),
|
||||
ClientSecretHmac: "public-client_secret_hmac",
|
||||
MaxAge: wrapperspb.UInt32(100),
|
||||
SigningAlgorithms: []string{"public-signing_algorithms"},
|
||||
IdpCaCerts: []string{"public-idp_ca_certs"},
|
||||
ApiUrlPrefix: wrapperspb.String("public-api_url_prefix"),
|
||||
CallbackUrl: "public-callback_url",
|
||||
AllowedAudiences: []string{"public-allowed_audiences"},
|
||||
ClaimsScopes: []string{"public-claims_scopes"},
|
||||
AccountClaimMaps: []string{"public-account_claim_maps"},
|
||||
DisableDiscoveredConfigValidation: false,
|
||||
DryRun: false,
|
||||
ClientSecret: wrapperspb.String("secret-client_secret"),
|
||||
},
|
||||
},
|
||||
AuthorizedActions: []string{"action-1", "action-2"},
|
||||
AuthorizedCollectionActions: map[string]*structpb.ListValue{
|
||||
"auth-methods": {
|
||||
Values: []*structpb.Value{
|
||||
structpb.NewStringValue("create"),
|
||||
structpb.NewStringValue("list"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
wantEvent: &eventlogger.Event{
|
||||
Type: "test",
|
||||
CreatedAt: now,
|
||||
Payload: &pb.AuthMethod{
|
||||
Id: "id",
|
||||
ScopeId: "scope-id",
|
||||
Name: &wrapperspb.StringValue{Value: "name"},
|
||||
Description: &wrapperspb.StringValue{Value: "description"},
|
||||
Type: "oidc",
|
||||
// TODO(johanbrandhorst): update redaction once typed attributes are available
|
||||
Attrs: &pb.AuthMethod_OidcAuthMethodsAttributes{
|
||||
OidcAuthMethodsAttributes: &pb.OidcAuthMethodAttributes{
|
||||
State: encrypt.RedactedData,
|
||||
Issuer: wrapperspb.String(encrypt.RedactedData),
|
||||
ClientId: wrapperspb.String(encrypt.RedactedData),
|
||||
ClientSecretHmac: encrypt.RedactedData,
|
||||
MaxAge: wrapperspb.UInt32(100),
|
||||
SigningAlgorithms: []string{encrypt.RedactedData},
|
||||
IdpCaCerts: []string{encrypt.RedactedData},
|
||||
ApiUrlPrefix: wrapperspb.String(encrypt.RedactedData),
|
||||
CallbackUrl: encrypt.RedactedData,
|
||||
AllowedAudiences: []string{encrypt.RedactedData},
|
||||
ClaimsScopes: []string{encrypt.RedactedData},
|
||||
AccountClaimMaps: []string{encrypt.RedactedData},
|
||||
DisableDiscoveredConfigValidation: false,
|
||||
DryRun: false,
|
||||
ClientSecret: wrapperspb.String(encrypt.RedactedData),
|
||||
},
|
||||
},
|
||||
AuthorizedActions: []string{"action-1", "action-2"},
|
||||
AuthorizedCollectionActions: map[string]*structpb.ListValue{
|
||||
"auth-methods": {
|
||||
Values: []*structpb.Value{
|
||||
structpb.NewStringValue("create"),
|
||||
structpb.NewStringValue("list"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "validate-password-filtering",
|
||||
testEvent: &eventlogger.Event{
|
||||
Type: "test",
|
||||
CreatedAt: now,
|
||||
Payload: &pb.AuthMethod{
|
||||
Id: "id",
|
||||
ScopeId: "scope-id",
|
||||
Name: &wrapperspb.StringValue{Value: "name"},
|
||||
Description: &wrapperspb.StringValue{Value: "description"},
|
||||
Type: "password",
|
||||
Attrs: &pb.AuthMethod_PasswordAuthMethodAttributes{
|
||||
PasswordAuthMethodAttributes: &pb.PasswordAuthMethodAttributes{
|
||||
MinLoginNameLength: 100,
|
||||
MinPasswordLength: 100,
|
||||
},
|
||||
},
|
||||
AuthorizedActions: []string{"action-1", "action-2"},
|
||||
AuthorizedCollectionActions: map[string]*structpb.ListValue{
|
||||
"auth-methods": {
|
||||
Values: []*structpb.Value{
|
||||
structpb.NewStringValue("create"),
|
||||
structpb.NewStringValue("list"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
wantEvent: &eventlogger.Event{
|
||||
Type: "test",
|
||||
CreatedAt: now,
|
||||
Payload: &pb.AuthMethod{
|
||||
Id: "id",
|
||||
ScopeId: "scope-id",
|
||||
Name: &wrapperspb.StringValue{Value: "name"},
|
||||
Description: &wrapperspb.StringValue{Value: "description"},
|
||||
Type: "password",
|
||||
// TODO(johanbrandhorst): update redaction once typed attributes are available
|
||||
Attrs: &pb.AuthMethod_PasswordAuthMethodAttributes{
|
||||
PasswordAuthMethodAttributes: &pb.PasswordAuthMethodAttributes{
|
||||
MinLoginNameLength: 100,
|
||||
MinPasswordLength: 100,
|
||||
},
|
||||
},
|
||||
AuthorizedActions: []string{"action-1", "action-2"},
|
||||
AuthorizedCollectionActions: map[string]*structpb.ListValue{
|
||||
"auth-methods": {
|
||||
Values: []*structpb.Value{
|
||||
structpb.NewStringValue("create"),
|
||||
structpb.NewStringValue("list"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
assert, require := assert.New(t), require.New(t)
|
||||
got, err := testEncryptingFilter.Process(ctx, tt.testEvent)
|
||||
require.NoError(err)
|
||||
require.NotNil(got)
|
||||
actualJson, err := json.Marshal(got)
|
||||
require.NoError(err)
|
||||
t.Log(string(actualJson))
|
||||
|
||||
wantJson, err := json.Marshal(tt.wantEvent)
|
||||
require.NoError(err)
|
||||
assert.JSONEq(string(wantJson), string(actualJson))
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
package authmethods_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/boundary/internal/gen/controller/api/services"
|
||||
"github.com/hashicorp/boundary/sdk/pbs/controller/api"
|
||||
"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"
|
||||
)
|
||||
|
||||
// TestAuthenticate_Tags will test that the response filtering aligns with the
|
||||
// AuthenticateResponse and AuthenticateResponse tags. See:
|
||||
// internal/tests/api/authmethods/authenticate_test.go TestAuthenticate where
|
||||
// the audit events produced using these tags is unit tested.
|
||||
func TestAuthenticate_Tags(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
now := time.Now()
|
||||
wrapper := wrapper.TestWrapper(t)
|
||||
testEncryptingFilter := api.NewEncryptFilter(t, wrapper)
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
testEvent *eventlogger.Event
|
||||
wantEvent *eventlogger.Event
|
||||
}{
|
||||
{
|
||||
name: "validate-response-filtering",
|
||||
testEvent: &eventlogger.Event{
|
||||
Type: "test",
|
||||
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"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
wantEvent: &eventlogger.Event{
|
||||
Type: "test",
|
||||
CreatedAt: now,
|
||||
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),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "validate-request-filtering",
|
||||
testEvent: &eventlogger.Event{
|
||||
Type: "test",
|
||||
CreatedAt: now,
|
||||
Payload: &services.AuthenticateRequest{
|
||||
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"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
wantEvent: &eventlogger.Event{
|
||||
Type: "test",
|
||||
CreatedAt: now,
|
||||
Payload: &services.AuthenticateRequest{
|
||||
AuthMethodId: "public-auth-method-id",
|
||||
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),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
assert, require := assert.New(t), require.New(t)
|
||||
got, err := testEncryptingFilter.Process(ctx, tt.testEvent)
|
||||
require.NoError(err)
|
||||
require.NotNil(got)
|
||||
actualJson, err := json.Marshal(got)
|
||||
require.NoError(err)
|
||||
t.Log(string(actualJson))
|
||||
|
||||
wantJson, err := json.Marshal(tt.wantEvent)
|
||||
require.NoError(err)
|
||||
assert.JSONEq(string(wantJson), string(actualJson))
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user