-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from CACI-MIlMOVE/Misc-Test-Fixes
Okta Feature Branch Misc Test Fixes
- Loading branch information
Showing
9 changed files
with
25 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
migrations/app/schema/20230829133429_add_unique_constaint_okta_id.up.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ALTER TABLE users ADD CONSTRAINT users_okta_un UNIQUE (okta_id); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,7 +66,7 @@ func BuildDefaultAdminUser(db *pop.Connection) models.AdminUser { | |
// GetTraitAdminUserEmail helps comply with the uniqueness constraint on emails | ||
func GetTraitAdminUserEmail() []Customization { | ||
// There's a uniqueness constraint on admin user emails so add some randomness | ||
email := strings.ToLower(fmt.Sprintf("leo_spaceman_admin_%[email protected]", makeRandomString(5))) | ||
email := strings.ToLower(fmt.Sprintf("leo_spaceman_admin_%[email protected]", MakeRandomString(5))) | ||
return []Customization{ | ||
{ | ||
Model: models.User{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -114,7 +114,7 @@ func BuildOfficeUserWithRoles(db *pop.Connection, customs []Customization, roleT | |
// GetTraitOfficeUserEmail helps comply with the uniqueness constraint on emails | ||
func GetTraitOfficeUserEmail() []Customization { | ||
// There's a uniqueness constraint on office user emails so add some randomness | ||
email := strings.ToLower(fmt.Sprintf("leo_spaceman_office_%[email protected]", makeRandomString(5))) | ||
email := strings.ToLower(fmt.Sprintf("leo_spaceman_office_%[email protected]", MakeRandomString(5))) | ||
return []Customization{ | ||
{ | ||
Model: models.User{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,7 +30,7 @@ func BuildUser(db *pop.Connection, customs []Customization, traits []Trait) mode | |
} | ||
|
||
// create user | ||
OktaID := makeRandomString(20) | ||
OktaID := MakeRandomString(20) | ||
user := models.User{ | ||
OktaID: OktaID, | ||
OktaEmail: "[email protected]", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,11 +14,11 @@ import ( | |
) | ||
|
||
func (suite *ModelSuite) TestUserValidation() { | ||
fakeUUID, _ := uuid.FromString("39b28c92-0506-4bef-8b57-e39519f42dc1") | ||
oktaID := "abcdefghijklmnopqrst" | ||
userEmail := "[email protected]" | ||
|
||
newUser := User{ | ||
OktaID: fakeUUID.String(), | ||
OktaID: oktaID, | ||
OktaEmail: userEmail, | ||
} | ||
|
||
|
@@ -27,7 +27,7 @@ func (suite *ModelSuite) TestUserValidation() { | |
suite.NoError(err) | ||
suite.False(verrs.HasAny(), "Error validating model") | ||
suite.Equal(userEmail, newUser.OktaEmail) | ||
suite.Equal(fakeUUID, newUser.OktaID) | ||
suite.Equal(oktaID, newUser.OktaID) | ||
} | ||
|
||
func (suite *ModelSuite) TestUserCreationWithoutValues() { | ||
|
@@ -40,17 +40,17 @@ func (suite *ModelSuite) TestUserCreationWithoutValues() { | |
suite.verifyValidationErrors(newUser, expErrors) | ||
} | ||
|
||
func (suite *ModelSuite) TestUserCreationDuplicateUUID() { | ||
fakeUUID, _ := uuid.FromString("39b28c92-0506-4bef-8b57-e39519f42dc2") | ||
func (suite *ModelSuite) TestUserCreationDuplicateOktaID() { | ||
oktaID := "abcdefghijklmnopqrst" | ||
userEmail := "[email protected]" | ||
|
||
newUser := User{ | ||
OktaID: fakeUUID.String(), | ||
OktaID: oktaID, | ||
OktaEmail: userEmail, | ||
} | ||
|
||
sameUser := User{ | ||
OktaID: fakeUUID.String(), | ||
OktaID: oktaID, | ||
OktaEmail: userEmail, | ||
} | ||
|
||
|
@@ -65,30 +65,24 @@ func (suite *ModelSuite) TestUserCreationDuplicateUUID() { | |
// nolint:errcheck | ||
suite.DB().Create(&newUser) | ||
err := suite.DB().Create(&sameUser) | ||
|
||
suite.True(dberr.IsDBErrorForConstraint(err, pgerrcode.UniqueViolation, "constraint_name"), "Db should have errored on unique constraint for UUID") | ||
suite.True(dberr.IsDBErrorForConstraint(err, pgerrcode.UniqueViolation, "users_okta_un"), "Db should have errored on unique constraint for UUID") | ||
} | ||
|
||
func (suite *ModelSuite) TestCreateUser() { | ||
const testEmail = "[email protected]" | ||
const expectedEmail = "[email protected]" | ||
const goodUUID = "39b28c92-0506-4bef-8b57-e39519f42dc2" | ||
const badUUID = "39xnfc92-0506-4bef-8b57-e39519f42dc2" | ||
const oktaID = "00u3ckm7yEoUJuI1i0k6" | ||
|
||
sally, err := CreateUser(suite.DB(), goodUUID, testEmail) | ||
sally, err := CreateUser(suite.DB(), oktaID, testEmail) | ||
suite.Nil(err, "No error for good create") | ||
suite.Equal(expectedEmail, sally.OktaEmail, "should convert email to lower case") | ||
suite.NotEqual(sally.ID, uuid.Nil) | ||
|
||
fail, err := CreateUser(suite.DB(), expectedEmail, badUUID) | ||
suite.NotNil(err, "should get and error from bad uuid") | ||
suite.Nil(fail, "no user with bad uuid") | ||
} | ||
|
||
func (suite *ModelSuite) TestFetchUserIdentity() { | ||
const goodUUID = "39b28c92-0506-4bef-8b57-e39519f42dc2" | ||
oktaID := factory.MakeRandomString(20) | ||
// First check that it all works with no record | ||
identity, err := FetchUserIdentity(suite.DB(), goodUUID) | ||
identity, err := FetchUserIdentity(suite.DB(), oktaID) | ||
suite.Equal(ErrFetchNotFound, err, "Expected not to find missing Identity") | ||
suite.Nil(identity) | ||
|
||
|
@@ -139,7 +133,6 @@ func (suite *ModelSuite) TestFetchUserIdentity() { | |
suite.Equal(systemAdmin.User.OktaEmail, identity.Email) | ||
suite.Nil(identity.ServiceMemberID) | ||
suite.Nil(identity.OfficeUserID) | ||
|
||
rs := []roles.Role{{ | ||
ID: uuid.FromStringOrNil("ed2d2cd7-d427-412a-98bb-a9b391d98d32"), | ||
RoleType: roles.RoleTypeCustomer, | ||
|
@@ -150,11 +143,11 @@ func (suite *ModelSuite) TestFetchUserIdentity() { | |
} | ||
suite.NoError(suite.DB().Create(&rs)) | ||
customerRole := rs[0] | ||
patUUID := uuid.Must(uuid.NewV4()) | ||
patOktaID := factory.MakeRandomString(20) | ||
pat := factory.BuildUser(suite.DB(), []factory.Customization{ | ||
{ | ||
Model: User{ | ||
OktaID: patUUID.String(), | ||
OktaID: patOktaID, | ||
Active: true, | ||
Roles: []roles.Role{customerRole}, | ||
}, | ||
|
@@ -261,7 +254,7 @@ func (suite *ModelSuite) TestFetchAppUserIdentities() { | |
suite.Run("service member", func() { | ||
|
||
// Create a user email that won't be filtered out of the devlocal user query w/ a default value of | ||
// first.last@login.gov.test | ||
// first.last@okta.mil | ||
user := factory.BuildUser(suite.DB(), []factory.Customization{ | ||
{ | ||
Model: User{ | ||
|