fix header settings upon auth. failure, add amqp connection to user/ scenario duplication test

This commit is contained in:
Sonja Happ 2021-10-19 11:36:04 +02:00
parent d6ab81a0f9
commit 9af822b801
2 changed files with 22 additions and 2 deletions

View file

@ -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

View file

@ -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!!
}