Skip to content

Commit b38424b

Browse files
Juanita De La CuestaJuanita De La Cuesta
authored andcommitted
Func: Add basic test for calculating signature
1 parent b645bba commit b38424b

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

signature/signature_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,24 @@
11
package signature
2+
3+
import (
4+
"bytes"
5+
"encoding/base64"
6+
"testing"
7+
)
8+
9+
const testTs = "1544544948"
10+
const testQp = "abc=foo&def=bar"
11+
const testBody = `{"a key":"some value"}`
12+
const testSignature = "orb0adPhRCYND1WCAvPBr+qjm4STGtyvNDIDNBZ4Ir4="
13+
14+
func TestCalculateSignature(t *testing.T) {
15+
v := NewValidator("other-secret", 2, nil, nil)
16+
s, err := v.CalculateSignature(testTs, testQp, []byte(testBody))
17+
if err != nil {
18+
t.Errorf("Error calculating signature: %s, expected: orb0adPhRCYND1WCAvPBr+qjm4STGtyvNDIDNBZ4Ir4=", s)
19+
}
20+
drs, _ := base64.StdEncoding.DecodeString(testSignature)
21+
if bytes.Compare(s, drs) != 0 {
22+
t.Errorf("Unexpected signature: %s, expected: orb0adPhRCYND1WCAvPBr+qjm4STGtyvNDIDNBZ4Ir4=", s)
23+
}
24+
}

0 commit comments

Comments
 (0)