mirror of
https://github.com/maxlerebourg/crowdsec-bouncer-traefik-plugin.git
synced 2026-07-21 11:38:59 +02:00
* ✨ Add support for insecure tls connections to LAPI * 📝 Add documentation for the TLS insecure parameter * 🚧 Add tls authority certificate and checks for params * 📝 Add example for tls communication in readme and folder * 📝 Update documentation and example for tls * 🚨 Fix easy lint errors * 🦺 logic to fetch certificates * 🚨 Fix lint on readme * ♻️ Refactor validate to fix lint and clean * 🚧 Add doc, cert gen for crowdsec example * 🚧 Progress on setting up Crowdsec with tls * 🚧 Update certs validation for example * ♻️ Add load variable from file or value and get client cert * ♻️ Refactor getting variables * 🚨 Fix lint, no new line on new files * 🐛 Fix bug on condition check lapi key cert * ♻️ Update after review * ♻️ Update after review * 🍱 fix mathieu code * ♻️ Refactor logic of loading tls certificates * 🍱 clean code * 🍱 last fix * 🍱 fix lint * ♻️ Add documentation in readme, fix lint, remove unfinished tests * 🐛 Fix conditions logics * 🚨 Fix Lint * ♻️ simplify code on getVariable Co-authored-by: Max Lerebourg <maxlerebourg@gmail.com>
93 lines
2.1 KiB
Go
93 lines
2.1 KiB
Go
package crowdsec_bouncer_traefik_plugin //nolint:revive,stylecheck
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
)
|
|
|
|
func TestCreation(t *testing.T) {
|
|
cfg := CreateConfig()
|
|
cfg.CrowdsecLapiKey = "test"
|
|
|
|
ctx := context.Background()
|
|
next := http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {})
|
|
|
|
handler, err := New(ctx, next, cfg, "demo-plugin")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
recorder := httptest.NewRecorder()
|
|
req, err := http.NewRequestWithContext(ctx, http.MethodGet, "http://localhost", nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
handler.ServeHTTP(recorder, req)
|
|
}
|
|
|
|
// func TestValidateParamsCrowdsecLapiKey(t *testing.T) {
|
|
// cfg := CreateConfig()
|
|
// err := validateParams(cfg)
|
|
// fmt.Println(err.Error())
|
|
// if err == nil {
|
|
// t.Errorf("Need error here %s", err.Error())
|
|
// }
|
|
// }
|
|
|
|
// func TestValidateParamsCrowdsecLapiScheme(t *testing.T) {
|
|
// cfg := CreateConfig()
|
|
// cfg.CrowdsecLapiKey = "test"
|
|
// cfg.CrowdsecLapiScheme = "bad"
|
|
// err := validateParams(cfg)
|
|
// fmt.Println(err.Error())
|
|
// if err == nil {
|
|
// t.Errorf("Need error here %s", err.Error())
|
|
// }
|
|
// }
|
|
|
|
// func TestValidateParamsCrowdsecMode(t *testing.T) {
|
|
// cfg := CreateConfig()
|
|
// cfg.CrowdsecLapiKey = "test"
|
|
// cfg.CrowdsecMode = "bad"
|
|
// err := validateParams(cfg)
|
|
// fmt.Println(err.Error())
|
|
// if err == nil {
|
|
// t.Errorf("Need error here %s", err.Error())
|
|
// }
|
|
// }
|
|
|
|
// func TestValidateParamsUpdateIntervalSeconds(t *testing.T) {
|
|
// cfg := CreateConfig()
|
|
// cfg.CrowdsecLapiKey = "test"
|
|
// cfg.UpdateIntervalSeconds = 0
|
|
// err := validateParams(cfg)
|
|
// fmt.Println(err.Error())
|
|
// if err == nil {
|
|
// t.Errorf("Need error here %s", err.Error())
|
|
// }
|
|
// }
|
|
|
|
func TestServeHTTP(t *testing.T) {
|
|
cfg := CreateConfig()
|
|
cfg.CrowdsecLapiKey = "test"
|
|
|
|
ctx := context.Background()
|
|
next := http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {})
|
|
|
|
handler, err := New(ctx, next, cfg, "demo-plugin")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
recorder := httptest.NewRecorder()
|
|
req, err := http.NewRequestWithContext(ctx, http.MethodGet, "http://localhost", nil)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
handler.ServeHTTP(recorder, req)
|
|
}
|