-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathwebsite_key_credential_test.go
47 lines (34 loc) · 1.31 KB
/
website_key_credential_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
package sdk
import (
"net/http/httptest"
"testing"
"github.com/smarty/assertions/should"
"github.com/smarty/gunit"
)
func TestWebsiteKeyCredentialFixture(t *testing.T) {
gunit.Run(new(WebsiteKeyCredentialFixture), t)
}
type WebsiteKeyCredentialFixture struct {
*gunit.Fixture
}
func (this *WebsiteKeyCredentialFixture) TestWebsiteKeySigning() {
credential := NewWebsiteKeyCredential("12345", "abc.com")
request := httptest.NewRequest("GET", "/", nil)
credential.Sign(request)
this.So(request.URL.Query().Get("key"), should.Equal, "12345")
this.So(request.Header.Get("Referer"), should.Equal, "http://abc.com")
}
func (this *WebsiteKeyCredentialFixture) TestHostAlreadyHasHTTPScheme() {
credential := NewWebsiteKeyCredential("12345", "http://abc.com")
request := httptest.NewRequest("GET", "/", nil)
credential.Sign(request)
this.So(request.URL.Query().Get("key"), should.Equal, "12345")
this.So(request.Header.Get("Referer"), should.Equal, "http://abc.com")
}
func (this *WebsiteKeyCredentialFixture) TestHostAlreadyHasHTTPSScheme() {
credential := NewWebsiteKeyCredential("12345", "https://abc.com")
request := httptest.NewRequest("GET", "/", nil)
credential.Sign(request)
this.So(request.URL.Query().Get("key"), should.Equal, "12345")
this.So(request.Header.Get("Referer"), should.Equal, "https://abc.com")
}