Add tests for getSessionId helper

This commit is contained in:
Dan Sosedoff
2016-02-26 08:48:55 -08:00
parent 86f63eecc5
commit c57b477dc9
4 changed files with 21 additions and 7 deletions

View File

@@ -1,8 +1,11 @@
package api
import (
"github.com/stretchr/testify/assert"
"net/http"
"net/url"
"testing"
"github.com/stretchr/testify/assert"
)
func Test_desanitize64(t *testing.T) {
@@ -23,3 +26,13 @@ func Test_cleanQuery(t *testing.T) {
assert.Equal(t, "", cleanQuery("--something"))
assert.Equal(t, "test", cleanQuery("--test\ntest\n -- test\n"))
}
func Test_getSessionId(t *testing.T) {
req := &http.Request{Header: http.Header{}}
req.Header.Add("x-session-id", "token")
assert.Equal(t, "token", getSessionId(req))
req = &http.Request{}
req.URL, _ = url.Parse("http://foobar/?_session_id=token")
assert.Equal(t, "token", getSessionId(req))
}