mirror of
https://github.com/openziti/ziti.git
synced 2026-11-25 00:41:54 +00:00
ad540d9988
- returns the dispatch error from CreateWithAuthenticators instead of a nil tuple, so CA and token enrollment no longer treat a failed identity create as success - returns the ValidateNameOnUpdate error from updateEntity and updateEntityBatch, so a rename to a taken or empty name is rejected instead of silently skipped - tests both at the manager level and the rename through the service API
59 lines
1.9 KiB
Go
59 lines
1.9 KiB
Go
package model
|
|
|
|
import (
|
|
"errors"
|
|
"testing"
|
|
|
|
"github.com/openziti/foundation/v2/errorz"
|
|
"github.com/openziti/ziti/v2/controller/change"
|
|
"github.com/openziti/ziti/v2/controller/db"
|
|
"github.com/openziti/ziti/v2/controller/idgen"
|
|
"github.com/openziti/ziti/v2/controller/storage/boltz"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func Test_CreateWithAuthenticators_ReturnsDispatchError(t *testing.T) {
|
|
ctx := NewTestContext(t)
|
|
defer ctx.Cleanup()
|
|
req := require.New(t)
|
|
|
|
existing := ctx.requireNewIdentity(false)
|
|
|
|
duplicate := &Identity{Name: existing.Name, IdentityTypeId: db.DefaultIdentityType}
|
|
authenticator := &Authenticator{Method: db.MethodAuthenticatorCert}
|
|
authenticator.SubType = &AuthenticatorCert{Authenticator: authenticator, Fingerprint: idgen.MustNewUUIDString()}
|
|
|
|
id, authenticatorIds, err := ctx.managers.Identity.CreateWithAuthenticators(duplicate, []*Authenticator{authenticator}, change.New())
|
|
req.Error(err, "a create that fails in Apply reports the failure")
|
|
req.Empty(id)
|
|
req.Nil(authenticatorIds)
|
|
|
|
_, err = ctx.managers.Identity.Read(duplicate.Id)
|
|
req.True(boltz.IsErrNotFoundErr(err), "the identity was not created")
|
|
}
|
|
|
|
func Test_Update_RejectsDuplicateAndEmptyName(t *testing.T) {
|
|
ctx := NewTestContext(t)
|
|
defer ctx.Cleanup()
|
|
req := require.New(t)
|
|
|
|
first := ctx.requireNewService()
|
|
second := ctx.requireNewService()
|
|
originalName := second.Name
|
|
|
|
second.Name = first.Name
|
|
err := ctx.managers.EdgeService.Update(second, nil, change.New())
|
|
req.Error(err, "renaming to a name already in use is an error")
|
|
var fe *errorz.FieldError
|
|
req.True(errors.As(err, &fe))
|
|
req.Equal("name", fe.FieldName)
|
|
|
|
second.Name = ""
|
|
err = ctx.managers.EdgeService.Update(second, nil, change.New())
|
|
req.Error(err, "renaming to an empty name is an error")
|
|
|
|
stored, err := ctx.managers.EdgeService.Read(second.Id)
|
|
req.NoError(err)
|
|
req.Equal(originalName, stored.Name, "a rejected rename leaves the stored name unchanged")
|
|
}
|