From 7af66ee9de9ca255cbb37540314af95cf31fbf14 Mon Sep 17 00:00:00 2001 From: Alex <$(pass /github/email)> Date: Wed, 5 Mar 2025 14:54:19 +0100 Subject: [PATCH] added user_password tests --- .../internal/controllers/controllers_test.go | 26 ++- .../internal/controllers/user_Password.go | 4 +- .../controllers/user_Password_test.go | 211 ++++++++++++++++++ .../internal/controllers/user_controller.go | 4 +- .../controllers/user_controller_test.go | 1 + 5 files changed, 239 insertions(+), 7 deletions(-) create mode 100644 go-backend/internal/controllers/user_Password_test.go diff --git a/go-backend/internal/controllers/controllers_test.go b/go-backend/internal/controllers/controllers_test.go index d8c3830..c47c815 100644 --- a/go-backend/internal/controllers/controllers_test.go +++ b/go-backend/internal/controllers/controllers_test.go @@ -50,7 +50,7 @@ var ( Cc *ContactController ) -func TestSuite(t *testing.T) { +func TestMain(t *testing.T) { _ = deleteTestDB("test.db") cwd, err := os.Getwd() @@ -136,7 +136,9 @@ func TestSuite(t *testing.T) { t.Run("userController", func(t *testing.T) { testUserController(t) }) + t.Run("Password_Controller", func(t *testing.T) { + }) t.Run("SQL_Injection", func(t *testing.T) { testSQLInjectionAttempt(t) }) @@ -152,7 +154,6 @@ func TestSuite(t *testing.T) { t.Run("XSSAttempt", func(t *testing.T) { testXSSAttempt(t) }) - if err := utils.SMTPStop(); err != nil { log.Fatalf("Failed to stop SMTP Mockup Server: %#v", err) } @@ -278,10 +279,29 @@ func getBaseUser() models.User { ProfilePicture: "", Password: "passw@#$#%$!-ord123", Company: "", - RoleID: 8, + RoleID: 1, } } +func getBaseSupporter() models.User { + return models.User{ + DateOfBirth: time.Date(2000, time.January, 1, 0, 0, 0, 0, time.UTC), + FirstName: "John", + LastName: "Rich", + Email: "john.supporter@example.com", + Address: "Pablo Escobar Str. 4", + ZipCode: "25474", + City: "Hasloh", + Phone: "01738484993", + BankAccount: models.BankAccount{IBAN: "DE89370400440532013000"}, + Membership: models.Membership{SubscriptionModel: models.SubscriptionModel{Name: "Basic"}}, + Licence: nil, + ProfilePicture: "", + Password: "passw@#$#%$!-ord123", + Company: "", + RoleID: 0, + } +} func deleteTestDB(dbPath string) error { err := os.Remove(dbPath) if err != nil { diff --git a/go-backend/internal/controllers/user_Password.go b/go-backend/internal/controllers/user_Password.go index 9a6dc30..ddb9825 100644 --- a/go-backend/internal/controllers/user_Password.go +++ b/go-backend/internal/controllers/user_Password.go @@ -21,10 +21,10 @@ func (uc *UserController) CreatePasswordHandler(c *gin.Context) { return } if !utils.HasPrivilige(requestUser, constants.Priviliges.AccessControl) { - utils.RespondWithError(c, errors.ErrNotAuthorized, fmt.Sprintf("Not allowed to handle all users. RoleID(%v)