generated from traefik/plugindemo
-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
ldapauth_test.go
42 lines (31 loc) · 854 Bytes
/
ldapauth_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// Package ldapAuth_test a test suit for ldap authentication plugin.
//nolint
package ldapAuth_test
import (
"context"
"net/http"
"net/http/httptest"
"testing"
"github.com/wiltonsr/ldapAuth"
)
func TestDemo(t *testing.T) {
cfg := ldapAuth.CreateConfig()
ctx := context.Background()
next := http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {})
handler, err := ldapAuth.New(ctx, next, cfg, "ldapAuth")
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 assertHeader(t *testing.T, req *http.Request, key, expected string) {
t.Helper()
if req.Header.Get(key) != expected {
t.Errorf("invalid header value: %s", req.Header.Get(key))
}
}