From 4f3a042fd0067fccf19b0ea1f0ce5d0253f3624e Mon Sep 17 00:00:00 2001 From: Steven Wade <99294987+StevenWadeOddball@users.noreply.github.com> Date: Tue, 16 Jul 2024 07:16:18 -0700 Subject: [PATCH] [EASI-4507] Improve Local User Accounts (#2689) * feat: replace localGetUserInfo from helpers to use local mock dev data okta api * feat: dev data using mock data test data * feat: add username to Intake relation to existing systm * fix correct dev data using system intake id as user name. Replace with Username references * fix linting * feat: update some snapshots * fix: make email addresses all lower case * fix email casing for resolver tests * feat: update seeder to seed with the `mock.PrincipalUser` * feat: refactor how we fetch mock user roles for cedar systems, so we have an explicit linking for Cypress tests * feat: update snapshots --- cmd/devdata/main.go | 31 +- cmd/devdata/mock/mock.go | 70 +- cmd/devdata/system_intake.go | 13 +- pkg/graph/resolvers/resolver_test.go | 48 +- pkg/local/authentication_middleware.go | 4 +- pkg/local/cedarcoremock/roles.go | 10 +- pkg/local/okta_api.go | 1082 +++++++++++--------- pkg/okta/authentication_middleware_test.go | 21 +- pkg/userhelpers/user_account_utils.go | 16 - 9 files changed, 731 insertions(+), 564 deletions(-) diff --git a/cmd/devdata/main.go b/cmd/devdata/main.go index 75b3c8df2c..c9ef2fea5d 100644 --- a/cmd/devdata/main.go +++ b/cmd/devdata/main.go @@ -11,16 +11,19 @@ import ( "github.com/cms-enterprise/easi-app/cmd/devdata/mock" "github.com/cms-enterprise/easi-app/pkg/appconfig" + "github.com/cms-enterprise/easi-app/pkg/local" "github.com/cms-enterprise/easi-app/pkg/models" "github.com/cms-enterprise/easi-app/pkg/storage" "github.com/cms-enterprise/easi-app/pkg/testhelpers" "github.com/cms-enterprise/easi-app/pkg/upload" + "github.com/cms-enterprise/easi-app/pkg/usersearch" ) type seederConfig struct { - logger *zap.Logger - store *storage.Store - s3Client *upload.S3Client + logger *zap.Logger + store *storage.Store + s3Client *upload.S3Client + UserSearchClient usersearch.Client } func main() { @@ -60,10 +63,14 @@ func main() { s3Client := upload.NewS3Client(s3Cfg) ctx := mock.CtxWithLoggerAndPrincipal(logger, store, mock.PrincipalUser) + + localOktaClient := local.NewOktaAPIClient() + seederConfig := &seederConfig{ - logger: logger, - store: store, - s3Client: &s3Client, + logger: logger, + store: store, + s3Client: &s3Client, + UserSearchClient: localOktaClient, } var intake *models.SystemIntake @@ -552,6 +559,7 @@ func main() { logger, store, intakeID, + mock.PrincipalUser, []string{"12345", "67890"}, ) @@ -562,6 +570,7 @@ func main() { logger, store, intakeID, + mock.PrincipalUser, []string{"00001", "00002"}, []string{ "{11AB1A00-1234-5678-ABC1-1A001B00CC0A}", @@ -575,6 +584,7 @@ func main() { logger, store, intakeID, + mock.PrincipalUser, []string{"00003", "00004"}, []string{ "{11AB1A00-1234-5678-ABC1-1A001B00CC0A}", @@ -588,6 +598,7 @@ func main() { logger, store, intakeID, + mock.PrincipalUser, []string{"00003", "00004"}, []string{ "{11AB1A00-1234-5678-ABC1-1A001B00CC1B}", @@ -601,6 +612,7 @@ func main() { logger, store, intakeID, + mock.PrincipalUser, []string{"00005", "00001"}, []string{ "{11AB1A00-1234-5678-ABC1-1A001B00CC5F}", @@ -614,6 +626,7 @@ func main() { logger, store, intakeID, + mock.PrincipalUser, "My Cool Existing Contract/Service", []string{"00001"}, ) @@ -625,13 +638,14 @@ func main() { logger, store, intakeID, + mock.PrincipalUser, []string{"12345", "67890"}, []string{ "{11AB1A00-1234-5678-ABC1-1A001B00CC0A}", "{11AB1A00-1234-5678-ABC1-1A001B00CC1B}", }, ) - unlinkSystemIntakeRelation(logger, store, intakeID) + unlinkSystemIntakeRelation(logger, store, intakeID, mock.PrincipalUser) // 5. Link deactivated Systems intakeID = uuid.MustParse("04cb8a97-3515-4071-9b80-2710834cd94c") @@ -640,6 +654,7 @@ func main() { logger, store, intakeID, + mock.PrincipalUser, []string{"12345", "67890"}, []string{ "{11AB1A00-1234-5678-ABC1-1A001B00CC5F}", @@ -668,7 +683,7 @@ func main() { intake = makeSystemIntakeAndProgressToStep( "For business case Cypress test", &intakeID, - "E2E1", + mock.EndToEnd1User, logger, store, models.SystemIntakeStepToProgressToDraftBusinessCase, diff --git a/cmd/devdata/mock/mock.go b/cmd/devdata/mock/mock.go index d080cc0751..b8778b1a3d 100644 --- a/cmd/devdata/mock/mock.go +++ b/cmd/devdata/mock/mock.go @@ -8,50 +8,70 @@ import ( "github.com/cms-enterprise/easi-app/pkg/appcontext" "github.com/cms-enterprise/easi-app/pkg/authentication" + "github.com/cms-enterprise/easi-app/pkg/local" "github.com/cms-enterprise/easi-app/pkg/models" "github.com/cms-enterprise/easi-app/pkg/storage" "github.com/cms-enterprise/easi-app/pkg/userhelpers" ) -// PrincipalUser is the "current user" when seeding the data -const PrincipalUser = "ABCD" +// These represent some users who have mocked okta data +const ( + // PrincipalUser is the "current user" when seeding the data (Adeline Aarons) + PrincipalUser = "ABCD" + + // TestUser is the "TEST user" when seeding the data (Terry Thompson) + TestUser = "TEST" + + // EndToEnd1User is the username of the user for some end to end testing + EndToEnd1User = "E2E1" + + // EndToEnd2User is the username of the user for some end to end testing + EndToEnd2User = "E2E2" + + AllyUser = "A11Y" + GaryUser = "GRTB" + AubryUser = "ADMI" + User1User = "USR1" + User2User = "USR2" + User3User = "USR3" + User4User = "USR4" + User5User = "USR5" + TheoUser = "CJRW" +) + +var UserNamesForCedarSystemRoles = []string{ + PrincipalUser, TestUser, EndToEnd1User, EndToEnd2User, AllyUser, GaryUser, AubryUser, User1User, User2User, User3User, User4User, User5User, TheoUser, + // Duplicate so we don't run out of users for roles + PrincipalUser, TestUser, EndToEnd1User, EndToEnd2User, AllyUser, GaryUser, AubryUser, User1User, User2User, User3User, User4User, User5User, TheoUser, + PrincipalUser, TestUser, EndToEnd1User, EndToEnd2User, AllyUser, GaryUser, AubryUser, User1User, User2User, User3User, User4User, User5User, TheoUser} // FetchUserInfoMock mocks the fetch user info logic -func FetchUserInfoMock(ctx context.Context, eua string) (*models.UserInfo, error) { - return &models.UserInfo{ - Username: eua, - FirstName: eua, - LastName: "Doe", - DisplayName: eua + "Doe", - Email: models.EmailAddress(eua + "@example.com"), - }, nil +func FetchUserInfoMock(ctx context.Context, username string) (*models.UserInfo, error) { + localOktaClient := local.NewOktaAPIClient() + return localOktaClient.FetchUserInfo(ctx, username) } // FetchUserInfosMock mocks the fetch user info logic -func FetchUserInfosMock(ctx context.Context, euas []string) ([]*models.UserInfo, error) { - userInfos := make([]*models.UserInfo, 0, len(euas)) - for _, eua := range euas { - userInfo, err := FetchUserInfoMock(ctx, eua) - if err != nil { - return nil, err - } - userInfos = append(userInfos, userInfo) - } - return userInfos, nil +func FetchUserInfosMock(ctx context.Context, usernames []string) ([]*models.UserInfo, error) { + localOktaClient := local.NewOktaAPIClient() + return localOktaClient.FetchUserInfos(ctx, usernames) } // CtxWithLoggerAndPrincipal makes a context with a mocked logger and principal -func CtxWithLoggerAndPrincipal(logger *zap.Logger, store *storage.Store, euaID string) context.Context { - if len(euaID) < 1 { - euaID = PrincipalUser +func CtxWithLoggerAndPrincipal(logger *zap.Logger, store *storage.Store, username string) context.Context { + //Future Enhancement: Consider adding this to the seederConfig, and also emb + if len(username) < 1 { + username = PrincipalUser } - userAccount, err := userhelpers.GetOrCreateUserAccount(context.Background(), store, store, euaID, true, userhelpers.GetOktaAccountInfoWrapperFunction(userhelpers.GetUserInfoFromOktaLocal)) + + //Future Enhancement: consider passing the context with the seeder, and using the seeder.UserSearchClient to return mocked data instead of needing to initialize a client for each mock call + userAccount, err := userhelpers.GetOrCreateUserAccount(context.Background(), store, store, username, true, userhelpers.GetUserInfoAccountInfoWrapperFunc(FetchUserInfoMock)) if err != nil { panic(fmt.Errorf("failed to get or create user account for mock data: %w", err)) } princ := &authentication.EUAPrincipal{ - EUAID: euaID, + EUAID: username, JobCodeEASi: true, JobCodeGRT: true, UserAccount: userAccount, diff --git a/cmd/devdata/system_intake.go b/cmd/devdata/system_intake.go index 7f37f7655b..86bb5d8d16 100644 --- a/cmd/devdata/system_intake.go +++ b/cmd/devdata/system_intake.go @@ -260,9 +260,10 @@ func setSystemIntakeRelationNewSystem( logger *zap.Logger, store *storage.Store, intakeID uuid.UUID, + username string, contractNumbers []string, ) { - ctx := mock.CtxWithLoggerAndPrincipal(logger, store, intakeID.String()) + ctx := mock.CtxWithLoggerAndPrincipal(logger, store, username) input := &models.SetSystemIntakeRelationNewSystemInput{ SystemIntakeID: intakeID, ContractNumbers: contractNumbers, @@ -285,10 +286,11 @@ func setSystemIntakeRelationExistingSystem( logger *zap.Logger, store *storage.Store, intakeID uuid.UUID, + username string, contractNumbers []string, cedarSystemIDs []string, ) { - ctx := mock.CtxWithLoggerAndPrincipal(logger, store, intakeID.String()) + ctx := mock.CtxWithLoggerAndPrincipal(logger, store, username) input := &models.SetSystemIntakeRelationExistingSystemInput{ SystemIntakeID: intakeID, ContractNumbers: contractNumbers, @@ -320,10 +322,11 @@ func setSystemIntakeRelationExistingService( logger *zap.Logger, store *storage.Store, intakeID uuid.UUID, + username string, contractName string, contractNumbers []string, ) { - ctx := mock.CtxWithLoggerAndPrincipal(logger, store, intakeID.String()) + ctx := mock.CtxWithLoggerAndPrincipal(logger, store, username) input := &models.SetSystemIntakeRelationExistingServiceInput{ SystemIntakeID: intakeID, ContractName: contractName, @@ -344,8 +347,8 @@ func setSystemIntakeRelationExistingService( } } -func unlinkSystemIntakeRelation(logger *zap.Logger, store *storage.Store, intakeID uuid.UUID) { - ctx := mock.CtxWithLoggerAndPrincipal(logger, store, intakeID.String()) +func unlinkSystemIntakeRelation(logger *zap.Logger, store *storage.Store, intakeID uuid.UUID, username string) { + ctx := mock.CtxWithLoggerAndPrincipal(logger, store, username) // temp, manually unlink contract numbers // see Note [EASI-4160 Disable Contract Number Linking] diff --git a/pkg/graph/resolvers/resolver_test.go b/pkg/graph/resolvers/resolver_test.go index 912be583b3..549db8f4af 100644 --- a/pkg/graph/resolvers/resolver_test.go +++ b/pkg/graph/resolvers/resolver_test.go @@ -23,6 +23,7 @@ import ( "github.com/cms-enterprise/easi-app/pkg/testhelpers" "github.com/cms-enterprise/easi-app/pkg/upload" "github.com/cms-enterprise/easi-app/pkg/userhelpers" + "github.com/cms-enterprise/easi-app/pkg/usersearch" ld "gopkg.in/launchdarkly/go-server-sdk.v5" ) @@ -46,11 +47,16 @@ func (s *ResolverSuite) SetupTest() { assert.NoError(s.T(), err) // Get the user account from the DB fresh for each test - princ := getTestPrincipal(s.testConfigs.Context, s.testConfigs.Store, s.testConfigs.UserInfo.Username) + princ := s.getTestPrincipal(s.testConfigs.Context, s.testConfigs.Store, s.testConfigs.UserInfo.Username) s.testConfigs.Principal = princ // get new dataloaders to clear any existing cached data s.testConfigs.Context = s.ctxWithNewDataloaders() + + // Since we are recreating the context we need to wrap all expected values on the context (like the principal) + s.testConfigs.Context = appcontext.WithLogger(s.testConfigs.Context, s.testConfigs.Logger) + s.testConfigs.Context = appcontext.WithPrincipal(s.testConfigs.Context, princ) + } // TestResolverSuite runs the resolver test suite @@ -69,16 +75,17 @@ func TestResolverSuite(t *testing.T) { // TestConfigs is a struct that contains all the dependencies needed to run a test type TestConfigs struct { - DBConfig storage.DBConfig - LDClient *ld.LDClient - S3Client *upload.S3Client - Logger *zap.Logger - UserInfo *models.UserInfo - Store *storage.Store - Principal *authentication.EUAPrincipal - Context context.Context - EmailClient *email.Client - Sender *mockSender + DBConfig storage.DBConfig + LDClient *ld.LDClient + S3Client *upload.S3Client + Logger *zap.Logger + UserInfo *models.UserInfo + Store *storage.Store + Principal *authentication.EUAPrincipal + Context context.Context + EmailClient *email.Client + Sender *mockSender + UserSearchClient usersearch.Client } type mockSender struct { @@ -119,12 +126,11 @@ func (tc *TestConfigs) GetDefaults() { } tc.Store, _ = storage.NewStore(tc.DBConfig, tc.LDClient) - // create the test context - // principal is fetched between each test in SetupTest() - ctx := appcontext.WithLogger(context.Background(), tc.Logger) - ctx = appcontext.WithPrincipal(ctx, getTestPrincipal(ctx, tc.Store, tc.UserInfo.Username)) + localOktaClient := local.NewOktaAPIClient() + tc.UserSearchClient = localOktaClient - tc.Context = ctx + // create the test context, note because of the data loaders, the context gets recreated before each test. + tc.Context = context.Background() localSender := mockSender{} tc.Sender = &localSender @@ -148,9 +154,10 @@ func NewEmailClient(sender *mockSender) *email.Client { return &emailClient } -func getTestPrincipal(ctx context.Context, store *storage.Store, userName string) *authentication.EUAPrincipal { +// getTestPrincipal gets a user principal from database +func (s *ResolverSuite) getTestPrincipal(ctx context.Context, store *storage.Store, userName string) *authentication.EUAPrincipal { - userAccount, _ := userhelpers.GetOrCreateUserAccount(ctx, store, store, userName, true, userhelpers.GetOktaAccountInfoWrapperFunction(userhelpers.GetUserInfoFromOktaLocal)) + userAccount, _ := userhelpers.GetOrCreateUserAccount(ctx, store, store, userName, true, userhelpers.GetUserInfoAccountInfoWrapperFunc(s.testConfigs.UserSearchClient.FetchUserInfo)) princ := &authentication.EUAPrincipal{ EUAID: userName, @@ -240,9 +247,6 @@ func (s *ResolverSuite) getOrCreateUserAcct(euaUserID string) *authentication.Us // that caching feature is great for app code, but in test code, where we often load something, // update that thing, and load it again to confirm updates worked, caching the first version breaks that flow func (s *ResolverSuite) ctxWithNewDataloaders() context.Context { - fetchUserInfos := func(ctx context.Context, euaUserIDs []string) ([]*models.UserInfo, error) { - return nil, nil - } coreClient := cedarcore.NewClient(s.testConfigs.Context, "", "", "", true, true) getCedarSystems := func(ctx context.Context) ([]*models.CedarSystem, error) { @@ -250,7 +254,7 @@ func (s *ResolverSuite) ctxWithNewDataloaders() context.Context { } buildDataloaders := func() *dataloaders.Dataloaders { - return dataloaders.NewDataloaders(s.testConfigs.Store, fetchUserInfos, getCedarSystems) + return dataloaders.NewDataloaders(s.testConfigs.Store, s.testConfigs.UserSearchClient.FetchUserInfos, getCedarSystems) } // Set up mocked dataloaders for the test context diff --git a/pkg/local/authentication_middleware.go b/pkg/local/authentication_middleware.go index 7612158ec9..33723c4f35 100644 --- a/pkg/local/authentication_middleware.go +++ b/pkg/local/authentication_middleware.go @@ -78,7 +78,9 @@ func devUserContext(ctx context.Context, authHeader string, store *storage.Store JobCodeGRT: swag.ContainsStrings(config.JobCodes, "EASI_D_GOVTEAM"), JobCodeTRBAdmin: swag.ContainsStrings(config.JobCodes, "EASI_TRB_ADMIN_D"), } - userAccount, err := userhelpers.GetOrCreateUserAccount(ctx, store, store, princ.ID(), true, userhelpers.GetOktaAccountInfoWrapperFunction(userhelpers.GetUserInfoFromOktaLocal)) + localOktaClient := NewOktaAPIClient() + + userAccount, err := userhelpers.GetOrCreateUserAccount(ctx, store, store, princ.ID(), true, userhelpers.GetUserInfoAccountInfoWrapperFunc(localOktaClient.FetchUserInfo)) if err != nil { return nil, err } diff --git a/pkg/local/cedarcoremock/roles.go b/pkg/local/cedarcoremock/roles.go index fde4052cec..c8af0227a8 100644 --- a/pkg/local/cedarcoremock/roles.go +++ b/pkg/local/cedarcoremock/roles.go @@ -1,10 +1,12 @@ package cedarcoremock import ( + "context" "fmt" "github.com/guregu/null/zero" + "github.com/cms-enterprise/easi-app/cmd/devdata/mock" "github.com/cms-enterprise/easi-app/pkg/helpers" "github.com/cms-enterprise/easi-app/pkg/local" "github.com/cms-enterprise/easi-app/pkg/models" @@ -125,7 +127,11 @@ func GetSystemRoles(cedarSystemID string, roleTypeID *string) []*models.CedarRol roleTypeIDStr = *roleTypeID } roleTypes := GetRoleTypes() - users := local.GetMockUserData() + + oktaClient := local.NewOktaAPIClient() + //swallow error for mocking + users, _ := oktaClient.FetchUserInfos(context.Background(), mock.UserNamesForCedarSystemRoles) + mockSystemRoles := []*models.CedarRole{} makeMockRoleFromUserAndRoleType := func( @@ -138,7 +144,7 @@ func GetSystemRoles(cedarSystemID string, roleTypeID *string) []*models.CedarRol ObjectID: zero.StringFrom(cedarSystemID), AssigneeType: helpers.PointerTo(models.PersonAssignee), AssigneeUsername: zero.StringFrom(user.Username), - AssigneeEmail: zero.StringFrom(fmt.Sprintf(`%s.%s@fake.local`, user.FirstName, user.LastName)), + AssigneeEmail: zero.StringFrom(string(user.Email)), AssigneeFirstName: zero.StringFrom(user.FirstName), AssigneeLastName: zero.StringFrom(user.LastName), AssigneePhone: zero.StringFrom("123-456-7890"), diff --git a/pkg/local/okta_api.go b/pkg/local/okta_api.go index 78b73bccdf..62789f0c56 100644 --- a/pkg/local/okta_api.go +++ b/pkg/local/okta_api.go @@ -2,13 +2,11 @@ package local import ( "context" - "errors" "strings" "go.uber.org/zap" "github.com/cms-enterprise/easi-app/pkg/appcontext" - "github.com/cms-enterprise/easi-app/pkg/apperrors" "github.com/cms-enterprise/easi-app/pkg/models" ) @@ -20,492 +18,623 @@ func NewOktaAPIClient() *client { return &client{} } -// GetMockUserData returns a slice of *models.UserInfo that represents a response from the Okta server. +// mockUserDictionary returns a map of *models.UserInfo that represents a response from the Okta server. // Most of the data here is generated randomly, though some of it was curated specifically for the purpose of making tests pass. -func GetMockUserData() []*models.UserInfo { - return []*models.UserInfo{ - { - DisplayName: "Adeline Aarons", - Email: "adeline.aarons@local.fake", - Username: "ABCD", - FirstName: "Adeline", - LastName: "Aarons", - }, - { - DisplayName: "Terry Thompson", - Email: "terry.thompson@local.fake", - Username: "TEST", - FirstName: "Terry", - LastName: "Thompson", - }, - { - DisplayName: "Ally Anderson", - Email: "ally.anderson@local.fake", - Username: "A11Y", - FirstName: "Ally", - LastName: "Anderson", - }, - { - DisplayName: "Gary Gordon", - Email: "gary.gordon@local.fake", - Username: "GRTB", - FirstName: "Gary", - LastName: "Gordon", - }, - { - DisplayName: "Charlie Campbell", - Email: "charlie.campbell@local.fake", - Username: "CMSU", - FirstName: "Charlie", - LastName: "Campbell", - }, - { - DisplayName: "Audrey Abrams", - Email: "audrey.abrams@local.fake", - Username: "ADMI", - FirstName: "Audrey", - LastName: "Abrams", - }, - { - DisplayName: "Aaron Adams", - Email: "aaron.adams@local.fake", - Username: "ADMN", - FirstName: "Aaron", - LastName: "Adams", - }, - { - DisplayName: "User One", - Email: "user.one@local.fake", - Username: "USR1", - FirstName: "User", - LastName: "One", - }, - { - DisplayName: "User Two", - Email: "user.two@local.fake", - Username: "USR2", - FirstName: "User", - LastName: "Two", - }, - { - DisplayName: "User Three", - Email: "user.three@local.fake", - Username: "USR3", - FirstName: "User", - LastName: "Three", - }, - { - DisplayName: "User Four", - Email: "user.four@local.fake", - Username: "USR4", - FirstName: "User", - LastName: "Four", - }, - { - DisplayName: "User Five", - Email: "user.five@local.fake", - Username: "USR5", - FirstName: "User", - LastName: "Five", - }, - { - DisplayName: "Jerry Seinfeld", - Email: "jerry.seinfeld@local.fake", - Username: "SF13", - FirstName: "Jerry", - LastName: "Seinfeld", - }, - { - DisplayName: "Cosmo Kramer", - Email: "cosmo.kramer@local.fake", - Username: "KR14", - FirstName: "Cosmo", - LastName: "Kramer", - }, - { - DisplayName: "Kennedy Kuhic", - Email: "kennedy.kuhic@local.fake", - Username: "KVB3", - FirstName: "Kennedy", - LastName: "Kuhic", - }, - { - DisplayName: "Theo Crooks", - Email: "theo.crooks@local.fake", - Username: "CJRW", - FirstName: "Theo", - LastName: "Crooks", - }, - { - DisplayName: "Delphia Green", - Email: "delphia.green@local.fake", - Username: "GBRG", - FirstName: "Delphia", - LastName: "Green", - }, - { - DisplayName: "Leatha Gorczany", - Email: "leatha.gorczany@local.fake", - Username: "GP87", - FirstName: "Leatha", - LastName: "Gorczany", - }, - { - DisplayName: "Catherine Rice", - Email: "catherine.rice@local.fake", - Username: "RH4V", - FirstName: "Catherine", - LastName: "Rice", - }, - { - DisplayName: "Litzy Emard", - Email: "litzy.emard@local.fake", - Username: "ER3Z", - FirstName: "Litzy", - LastName: "Emard", - }, - { - DisplayName: "Lauriane Stoltenberg", - Email: "lauriane.stoltenberg@local.fake", - Username: "S3W0", - FirstName: "Lauriane", - LastName: "Stoltenberg", - }, - { - DisplayName: "Zechariah Wyman", - Email: "zechariah.wyman@local.fake", - Username: "W1I4", - FirstName: "Zechariah", - LastName: "Wyman", - }, - { - DisplayName: "Savanna Hyatt", - Email: "savanna.hyatt@local.fake", - Username: "HCNK", - FirstName: "Savanna", - LastName: "Hyatt", - }, - { - DisplayName: "Dawn Jaskolski", - Email: "dawn.jaskolski@local.fake", - Username: "JG1B", - FirstName: "Dawn", - LastName: "Jaskolski", - }, - { - DisplayName: "Anabelle Jerde", - Email: "anabelle.jerde@local.fake", - Username: "JTTC", - FirstName: "Anabelle", - LastName: "Jerde", - }, - { - DisplayName: "Hilbert Gislason", - Email: "hilbert.gislason@local.fake", - Username: "G4A7", - FirstName: "Hilbert", - LastName: "Gislason", - }, - { - DisplayName: "Rudolph Pagac", - Email: "rudolph.pagac@local.fake", - Username: "POJG", - FirstName: "Rudolph", - LastName: "Pagac", - }, - { - DisplayName: "Avis Anderson", - Email: "avis.anderson@local.fake", - Username: "ATSI", - FirstName: "Avis", - LastName: "Anderson", - }, - { - DisplayName: "Annetta Lockman", - Email: "annetta.lockman@local.fake", - Username: "LW40", - FirstName: "Annetta", - LastName: "Lockman", - }, - { - DisplayName: "Elva Ruecker", - Email: "elva.ruecker@local.fake", - Username: "RP20", - FirstName: "Elva", - LastName: "Ruecker", - }, - { - DisplayName: "Waylon Tromp", - Email: "waylon.tromp@local.fake", - Username: "TWAW", - FirstName: "Waylon", - LastName: "Tromp", - }, - { - DisplayName: "Doyle Heller", - Email: "doyle.heller@local.fake", - Username: "HIV3", - FirstName: "Doyle", - LastName: "Heller", - }, - { - DisplayName: "Hallie O'Hara", - Email: "hallie.ohara@local.fake", - Username: "OQYV", - FirstName: "Hallie", - LastName: "Hara", - }, - { - DisplayName: "Laverne Roberts", - Email: "laverne.roberts@local.fake", - Username: "R0EI", - FirstName: "Laverne", - LastName: "Roberts", - }, - { - DisplayName: "Alexander Stark", - Email: "alexander.stark@local.fake", - Username: "SKZO", - FirstName: "Alexander", - LastName: "Stark", - }, - { - DisplayName: "Caden Schmeler", - Email: "caden.schmeler@local.fake", - Username: "SPJW", - FirstName: "Caden", - LastName: "Schmeler", - }, - { - DisplayName: "Nat Krajcik", - Email: "nat.krajcik@local.fake", - Username: "K0AM", - FirstName: "Nat", - LastName: "Krajcik", - }, - { - DisplayName: "Palma Towne", - Email: "palma.towne@local.fake", - Username: "TX4A", - FirstName: "Palma", - LastName: "Towne", - }, - { - DisplayName: "Aurelie Morar", - Email: "aurelie.morar@local.fake", - Username: "MN3Q", - FirstName: "Aurelie", - LastName: "Morar", - }, - { - DisplayName: "Hellen Grimes", - Email: "hellen.grimes@local.fake", - Username: "GFRY", - FirstName: "Hellen", - LastName: "Grimes", - }, - { - DisplayName: "Kenna Gerhold", - Email: "kenna.gerhold@local.fake", - Username: "GZP4", - FirstName: "Kenna", - LastName: "Gerhold", - }, - { - DisplayName: "Rolando Weber", - Email: "rolando.weber@local.fake", - Username: "WNZ3", - FirstName: "Rolando", - LastName: "Weber", - }, - { - DisplayName: "Lance Konopelski", - Email: "lance.konopelski@local.fake", - Username: "K0LR", - FirstName: "Lance", - LastName: "Konopelski", - }, - { - DisplayName: "Otilia Abbott", - Email: "otilia.abbott@local.fake", - Username: "AX0Q", - FirstName: "Otilia", - LastName: "Abbott", - }, - { - DisplayName: "Marjory Doyle", - Email: "marjory.doyle@local.fake", - Username: "D7R3", - FirstName: "Marjory", - LastName: "Doyle", - }, - { - DisplayName: "Yasmine Dare", - Email: "yasmine.dare@local.fake", - Username: "D2AC", - FirstName: "Yasmine", - LastName: "Dare", - }, - { - DisplayName: "Kayla Zulauf", - Email: "kayla.zulauf@local.fake", - Username: "ZOCN", - FirstName: "Kayla", - LastName: "Zulauf", - }, - { - DisplayName: "Lucinda Hansen", - Email: "lucinda.hansen@local.fake", - Username: "H2KQ", - FirstName: "Lucinda", - LastName: "Hansen", - }, - { - DisplayName: "Alyce Haag", - Email: "alyce.haag@local.fake", - Username: "HBGM", - FirstName: "Alyce", - LastName: "Haag", - }, - { - DisplayName: "Deonte Kassulke", - Email: "deonte.kassulke@local.fake", - Username: "KDYZ", - FirstName: "Deonte", - LastName: "Kassulke", - }, - { - DisplayName: "Mckayla Fritsch", - Email: "mckayla.fritsch@local.fake", - Username: "FAUI", - FirstName: "Mckayla", - LastName: "Fritsch", - }, - { - DisplayName: "Brooks Johnson", - Email: "brooks.johnson@local.fake", - Username: "J3C8", - FirstName: "Brooks", - LastName: "Johnson", - }, - { - DisplayName: "Bernhard Koss", - Email: "bernhard.koss@local.fake", - Username: "K9W1", - FirstName: "Bernhard", - LastName: "Koss", - }, - { - DisplayName: "Gust Murray", - Email: "gust.murray@local.fake", - Username: "MR92", - FirstName: "Gust", - LastName: "Murray", - }, - { - DisplayName: "Eldred Hammes", - Email: "eldred.hammes@local.fake", - Username: "HY0W", - FirstName: "Eldred", - LastName: "Hammes", - }, - { - DisplayName: "Adrianna Gottlieb", - Email: "adrianna.gottlieb@local.fake", - Username: "GT98", - FirstName: "Adrianna", - LastName: "Gottlieb", - }, - { - DisplayName: "Earnest Torp", - Email: "earnest.torp@local.fake", - Username: "TD4Z", - FirstName: "Earnest", - LastName: "Torp", - }, - { - DisplayName: "Cecelia Hahn", - Email: "cecelia.hahn@local.fake", - Username: "HGDS", - FirstName: "Cecelia", - LastName: "Hahn", - }, - { - DisplayName: "Desmond Nolan", - Email: "desmond.nolan@local.fake", - Username: "N60U", - FirstName: "Desmond", - LastName: "Nolan", - }, - { - DisplayName: "Karianne Hickle", - Email: "karianne.hickle@local.fake", - Username: "HYG2", - FirstName: "Karianne", - LastName: "Hickle", - }, - { - DisplayName: "Isobel Koelpin", - Email: "isobel.koelpin@local.fake", - Username: "KT77", - FirstName: "Isobel", - LastName: "Koelpin", - }, - { - DisplayName: "Isidro Swaniawski", - Email: "isidro.swaniawski@local.fake", - Username: "SM7H", - FirstName: "Isidro", - LastName: "Swaniawski", - }, - { - DisplayName: "EndToEnd One", - Email: "endtoend.one@local.fake", - Username: "E2E1", - FirstName: "EndToEnd", - LastName: "One", - }, - { - DisplayName: "EndToEnd Two", - Email: "endtoend.two@local.fake", - Username: "E2E2", - FirstName: "EndToEnd", - LastName: "Two", - }, - } +var mockUserDictionary = map[string]*models.UserInfo{ + "ABCD": { + DisplayName: "Adeline Aarons", + Email: "adeline.aarons@local.fake", + Username: "ABCD", + FirstName: "Adeline", + LastName: "Aarons", + }, + "TEST": { + DisplayName: "Terry Thompson", + Email: "terry.thompson@local.fake", + Username: "TEST", + FirstName: "Terry", + LastName: "Thompson", + }, + "A11Y": { + DisplayName: "Ally Anderson", + Email: "ally.anderson@local.fake", + Username: "A11Y", + FirstName: "Ally", + LastName: "Anderson", + }, + "GRTB": { + DisplayName: "Gary Gordon", + Email: "gary.gordon@local.fake", + Username: "GRTB", + FirstName: "Gary", + LastName: "Gordon", + }, + "CMSU": { + DisplayName: "Charlie Campbell", + Email: "charlie.campbell@local.fake", + Username: "CMSU", + FirstName: "Charlie", + LastName: "Campbell", + }, + "ADMI": { + DisplayName: "Audrey Abrams", + Email: "audrey.abrams@local.fake", + Username: "ADMI", + FirstName: "Audrey", + LastName: "Abrams", + }, + "ADMN": { + DisplayName: "Aaron Adams", + Email: "aaron.adams@local.fake", + Username: "ADMN", + FirstName: "Aaron", + LastName: "Adams", + }, + "USR1": { + DisplayName: "User One", + Email: "user.one@local.fake", + Username: "USR1", + FirstName: "User", + LastName: "One", + }, + "USR2": { + DisplayName: "User Two", + Email: "user.two@local.fake", + Username: "USR2", + FirstName: "User", + LastName: "Two", + }, + "USR3": { + DisplayName: "User Three", + Email: "user.three@local.fake", + Username: "USR3", + FirstName: "User", + LastName: "Three", + }, + "USR4": { + DisplayName: "User Four", + Email: "user.four@local.fake", + Username: "USR4", + FirstName: "User", + LastName: "Four", + }, + "USR5": { + DisplayName: "User Five", + Email: "user.five@local.fake", + Username: "USR5", + FirstName: "User", + LastName: "Five", + }, + "SF13": { + DisplayName: "Jerry Seinfeld", + Email: "jerry.seinfeld@local.fake", + Username: "SF13", + FirstName: "Jerry", + LastName: "Seinfeld", + }, + "KR14": { + DisplayName: "Cosmo Kramer", + Email: "cosmo.kramer@local.fake", + Username: "KR14", + FirstName: "Cosmo", + LastName: "Kramer", + }, + "KVB3": { + DisplayName: "Kennedy Kuhic", + Email: "kennedy.kuhic@local.fake", + Username: "KVB3", + FirstName: "Kennedy", + LastName: "Kuhic", + }, + "CJRW": { + DisplayName: "Theo Crooks", + Email: "theo.crooks@local.fake", + Username: "CJRW", + FirstName: "Theo", + LastName: "Crooks", + }, + "GBRG": { + DisplayName: "Delphia Green", + Email: "delphia.green@local.fake", + Username: "GBRG", + FirstName: "Delphia", + LastName: "Green", + }, + "GP87": { + DisplayName: "Leatha Gorczany", + Email: "leatha.gorczany@local.fake", + Username: "GP87", + FirstName: "Leatha", + LastName: "Gorczany", + }, + "RH4V": { + DisplayName: "Catherine Rice", + Email: "catherine.rice@local.fake", + Username: "RH4V", + FirstName: "Catherine", + LastName: "Rice", + }, + "ER3Z": { + DisplayName: "Litzy Emard", + Email: "litzy.emard@local.fake", + Username: "ER3Z", + FirstName: "Litzy", + LastName: "Emard", + }, + "S3W0": { + DisplayName: "Lauriane Stoltenberg", + Email: "lauriane.stoltenberg@local.fake", + Username: "S3W0", + FirstName: "Lauriane", + LastName: "Stoltenberg", + }, + "W1I4": { + DisplayName: "Zechariah Wyman", + Email: "zechariah.wyman@local.fake", + Username: "W1I4", + FirstName: "Zechariah", + LastName: "Wyman", + }, + "HCNK": { + DisplayName: "Savanna Hyatt", + Email: "savanna.hyatt@local.fake", + Username: "HCNK", + FirstName: "Savanna", + LastName: "Hyatt", + }, + "JG1B": { + DisplayName: "Dawn Jaskolski", + Email: "dawn.jaskolski@local.fake", + Username: "JG1B", + FirstName: "Dawn", + LastName: "Jaskolski", + }, + "JTTC": { + DisplayName: "Anabelle Jerde", + Email: "anabelle.jerde@local.fake", + Username: "JTTC", + FirstName: "Anabelle", + LastName: "Jerde", + }, + "G4A7": { + DisplayName: "Hilbert Gislason", + Email: "hilbert.gislason@local.fake", + Username: "G4A7", + FirstName: "Hilbert", + LastName: "Gislason", + }, + "POJG": { + DisplayName: "Rudolph Pagac", + Email: "rudolph.pagac@local.fake", + Username: "POJG", + FirstName: "Rudolph", + LastName: "Pagac", + }, + "ATSI": { + DisplayName: "Avis Anderson", + Email: "avis.anderson@local.fake", + Username: "ATSI", + FirstName: "Avis", + LastName: "Anderson", + }, + "LW40": { + DisplayName: "Annetta Lockman", + Email: "annetta.lockman@local.fake", + Username: "LW40", + FirstName: "Annetta", + LastName: "Lockman", + }, + "RP20": { + DisplayName: "Elva Ruecker", + Email: "elva.ruecker@local.fake", + Username: "RP20", + FirstName: "Elva", + LastName: "Ruecker", + }, + "TWAW": { + DisplayName: "Waylon Tromp", + Email: "waylon.tromp@local.fake", + Username: "TWAW", + FirstName: "Waylon", + LastName: "Tromp", + }, + "HIV3": { + DisplayName: "Doyle Heller", + Email: "doyle.heller@local.fake", + Username: "HIV3", + FirstName: "Doyle", + LastName: "Heller", + }, + "OQYV": { + DisplayName: "Hallie O'Hara", + Email: "hallie.ohara@local.fake", + Username: "OQYV", + FirstName: "Hallie", + LastName: "Hara", + }, + "R0EI": { + DisplayName: "Laverne Roberts", + Email: "laverne.roberts@local.fake", + Username: "R0EI", + FirstName: "Laverne", + LastName: "Roberts", + }, + "SKZO": { + DisplayName: "Alexander Stark", + Email: "alexander.stark@local.fake", + Username: "SKZO", + FirstName: "Alexander", + LastName: "Stark", + }, + "SPJW": { + DisplayName: "Caden Schmeler", + Email: "caden.schmeler@local.fake", + Username: "SPJW", + FirstName: "Caden", + LastName: "Schmeler", + }, + "K0AM": { + DisplayName: "Nat Krajcik", + Email: "nat.krajcik@local.fake", + Username: "K0AM", + FirstName: "Nat", + LastName: "Krajcik", + }, + "TX4A": { + DisplayName: "Palma Towne", + Email: "palma.towne@local.fake", + Username: "TX4A", + FirstName: "Palma", + LastName: "Towne", + }, + "MN3Q": { + DisplayName: "Aurelie Morar", + Email: "aurelie.morar@local.fake", + Username: "MN3Q", + FirstName: "Aurelie", + LastName: "Morar", + }, + "GFRY": { + DisplayName: "Hellen Grimes", + Email: "hellen.grimes@local.fake", + Username: "GFRY", + FirstName: "Hellen", + LastName: "Grimes", + }, + "GZP4": { + DisplayName: "Kenna Gerhold", + Email: "kenna.gerhold@local.fake", + Username: "GZP4", + FirstName: "Kenna", + LastName: "Gerhold", + }, + "WNZ3": { + DisplayName: "Rolando Weber", + Email: "rolando.weber@local.fake", + Username: "WNZ3", + FirstName: "Rolando", + LastName: "Weber", + }, + "K0LR": { + DisplayName: "Lance Konopelski", + Email: "lance.konopelski@local.fake", + Username: "K0LR", + FirstName: "Lance", + LastName: "Konopelski", + }, + "AX0Q": { + DisplayName: "Otilia Abbott", + Email: "otilia.abbott@local.fake", + Username: "AX0Q", + FirstName: "Otilia", + LastName: "Abbott", + }, + "D7R3": { + DisplayName: "Marjory Doyle", + Email: "marjory.doyle@local.fake", + Username: "D7R3", + FirstName: "Marjory", + LastName: "Doyle", + }, + "D2AC": { + DisplayName: "Yasmine Dare", + Email: "yasmine.dare@local.fake", + Username: "D2AC", + FirstName: "Yasmine", + LastName: "Dare", + }, + "ZOCN": { + DisplayName: "Kayla Zulauf", + Email: "kayla.zulauf@local.fake", + Username: "ZOCN", + FirstName: "Kayla", + LastName: "Zulauf", + }, + "H2KQ": { + DisplayName: "Lucinda Hansen", + Email: "lucinda.hansen@local.fake", + Username: "H2KQ", + FirstName: "Lucinda", + LastName: "Hansen", + }, + "HBGM": { + DisplayName: "Alyce Haag", + Email: "alyce.haag@local.fake", + Username: "HBGM", + FirstName: "Alyce", + LastName: "Haag", + }, + "KDYZ": { + DisplayName: "Deonte Kassulke", + Email: "deonte.kassulke@local.fake", + Username: "KDYZ", + FirstName: "Deonte", + LastName: "Kassulke", + }, + "FAUI": { + DisplayName: "Mckayla Fritsch", + Email: "mckayla.fritsch@local.fake", + Username: "FAUI", + FirstName: "Mckayla", + LastName: "Fritsch", + }, + "J3C8": { + DisplayName: "Brooks Johnson", + Email: "brooks.johnson@local.fake", + Username: "J3C8", + FirstName: "Brooks", + LastName: "Johnson", + }, + "K9W1": { + DisplayName: "Bernhard Koss", + Email: "bernhard.koss@local.fake", + Username: "K9W1", + FirstName: "Bernhard", + LastName: "Koss", + }, + "MR92": { + DisplayName: "Gust Murray", + Email: "gust.murray@local.fake", + Username: "MR92", + FirstName: "Gust", + LastName: "Murray", + }, + "HY0W": { + DisplayName: "Eldred Hammes", + Email: "eldred.hammes@local.fake", + Username: "HY0W", + FirstName: "Eldred", + LastName: "Hammes", + }, + "GT98": { + DisplayName: "Adrianna Gottlieb", + Email: "adrianna.gottlieb@local.fake", + Username: "GT98", + FirstName: "Adrianna", + LastName: "Gottlieb", + }, + "TD4Z": { + DisplayName: "Earnest Torp", + Email: "earnest.torp@local.fake", + Username: "TD4Z", + FirstName: "Earnest", + LastName: "Torp", + }, + "HGDS": { + DisplayName: "Cecelia Hahn", + Email: "cecelia.hahn@local.fake", + Username: "HGDS", + FirstName: "Cecelia", + LastName: "Hahn", + }, + "N60U": { + DisplayName: "Desmond Nolan", + Email: "desmond.nolan@local.fake", + Username: "N60U", + FirstName: "Desmond", + LastName: "Nolan", + }, + "HYG2": { + DisplayName: "Karianne Hickle", + Email: "karianne.hickle@local.fake", + Username: "HYG2", + FirstName: "Karianne", + LastName: "Hickle", + }, + "KT77": { + DisplayName: "Isobel Koelpin", + Email: "isobel.koelpin@local.fake", + Username: "KT77", + FirstName: "Isobel", + LastName: "Koelpin", + }, + "SM7H": { + DisplayName: "Isidro Swaniawski", + Email: "isidro.swaniawski@local.fake", + Username: "SM7H", + FirstName: "Isidro", + LastName: "Swaniawski", + }, + "E2E1": { + DisplayName: "EndToEnd One", + Email: "endtoend.one@local.fake", + Username: "E2E1", + FirstName: "EndToEnd", + LastName: "One", + }, + "E2E2": { + DisplayName: "EndToEnd Two", + Email: "endtoend.two@local.fake", + Username: "E2E2", + FirstName: "EndToEnd", + LastName: "Two", + }, + "BTAL": { + DisplayName: "Betty Alpha", + Email: "betty.alpha@local.fake", + Username: "BTAL", + FirstName: "Betty", + LastName: "Alpha", + }, + "BTMN": { + DisplayName: "Bruce Wayne", + Email: "bruce.wayne@gotham.city", + Username: "BTMN", + FirstName: "Bruce", + LastName: "Wayne", + }, + "JANE": { + DisplayName: "Jane McModelteam", + Email: "jane.mcmodelteam@local.fake", + Username: "JANE", + FirstName: "Jane", + LastName: "McModelteam", + }, + "L4RZ": { + DisplayName: "Laura Rodriguez", + Email: "laura.rodriguez@local.fake", + Username: "L4RZ", + FirstName: "Laura", + LastName: "Rodriguez", + }, + "BRGJ": { + DisplayName: "Bryce Greenfield-Jones", + Email: "bryce.greenfield-Jones@local.fake", + Username: "BRGJ", + FirstName: "Bryce", + LastName: "Greenfield-Jones", + }, + "AL2I": { + DisplayName: "Alison Li", + Email: "alison.li@local.fake", + Username: "AL2I", + FirstName: "Alison", + LastName: "Li", + }, + "N1M1": { + DisplayName: "Nick Miller", + Email: "nick.miller@local.fake", + Username: "N1M1", + FirstName: "Nick", + LastName: "Miller", + }, + "K8SY": { + DisplayName: "Karen Stanley", + Email: "karen.stanley@local.fake", + Username: "K8SY", + FirstName: "Karen", + LastName: "Stanley", + }, + "B6TP": { + DisplayName: "Bill Topper", + Email: "bill.topper@local.fake", + Username: "B6TP", + FirstName: "Bill", + LastName: "Topper", + }, + "HU18": { + DisplayName: "Heather Ulrich", + Email: "heather.ulrich@local.fake", + Username: "HU18", + FirstName: "Heather", + LastName: "Ulrich", + }, + "KWR1": { + DisplayName: "Kenneth Wright", + Email: "kenneth.wright@local.fake", + Username: "KWR1", + FirstName: "Kenneth", + LastName: "Wright", + }, + "ZANE": { + DisplayName: "Robert Zane", + Email: "robert.zane@local.fake", + Username: "ZANE", + FirstName: "Robert", + LastName: "Zane", + }, + "ZBRA": { + DisplayName: "Robert Zebra", + Email: "robert.zebra@local.fake", + Username: "ZBRA", + FirstName: "Robert", + LastName: "Zebra", + }, + "RING": { + DisplayName: "Frodo Baggins", + Email: "frodo.baggins@local.fake", + Username: "RING", + FirstName: "Frodo", + LastName: "Baggins", + }, + "RANG": { + DisplayName: "Bilbo Baggins", + Email: "bilbo.baggins@local.fake", + Username: "RANG", + FirstName: "Bilbo", + LastName: "Baggins", + }, + "RUNG": { + DisplayName: "Samwise Gamgee", + Email: "samwise.gamgee@local.fake", + Username: "RUNG", + FirstName: "Samwise", + LastName: "Gamgee", + }, + "SPDR": { + DisplayName: "Peter Parker", + Email: "peter.parker@local.fake", + Username: "SPDR", + FirstName: "Peter", + LastName: "Parker", + }, + "PSTM": { + DisplayName: "Post Man", + Email: "post.man@local.fake", + Username: "PSTM", + FirstName: "Post", + LastName: "Man", + }, } // FetchUserInfo fetches a user's personal details -func (c *client) FetchUserInfo(ctx context.Context, euaID string) (*models.UserInfo, error) { +func (c *client) FetchUserInfo(ctx context.Context, username string) (*models.UserInfo, error) { logger := appcontext.ZLogger(ctx) - if euaID == "" { - return nil, &apperrors.ValidationError{ - Err: errors.New("invalid EUA ID"), - Model: euaID, - ModelID: euaID, - } + logger.Info("Mock FetchUserInfo from Okta", zap.String("username", username)) + + mockUser, mockUserExists := mockUserDictionary[username] + if mockUserExists { + return mockUser, nil } - logger.Info("Mock FetchUserInfo from Okta", zap.String("euaID", euaID)) - for _, mockUser := range GetMockUserData() { - if mockUser.Username == euaID { - return mockUser, nil - } + // Users not in dictionary can just have simulated information returned so we can allow any username combo + return genericMockUserInfo(username), nil +} + +func genericMockUserInfo(username string) *models.UserInfo { + accountInfo := &models.UserInfo{ + DisplayName: username + " Doe", + + Email: models.NewEmailAddress(username + "@local.cms.gov"), + FirstName: username, + LastName: username, + Username: username, } - return nil, errors.New("failed to fetch user from Okta API") + return accountInfo + } // FetchUserInfos fetches multiple users' personal details -func (c *client) FetchUserInfos(ctx context.Context, euaIDs []string) ([]*models.UserInfo, error) { +func (c *client) FetchUserInfos(ctx context.Context, usernames []string) ([]*models.UserInfo, error) { logger := appcontext.ZLogger(ctx) - logger.Info("Mock FetchUserInfos from Okta", zap.Strings("euaIDs", euaIDs)) + logger.Info("Mock FetchUserInfos from Okta", zap.Strings("usernames", usernames)) - userInfos := make([]*models.UserInfo, len(euaIDs)) - for i, euaID := range euaIDs { - for _, mockUser := range GetMockUserData() { - if mockUser.Username == euaID { - userInfos[i] = mockUser - } + userInfos := make([]*models.UserInfo, len(usernames)) + for i, username := range usernames { + mockUser, err := c.FetchUserInfo(ctx, username) + if err != nil { + return nil, err } + userInfos[i] = mockUser } return userInfos, nil @@ -516,10 +645,9 @@ func (c *client) SearchCommonNameContains(ctx context.Context, commonName string logger := appcontext.ZLogger(ctx) logger.Info("Mock SearchCommonNameContains from Okta") - mockUserData := GetMockUserData() searchResults := []*models.UserInfo{} - for _, element := range mockUserData { + for _, element := range mockUserDictionary { lowerName := strings.ToLower(element.DisplayName) lowerSearch := strings.ToLower(commonName) if strings.Contains(lowerName, lowerSearch) { diff --git a/pkg/okta/authentication_middleware_test.go b/pkg/okta/authentication_middleware_test.go index 6026ebac94..b5713f1be8 100644 --- a/pkg/okta/authentication_middleware_test.go +++ b/pkg/okta/authentication_middleware_test.go @@ -19,16 +19,19 @@ import ( "github.com/cms-enterprise/easi-app/pkg/appcontext" "github.com/cms-enterprise/easi-app/pkg/authentication" "github.com/cms-enterprise/easi-app/pkg/handlers" + "github.com/cms-enterprise/easi-app/pkg/local" "github.com/cms-enterprise/easi-app/pkg/storage" "github.com/cms-enterprise/easi-app/pkg/testhelpers" "github.com/cms-enterprise/easi-app/pkg/userhelpers" + "github.com/cms-enterprise/easi-app/pkg/usersearch" ) type AuthenticationMiddlewareTestSuite struct { suite.Suite - logger *zap.Logger - config *viper.Viper - store *storage.Store + logger *zap.Logger + config *viper.Viper + store *storage.Store + userSearchClient usersearch.Client } func TestAuthenticationMiddlewareTestSuite(t *testing.T) { @@ -38,12 +41,14 @@ func TestAuthenticationMiddlewareTestSuite(t *testing.T) { ldClient, _ := ld.MakeCustomClient("fake", ld.Config{Offline: true}, 0) store, _ := storage.NewStore(NewDBConfig(), ldClient) + localOktaClient := local.NewOktaAPIClient() testSuite := &AuthenticationMiddlewareTestSuite{ - Suite: suite.Suite{}, - store: store, - logger: logger, - config: config, + Suite: suite.Suite{}, + store: store, + logger: logger, + config: config, + userSearchClient: localOktaClient, } suite.Run(t, testSuite) @@ -82,7 +87,7 @@ func (s *AuthenticationMiddlewareTestSuite) buildMiddleware(verify func(jwt stri func (s *AuthenticationMiddlewareTestSuite) TestAuthorizeMiddleware() { - _, err := userhelpers.GetOrCreateUserAccount(context.Background(), s.store, s.store, "EASI", true, userhelpers.GetOktaAccountInfoWrapperFunction(userhelpers.GetUserInfoFromOktaLocal)) + _, err := userhelpers.GetOrCreateUserAccount(context.Background(), s.store, s.store, "EASI", true, userhelpers.GetUserInfoAccountInfoWrapperFunc(s.userSearchClient.FetchUserInfo)) s.NoError(err) s.Run("a valid token sets the principal", func() { diff --git a/pkg/userhelpers/user_account_utils.go b/pkg/userhelpers/user_account_utils.go index 1bae25983b..c7341797a4 100644 --- a/pkg/userhelpers/user_account_utils.go +++ b/pkg/userhelpers/user_account_utils.go @@ -221,19 +221,3 @@ func GetOktaAccountInfo(ctx context.Context, _ string) (*OktaAccountInfo, error) err = json.Unmarshal([]byte(jsonDataFromHTTP), &ret) return &ret, err } - -// GetUserInfoFromOktaLocal is used to simulate okta user information when testing locally -func GetUserInfoFromOktaLocal(ctx context.Context, username string) (*OktaAccountInfo, error) { - _ = ctx - - accountInfo := &OktaAccountInfo{ - Name: username + " Doe", - Locale: "en_US", - Email: username + "@local.cms.gov", - PreferredUsername: username, - GivenName: username, - FamilyName: "Doe", - ZoneInfo: "America/Los_Angeles", - } - return accountInfo, nil -}