-
Notifications
You must be signed in to change notification settings - Fork 129
/
ntlm_test.go
57 lines (48 loc) · 1.66 KB
/
ntlm_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
package winrm
import (
"net/http"
"net"
"time"
. "gopkg.in/check.v1"
)
func (s *WinRMSuite) TestHttpNTLMRequest(c *C) {
ts, host, port, err := StartTestServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/soap+xml")
_, _ = w.Write([]byte(response))
}))
c.Assert(err, IsNil)
defer ts.Close()
endpoint := NewEndpoint(host, port, false, false, nil, nil, nil, 0)
params := DefaultParameters
params.TransportDecorator = func() Transporter { return &ClientNTLM{} }
client, err := NewClientWithParameters(endpoint, "test", "test", params)
c.Assert(err, IsNil)
shell, err := client.CreateShell()
c.Assert(err, IsNil)
c.Assert(shell.id, Equals, "67A74734-DD32-4F10-89DE-49A060483810")
}
func (s *WinRMSuite) TestHttpNTLMViaCustomDialerRequest(c *C) {
normalDialer := (&net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
}).Dial
usedCustomDialer := false
dial := func(network, addr string) (net.Conn, error) {
usedCustomDialer = true
return normalDialer(network, addr)
}
ts, host, port, err := StartTestServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/soap+xml")
_, _ = w.Write([]byte(response))
}))
c.Assert(err, IsNil)
defer ts.Close()
endpoint := NewEndpoint(host, port, false, false, nil, nil, nil, 0)
params := DefaultParameters
params.TransportDecorator = func() Transporter { return NewClientNTLMWithDial(dial) }
client, err := NewClientWithParameters(endpoint, "test", "test", params)
c.Assert(err, IsNil)
_, err = client.CreateShell()
c.Assert(err, IsNil)
c.Assert(usedCustomDialer, Equals, true)
}