Skip to content

Commit

Permalink
fix: use aws region env var and prevent username changes
Browse files Browse the repository at this point in the history
  • Loading branch information
PThorpe92 committed Jan 14, 2025
1 parent dae0366 commit 628f24c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
5 changes: 2 additions & 3 deletions backend/src/handlers/user_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,8 @@ func (srv *Server) handleUpdateUser(w http.ResponseWriter, r *http.Request, log
return newDatabaseServiceError(err)
}
if toUpdate.Username != user.Username && user.Username != "" {
if srv.Db.UsernameExists(user.Username) {
return newBadRequestServiceError(err, "userexists")
}
// usernames are immutable
return newBadRequestServiceError(errors.New("username cannot be updated"), "username")
}
invalidUser := validateUser(&user)
if invalidUser != "" {
Expand Down
13 changes: 12 additions & 1 deletion backend/src/handlers/user_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ func TestCreateUser(t *testing.T) {
func TestUpdateUser(t *testing.T) {
httpTests := []httpTest{
{"TestNonAdminCannotUpdateUser", "student", getUpdateUserForm(), http.StatusUnauthorized, ""},
{"TestAdminCannotUpdateUsername", "admin", getUpdateUsernameForm(), http.StatusBadRequest, ""},
{"TestAdminCanUpdateUser", "admin", getUpdateUserForm(), http.StatusOK, ""},
{"TestAdminUpdateUserNameValidationFailed", "admin", getUserWithBadCharsForm(), http.StatusBadRequest, ""},
{"TestAdminUpdateUserNameExits", "admin", getUserWhereNameExistsAlreadyForm(), http.StatusBadRequest, ""},
Expand Down Expand Up @@ -367,7 +368,7 @@ func getBadUserWithNoNameForm() map[string]any {
return form
}

func getUpdateUserForm() map[string]any {
func getUpdateUsernameForm() map[string]any {
form := make(map[string]any)
form["username"] = "testUpdate"
form["name_first"] = "testUpdate"
Expand All @@ -376,3 +377,13 @@ func getUpdateUserForm() map[string]any {
form["role"] = "admin"
return form
}

func getUpdateUserForm() map[string]any {
form := make(map[string]any)
form["username"] = ""
form["name_first"] = "testUpdate"
form["name_last"] = "testUpdate"
form["email"] = "testUpdate"
form["role"] = "admin"
return form
}
2 changes: 1 addition & 1 deletion provider-middleware/video_dl.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func NewVideoService(prov *models.OpenContentProvider, db *gorm.DB, body *map[st
var svc *s3.Client = nil
if bucketName != "" {
logger().Info("s3 bucket found, creating client")
cfg, err := config.LoadDefaultConfig(context.Background(), config.WithClientLogMode(aws.LogRequest|aws.LogResponseWithBody), config.WithRegion("us-west-2"))
cfg, err := config.LoadDefaultConfig(context.Background(), config.WithClientLogMode(aws.LogRequest|aws.LogResponseWithBody), config.WithRegion(os.Getenv("AWS_REGION")))
if err != nil {
logger().Fatal(err)
}
Expand Down

0 comments on commit 628f24c

Please sign in to comment.