-
Notifications
You must be signed in to change notification settings - Fork 33
/
digest_test.go
45 lines (38 loc) · 1.03 KB
/
digest_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
package gosip
import (
"fmt"
"net/http"
"testing"
)
func TestDigest(t *testing.T) {
siteURL := "http://localhost:8989"
digestTriggered := false
closer, err := startFakeServer(":8989", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// faking digest response
if r.RequestURI == "/_api/ContextInfo" {
digestTriggered = true
_, _ = fmt.Fprintf(w, `{"d":{"GetContextWebInformation":{"FormDigestValue":"FAKE","FormDigestTimeoutSeconds":120,"LibraryVersion":"FAKE"}}}`)
return
}
_, _ = fmt.Fprintf(w, `{ "result": "Cool alfter some retries" }`)
}))
if err != nil {
t.Fatal(err)
}
defer func() { _ = closer.Close() }()
t.Run("ShouldTriggerDigest", func(t *testing.T) {
client := &SPClient{
AuthCnfg: &AnonymousCnfg{SiteURL: siteURL},
}
req, err := http.NewRequest("POST", client.AuthCnfg.GetSiteURL()+"/_api/post", nil)
if err != nil {
t.Fatal(err)
}
if _, err := client.Execute(req); err != nil {
t.Error(err)
}
if !digestTriggered {
t.Error("digest is not retrieved")
}
})
}