Identity: Rename "namespace" to "type" in the requester interface (#90567)
This commit is contained in:
@@ -69,11 +69,11 @@ func (a *Anonymous) Test(ctx context.Context, r *authn.Request) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (a *Anonymous) Namespace() string {
|
||||
return authn.NamespaceAnonymous.String()
|
||||
func (a *Anonymous) IdentityType() identity.IdentityType {
|
||||
return identity.TypeAnonymous
|
||||
}
|
||||
|
||||
func (a *Anonymous) ResolveIdentity(ctx context.Context, orgID int64, namespaceID identity.NamespaceID) (*authn.Identity, error) {
|
||||
func (a *Anonymous) ResolveIdentity(ctx context.Context, orgID int64, namespaceID identity.TypedID) (*authn.Identity, error) {
|
||||
o, err := a.orgService.GetByName(ctx, &org.GetOrgByNameQuery{Name: a.cfg.AnonymousOrgName})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -84,7 +84,7 @@ func (a *Anonymous) ResolveIdentity(ctx context.Context, orgID int64, namespaceI
|
||||
}
|
||||
|
||||
// Anonymous identities should always have the same namespace id.
|
||||
if namespaceID != authn.AnonymousNamespaceID {
|
||||
if namespaceID != identity.AnonymousTypedID {
|
||||
return nil, errInvalidID
|
||||
}
|
||||
|
||||
@@ -109,7 +109,7 @@ func (a *Anonymous) Priority() uint {
|
||||
|
||||
func (a *Anonymous) newAnonymousIdentity(o *org.Org) *authn.Identity {
|
||||
return &authn.Identity{
|
||||
ID: authn.AnonymousNamespaceID,
|
||||
ID: identity.AnonymousTypedID,
|
||||
OrgID: o.ID,
|
||||
OrgName: o.Name,
|
||||
OrgRoles: map[int64]org.RoleType{o.ID: org.RoleType(a.cfg.AnonymousOrgRole)},
|
||||
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/grafana/grafana/pkg/apimachinery/identity"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/services/anonymous/anontest"
|
||||
"github.com/grafana/grafana/pkg/services/authn"
|
||||
@@ -52,17 +53,17 @@ func TestAnonymous_Authenticate(t *testing.T) {
|
||||
anonDeviceService: anontest.NewFakeService(),
|
||||
}
|
||||
|
||||
identity, err := c.Authenticate(context.Background(), &authn.Request{})
|
||||
user, err := c.Authenticate(context.Background(), &authn.Request{})
|
||||
if err != nil {
|
||||
require.Error(t, err)
|
||||
require.Nil(t, identity)
|
||||
require.Nil(t, user)
|
||||
} else {
|
||||
require.Nil(t, err)
|
||||
|
||||
assert.Equal(t, authn.AnonymousNamespaceID, identity.ID)
|
||||
assert.Equal(t, tt.org.ID, identity.OrgID)
|
||||
assert.Equal(t, tt.org.Name, identity.OrgName)
|
||||
assert.Equal(t, tt.cfg.AnonymousOrgRole, string(identity.GetOrgRole()))
|
||||
assert.Equal(t, identity.AnonymousTypedID, user.ID)
|
||||
assert.Equal(t, tt.org.ID, user.OrgID)
|
||||
assert.Equal(t, tt.org.Name, user.OrgName)
|
||||
assert.Equal(t, tt.cfg.AnonymousOrgRole, string(user.GetOrgRole()))
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -73,7 +74,7 @@ func TestAnonymous_ResolveIdentity(t *testing.T) {
|
||||
desc string
|
||||
cfg *setting.Cfg
|
||||
orgID int64
|
||||
namespaceID authn.NamespaceID
|
||||
namespaceID identity.TypedID
|
||||
org *org.Org
|
||||
orgErr error
|
||||
expectedErr error
|
||||
@@ -87,7 +88,7 @@ func TestAnonymous_ResolveIdentity(t *testing.T) {
|
||||
AnonymousOrgName: "some org",
|
||||
},
|
||||
orgID: 1,
|
||||
namespaceID: authn.AnonymousNamespaceID,
|
||||
namespaceID: identity.AnonymousTypedID,
|
||||
expectedErr: errInvalidOrg,
|
||||
},
|
||||
{
|
||||
@@ -97,7 +98,7 @@ func TestAnonymous_ResolveIdentity(t *testing.T) {
|
||||
AnonymousOrgName: "some org",
|
||||
},
|
||||
orgID: 1,
|
||||
namespaceID: authn.MustParseNamespaceID("anonymous:1"),
|
||||
namespaceID: identity.MustParseTypedID("anonymous:1"),
|
||||
expectedErr: errInvalidID,
|
||||
},
|
||||
{
|
||||
@@ -107,7 +108,7 @@ func TestAnonymous_ResolveIdentity(t *testing.T) {
|
||||
AnonymousOrgName: "some org",
|
||||
},
|
||||
orgID: 1,
|
||||
namespaceID: authn.AnonymousNamespaceID,
|
||||
namespaceID: identity.AnonymousTypedID,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user