forked from greenpau/caddy-auth-portal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplugin_test.go
69 lines (64 loc) · 1.88 KB
/
plugin_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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright 2020 Paul Greenberg (greenpau@outlook.com)
package portal
import (
"github.com/caddyserver/caddy/v2/caddytest"
"io/ioutil"
"net/http"
"strings"
"testing"
"time"
)
func TestLocalConfig(t *testing.T) {
scheme := "https"
host := "127.0.0.1"
// port := "3080"
securePort := "3443"
authPath := "auth"
hostPort := host + ":" + securePort
baseURL := scheme + "://" + hostPort
tester := caddytest.NewTester(t)
configFile := "assets/conf/local/config.json"
configContent, err := ioutil.ReadFile(configFile)
if err != nil {
t.Fatalf("Failed to load configuration file %s: %s", configFile, err)
}
rawConfig := string(configContent)
tester.InitServer(rawConfig, "json")
tester.AssertGetResponse(baseURL+"/version", 200, "1.0.0")
req, _ := http.NewRequest(
"POST",
baseURL+"/"+authPath,
strings.NewReader("username=webadmin&password=password123"),
)
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
resp := tester.AssertResponseCode(req, 200)
t.Logf("%v", resp)
time.Sleep(1 * time.Second)
}
func TestLdapConfig(t *testing.T) {
scheme := "https"
host := "127.0.0.1"
// port := "3080"
securePort := "3443"
authPath := "auth"
hostPort := host + ":" + securePort
baseURL := scheme + "://" + hostPort
tester := caddytest.NewTester(t)
configFile := "assets/conf/ldap/config.json"
configContent, err := ioutil.ReadFile(configFile)
if err != nil {
t.Fatalf("Failed to load configuration file %s: %s", configFile, err)
}
rawConfig := string(configContent)
tester.InitServer(rawConfig, "json")
tester.AssertGetResponse(baseURL+"/version", 200, "1.0.0")
req, _ := http.NewRequest(
"POST",
baseURL+"/"+authPath,
strings.NewReader("username=webadmin&password=password123&realm=local"),
)
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
resp := tester.AssertResponseCode(req, 200)
t.Logf("%v", resp)
time.Sleep(1 * time.Second)
}