mirror of
https://github.com/gravitational/teleport.git
synced 2026-09-24 16:17:11 +08:00
* refactor: move msgraph models from /lib/msgraph to /lib/msgraph/models package * test: use msgraphtest server to test TestIterateUsers_Empty * add comments to exported types * lint: fix import cadence * test: DecodeGroupMember * test: add license header
130 lines
3.9 KiB
Go
130 lines
3.9 KiB
Go
// Teleport
|
|
// Copyright (C) 2025 Gravitational, Inc.
|
|
//
|
|
// This program is free software: you can redistribute it and/or modify
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
// (at your option) any later version.
|
|
//
|
|
// This program is distributed in the hope that it will be useful,
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
// GNU Affero General Public License for more details.
|
|
//
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
package msgraphtest
|
|
|
|
import (
|
|
"github.com/Azure/azure-sdk-for-go/sdk/azcore/to"
|
|
|
|
"github.com/gravitational/teleport/api/types"
|
|
"github.com/gravitational/teleport/lib/msgraph/models"
|
|
)
|
|
|
|
// Storage to be used by the Server
|
|
type Storage struct {
|
|
Users map[string]*models.User
|
|
Groups map[string]*models.Group
|
|
GroupMembers map[string][]models.GroupMember
|
|
GroupOwners map[string][]*models.User
|
|
Applications map[string]*models.Application
|
|
}
|
|
|
|
// NewStorage creates a new empty Storage.
|
|
func NewStorage() *Storage {
|
|
return &Storage{
|
|
Users: make(map[string]*models.User),
|
|
Groups: make(map[string]*models.Group),
|
|
GroupMembers: make(map[string][]models.GroupMember),
|
|
GroupOwners: make(map[string][]*models.User),
|
|
Applications: make(map[string]*models.Application),
|
|
}
|
|
}
|
|
|
|
// NewDefaultStorage creates a new Storage with hardcoded test data.
|
|
func NewDefaultStorage() *Storage {
|
|
alice := &models.User{
|
|
DirectoryObject: models.DirectoryObject{
|
|
ID: to.Ptr("alice@example.com"),
|
|
DisplayName: to.Ptr("Alice Alison"),
|
|
},
|
|
GivenName: to.Ptr("Alice"),
|
|
Surname: to.Ptr("Alison"),
|
|
Mail: to.Ptr("alice@example.com"),
|
|
UserPrincipalName: to.Ptr("alice@example.com"),
|
|
}
|
|
bob := &models.User{
|
|
DirectoryObject: models.DirectoryObject{
|
|
ID: to.Ptr("bob@example.com"),
|
|
DisplayName: to.Ptr("Bob Bobert"),
|
|
},
|
|
GivenName: to.Ptr("Bob"),
|
|
Surname: to.Ptr("Bobert"),
|
|
Mail: to.Ptr("bob@example.com"),
|
|
UserPrincipalName: to.Ptr("bob@example.com"),
|
|
}
|
|
carol := &models.User{
|
|
DirectoryObject: models.DirectoryObject{
|
|
ID: to.Ptr("carol@example.com"),
|
|
DisplayName: to.Ptr("Carol C"),
|
|
},
|
|
GivenName: to.Ptr("Carol"),
|
|
Surname: to.Ptr("C"),
|
|
Mail: to.Ptr("carol@example.com"),
|
|
UserPrincipalName: to.Ptr("carol@example.com"),
|
|
}
|
|
|
|
group1 := &models.Group{
|
|
DirectoryObject: models.DirectoryObject{
|
|
ID: to.Ptr("group1"),
|
|
DisplayName: to.Ptr("group1"),
|
|
},
|
|
GroupTypes: []string{types.EntraIDSecurityGroups},
|
|
}
|
|
group2 := &models.Group{
|
|
DirectoryObject: models.DirectoryObject{
|
|
ID: to.Ptr("group2"),
|
|
DisplayName: to.Ptr("group2"),
|
|
},
|
|
GroupTypes: []string{types.EntraIDSecurityGroups},
|
|
}
|
|
group3 := &models.Group{
|
|
DirectoryObject: models.DirectoryObject{
|
|
ID: to.Ptr("group3"),
|
|
DisplayName: to.Ptr("group3"),
|
|
},
|
|
GroupTypes: []string{types.EntraIDSecurityGroups},
|
|
}
|
|
|
|
app1 := &models.Application{
|
|
DirectoryObject: models.DirectoryObject{
|
|
ID: to.Ptr("app1"),
|
|
DisplayName: to.Ptr("test SAML App"),
|
|
},
|
|
AppID: to.Ptr("app1"),
|
|
}
|
|
|
|
storage := NewStorage()
|
|
|
|
storage.Users[*alice.ID] = alice
|
|
storage.Users[*bob.ID] = bob
|
|
storage.Users[*carol.ID] = carol
|
|
|
|
storage.Groups[*group1.ID] = group1
|
|
storage.Groups[*group2.ID] = group2
|
|
storage.Groups[*group3.ID] = group3
|
|
|
|
storage.GroupMembers["group1"] = []models.GroupMember{alice, group2}
|
|
storage.GroupMembers["group2"] = []models.GroupMember{alice, bob, carol}
|
|
storage.GroupMembers["group3"] = []models.GroupMember{alice, bob, carol}
|
|
|
|
storage.GroupOwners["group1"] = []*models.User{alice, bob}
|
|
storage.GroupOwners["group3"] = []*models.User{bob, carol}
|
|
|
|
storage.Applications[*app1.AppID] = app1
|
|
|
|
return storage
|
|
}
|