mirror of
https://github.com/portainer/portainer.git
synced 2025-07-24 07:49:41 +02:00
feat(unit-testing): add a mock for the RequestBouncer EE-5610 (#9089)
This commit is contained in:
parent
933e764a13
commit
f7dd73b0f7
42 changed files with 147 additions and 126 deletions
|
@ -27,7 +27,7 @@ import (
|
|||
type Handler struct {
|
||||
stackCreationMutex *sync.Mutex
|
||||
stackDeletionMutex *sync.Mutex
|
||||
requestBouncer *security.RequestBouncer
|
||||
requestBouncer security.BouncerService
|
||||
*mux.Router
|
||||
DataStore dataservices.DataStore
|
||||
DockerClientFactory *dockerclient.ClientFactory
|
||||
|
@ -48,7 +48,7 @@ func stackExistsError(name string) *httperror.HandlerError {
|
|||
}
|
||||
|
||||
// NewHandler creates a handler to manage stack operations.
|
||||
func NewHandler(bouncer *security.RequestBouncer) *Handler {
|
||||
func NewHandler(bouncer security.BouncerService) *Handler {
|
||||
h := &Handler{
|
||||
Router: mux.NewRouter(),
|
||||
stackCreationMutex: &sync.Mutex{},
|
||||
|
|
|
@ -5,10 +5,11 @@ import (
|
|||
"net/http/httptest"
|
||||
"testing"
|
||||
|
||||
portainer "github.com/portainer/portainer/api"
|
||||
"github.com/portainer/portainer/api/datastore"
|
||||
"github.com/portainer/portainer/api/internal/testhelpers"
|
||||
|
||||
"github.com/gofrs/uuid"
|
||||
portainer "github.com/portainer/portainer/api"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
@ -23,7 +24,7 @@ func TestHandler_webhookInvoke(t *testing.T) {
|
|||
},
|
||||
})
|
||||
|
||||
h := NewHandler(nil)
|
||||
h := NewHandler(testhelpers.NewTestRequestBouncer())
|
||||
h.DataStore = store
|
||||
|
||||
t.Run("invalid uuid results in http.StatusBadRequest", func(t *testing.T) {
|
||||
|
@ -32,12 +33,14 @@ func TestHandler_webhookInvoke(t *testing.T) {
|
|||
h.Router.ServeHTTP(w, req)
|
||||
assert.Equal(t, http.StatusBadRequest, w.Code)
|
||||
})
|
||||
|
||||
t.Run("registered webhook ID in http.StatusNoContent", func(t *testing.T) {
|
||||
w := httptest.NewRecorder()
|
||||
req := newRequest(webhookID)
|
||||
h.Router.ServeHTTP(w, req)
|
||||
assert.Equal(t, http.StatusNoContent, w.Code)
|
||||
})
|
||||
|
||||
t.Run("unregistered webhook ID in http.StatusNotFound", func(t *testing.T) {
|
||||
w := httptest.NewRecorder()
|
||||
req := newRequest(newGuidString(t))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue