File size: 756 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
package twilio

import (
	"net/url"
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestSignature(t *testing.T) {

	// From twilio docs
	//  https://www.twilio.com/docs/api/security#validating-requests

	const (
		reqURL    = "https://mycompany.com/myapp.php?foo=1&bar=2"
		authToken = "12345"

		// Twilio's example code seems to be incorrect (includes an extra `=`)
		// so this is different than the test example.
		expectedSignature = "GvWf1cFY/Q7PnoempGyD5oXAezc="
	)

	v := make(url.Values)
	v.Set("Digits", "1234")
	v.Set("To", "+18005551212")
	v.Set("From", "+14158675310")
	v.Set("Caller", "+14158675310")
	v.Set("CallSid", "CA1234567890ABCDE")

	sig := Signature(authToken, reqURL, v)
	assert.Equal(t, expectedSignature, string(sig))
}