Skip to content

Commit

Permalink
Add unit tests http middleware
Browse files Browse the repository at this point in the history
Add unit tests department user and department admin middleware

Add unit tests for subscribed team and subscribed org middleware

Add unit tests for some of the http util functions
  • Loading branch information
StevenWeathers committed Sep 23, 2024
1 parent 072183e commit a9ca8ea
Show file tree
Hide file tree
Showing 4 changed files with 1,007 additions and 32 deletions.
4 changes: 2 additions & 2 deletions internal/http/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ func (s *Service) departmentUserOnly(h http.HandlerFunc) http.HandlerFunc {
if UserType != thunderdome.AdminUserType {
var UserErr error
OrgRole, DepartmentRole, UserErr = s.OrganizationDataSvc.DepartmentUserRole(ctx, UserID, OrgID, DepartmentID)
if UserErr != nil {
if UserErr != nil || (DepartmentRole == "" && OrgRole != thunderdome.AdminUserType) {
s.Logger.Ctx(ctx).Warn("middleware departmentUserOnly REQUIRES_DEPARTMENT_USER",
zap.Error(UserErr),
zap.String("user_id", UserID),
Expand Down Expand Up @@ -375,7 +375,7 @@ func (s *Service) departmentAdminOnly(h http.HandlerFunc) http.HandlerFunc {
var DepartmentRole string
if UserType != thunderdome.AdminUserType {
var UserErr error
OrgRole, DepartmentRole, UserErr := s.OrganizationDataSvc.DepartmentUserRole(ctx, UserID, OrgID, DepartmentID)
OrgRole, DepartmentRole, UserErr = s.OrganizationDataSvc.DepartmentUserRole(ctx, UserID, OrgID, DepartmentID)
if UserErr != nil {
s.Failure(w, r, http.StatusForbidden, Errorf(EUNAUTHORIZED, "REQUIRES_DEPARTMENT_USER"))
return
Expand Down
Loading

0 comments on commit a9ca8ea

Please sign in to comment.