-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhmac_php_test.go_save
95 lines (93 loc) · 3.29 KB
/
hmac_php_test.go_save
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package goutils
import (
. "github.com/smartystreets/goconvey/convey"
"os/exec"
"strconv"
"testing"
)
func Test_HMAC_PHP(t *testing.T) {
MyConvey("URL 0", t, func() {
url := "http://www.eklenet.de"
pass := "geheim"
ttl := -1
out, err := exec.Command("php5", "hmac_test/ref.php", url, pass, strconv.Itoa(ttl)).Output()
So(nil, ShouldEqual, err)
So(HMAC.SignUrl(url, pass, ttl), ShouldEqual, string(out))
So(false, ShouldEqual, HMAC.Validate(string(out), pass))
})
MyConvey("URL 1", t, func() {
url := "http://www.eklenet.de"
pass := "geheim"
ttl := 30
out, err := exec.Command("php5", "hmac_test/ref.php", url, pass, strconv.Itoa(ttl)).Output()
So(nil, ShouldEqual, err)
So(HMAC.SignUrl(url, pass, ttl), ShouldEqual, string(out))
So(true, ShouldEqual, HMAC.Validate(string(out), pass))
})
MyConvey("URL 2", t, func() {
url := "http://www.eklenet.de/"
pass := "geheim"
ttl := 30
out, err := exec.Command("php5", "hmac_test/ref.php", url, pass, strconv.Itoa(ttl)).Output()
So(nil, ShouldEqual, err)
So(HMAC.SignUrl(url, pass, ttl), ShouldEqual, string(out))
So(true, ShouldEqual, HMAC.Validate(string(out), pass))
})
MyConvey("URL 3", t, func() {
url := "http://www.eklenet.de/abc"
pass := "geheim"
ttl := 30
out, err := exec.Command("php5", "hmac_test/ref.php", url, pass, strconv.Itoa(ttl)).Output()
So(nil, ShouldEqual, err)
So(HMAC.SignUrl(url, pass, ttl), ShouldEqual, string(out))
So(true, ShouldEqual, HMAC.Validate(string(out), pass))
})
MyConvey("URL 4", t, func() {
url := "http://www.eklenet.de/abc/"
pass := "geheim"
ttl := 30
out, err := exec.Command("php5", "hmac_test/ref.php", url, pass, strconv.Itoa(ttl)).Output()
So(nil, ShouldEqual, err)
So(HMAC.SignUrl(url, pass, 30), ShouldEqual, string(out))
So(true, ShouldEqual, HMAC.Validate(string(out), pass))
})
MyConvey("URL 5", t, func() {
url := "http://www.eklenet.de/abc/def?xyz=123&ok=no"
pass := "geheim"
ttl := 30
out, err := exec.Command("php5", "hmac_test/ref.php", url, pass, strconv.Itoa(ttl)).Output()
So(nil, ShouldEqual, err)
So(HMAC.SignUrl(url, pass, 30), ShouldEqual, string(out))
So(true, ShouldEqual, HMAC.Validate(string(out), pass))
})
MyConvey("URL 6", t, func() {
url := "http://www.eklenet.de/abc/def?ok=no&xyz=123"
pass := "geheim"
ttl := 30
out, err := exec.Command("php5", "hmac_test/ref.php", url, pass, strconv.Itoa(ttl)).Output()
So(nil, ShouldEqual, err)
So(HMAC.SignUrl(url, pass, ttl), ShouldEqual, string(out))
So(true, ShouldEqual, HMAC.Validate(string(out), pass))
})
MyConvey("URL 7", t, func() {
url := "http://www.eklenet.de/abc/def?ok=no&xyz=123#what"
pass := "geheim"
ttl := 30
out, err := exec.Command("php5", "hmac_test/ref.php", url, pass, strconv.Itoa(ttl)).Output()
So(nil, ShouldEqual, err)
So(HMAC.SignUrl(url, pass, ttl), ShouldEqual, string(out))
So(true, ShouldEqual, HMAC.Validate(string(out), pass))
})
MyConvey("URL 8", t, func() {
url := "http://www.eklenet.de/abc/def?ok=no&xyz=123#what"
pass := "geheim"
surl := HMAC.SignUrl(url, pass,30)
So(true, ShouldEqual, HMAC.Validate(surl, pass))
})
MyConvey("URL 9", t, func() {
url := "http://www.eklenet.de/abc/def?ok=no&xyz=123#what"
pass := "geheim"
surl := HMAC.SignUrl(url, pass,30)
So(true, ShouldNotEqual, HMAC.Validate("_"+surl, pass))
})
}