From 9af822b8011e89755a3b9e3fac7e4106873d77c8 Mon Sep 17 00:00:00 2001 From: Sonja Happ Date: Tue, 19 Oct 2021 11:36:04 +0200 Subject: [PATCH] fix header settings upon auth. failure, add amqp connection to user/ scenario duplication test --- routes/user/authenticate_endpoint.go | 8 ++++++-- routes/user/user_test.go | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/routes/user/authenticate_endpoint.go b/routes/user/authenticate_endpoint.go index 6f2da8e..e2dcd07 100644 --- a/routes/user/authenticate_endpoint.go +++ b/routes/user/authenticate_endpoint.go @@ -126,7 +126,8 @@ func authenticate(c *gin.Context) { case "internal": myUser, err = authenticateInternal(c) if err != nil { - helper.BadRequestError(c, err.Error()) + log.Println("internal auth. failed with error: ", err.Error()) + return } case "external": var authExternal bool @@ -134,13 +135,16 @@ func authenticate(c *gin.Context) { if err == nil && authExternal { myUser, err = authenticateExternal(c) if err != nil { - helper.BadRequestError(c, err.Error()) + log.Println("external auth. failed with error: ", err) + return } } else { helper.BadRequestError(c, "External authentication is not activated") + return } default: helper.BadRequestError(c, "Invalid authentication mechanism") + return } // Check if this is an active user diff --git a/routes/user/user_test.go b/routes/user/user_test.go index 0f3ab24..e5dcb2d 100644 --- a/routes/user/user_test.go +++ b/routes/user/user_test.go @@ -25,11 +25,13 @@ import ( "bytes" "encoding/json" "fmt" + infrastructure_component "git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/infrastructure-component" "net/http" "net/http/httptest" "os" "strings" "testing" + "time" "git.rwth-aachen.de/acs/public/villas/web-backend-go/helper" @@ -835,6 +837,20 @@ func TestDuplicateScenarioForUser(t *testing.T) { database.MigrateModels() assert.NoError(t, database.AddTestUsers()) + // connect AMQP client + // Make sure that AMQP_HOST, AMQP_USER, AMQP_PASS are set + host, _ := configuration.GlobalConfig.String("amqp.host") + usr, _ := configuration.GlobalConfig.String("amqp.user") + pass, _ := configuration.GlobalConfig.String("amqp.pass") + amqpURI := "amqp://" + usr + ":" + pass + "@" + host + + // AMQP Connection startup is tested here + // Not repeated in other tests because it is only needed once + session = helper.NewAMQPSession("villas-test-session", amqpURI, "villas", infrastructure_component.ProcessMessage) + SetAMQPSession(session) + + time.Sleep(3 * time.Second) + // TODO test duplicate scenario for user function here!! }