forked from koltyakov/gosip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
util_test.go
68 lines (54 loc) · 1.68 KB
/
util_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
package gosip
import (
"fmt"
"io"
"net"
"net/http"
)
type AnonymousCnfg struct {
SiteURL string `json:"siteUrl"` // SPSite or SPWeb URL, which is the context target for the API calls
Strategy string
}
// ReadConfig reads private config with auth options
// noinspection GoUnusedParameter
func (c *AnonymousCnfg) ReadConfig(privateFile string) error { return nil }
// ParseConfig parses credentials from a provided JSON byte array content
// noinspection GoUnusedParameter
func (c *AnonymousCnfg) ParseConfig(bytesValue []byte) error { return nil }
// WriteConfig : writes private config with auth options
// noinspection GoUnusedParameter
func (c *AnonymousCnfg) WriteConfig(privateFile string) error { return nil }
// GetAuth : authenticates, receives access token
func (c *AnonymousCnfg) GetAuth() (string, int64, error) { return "", 0, nil }
// GetSiteURL : gets siteURL
func (c *AnonymousCnfg) GetSiteURL() string { return c.SiteURL }
// GetStrategy : gets auth strategy name
func (c *AnonymousCnfg) GetStrategy() string {
if c.Strategy != "" {
return c.Strategy
}
return "anonymous"
}
// SetAuth : authenticate request
// noinspection GoUnusedParameter
func (c *AnonymousCnfg) SetAuth(req *http.Request, httpClient *SPClient) error {
if c.SiteURL == "http://restricted" {
return fmt.Errorf("can't set auth")
}
return nil
}
// Fake server bootstrap helper
func startFakeServer(addr string, handler http.Handler) (io.Closer, error) {
srv := &http.Server{Addr: addr, Handler: handler}
if addr == "" {
addr = ":8989"
}
listener, err := net.Listen("tcp", addr)
if err != nil {
return nil, err
}
go func() {
_ = srv.Serve(listener.(*net.TCPListener))
}()
return listener, nil
}