This commit is contained in:
Markus Schulte
2017-06-20 16:23:02 +02:00
parent 7ceb900c37
commit 2de4e9fc73
5 changed files with 21 additions and 22 deletions
+10 -10
View File
@@ -38,8 +38,8 @@ func TestSetup(t *testing.T) {
"bob": "secret",
},
},
Oauth: login.Options{},
GracePeriod: 5*time.Second,
Oauth: login.Options{},
GracePeriod: 5 * time.Second,
}},
{
input: `login {
@@ -73,8 +73,8 @@ func TestSetup(t *testing.T) {
"client_secret": "secret",
},
},
Oauth: login.Options{},
GracePeriod: 5*time.Second,
Oauth: login.Options{},
GracePeriod: 5 * time.Second,
}},
{ // backwards compatibility
// * login path as argument
@@ -97,8 +97,8 @@ func TestSetup(t *testing.T) {
"bob": "secret",
},
},
Oauth: login.Options{},
GracePeriod: 5*time.Second,
Oauth: login.Options{},
GracePeriod: 5 * time.Second,
}},
{ // backwards compatibility
// * login path as argument
@@ -121,8 +121,8 @@ func TestSetup(t *testing.T) {
"bob": "secret",
},
},
Oauth: login.Options{},
GracePeriod: 5*time.Second,
Oauth: login.Options{},
GracePeriod: 5 * time.Second,
}},
// error cases
@@ -143,8 +143,8 @@ func TestSetup(t *testing.T) {
"bob": "secret",
},
},
Oauth: login.Options{},
GracePeriod: 5*time.Second,
Oauth: login.Options{},
GracePeriod: 5 * time.Second,
}},
{input: "login {\n}", shouldErr: true},
{input: "login xx yy {\n}", shouldErr: true},
-1
View File
@@ -235,7 +235,6 @@ func ServerClosed(appName string) {
Logger.WithFields(fields).Infof("http server was closed: %v", appName)
}
func getRemoteIp(r *http.Request) string {
if r.Header.Get("X-Cluster-Client-Ip") != "" {
return r.Header.Get("X-Cluster-Client-Ip")
+3 -3
View File
@@ -4,8 +4,8 @@ import (
"bytes"
"encoding/json"
"errors"
"github.com/tarent/logrus"
"github.com/stretchr/testify/assert"
"github.com/tarent/logrus"
"net/http"
"os"
"testing"
@@ -319,7 +319,7 @@ func Test_Logger_Cacheinfo(t *testing.T) {
func Test_Logger_GetRemoteIp1(t *testing.T) {
a := assert.New(t)
req, _ := http.NewRequest("GET", "test.com", nil)
req.Header["X-Cluster-Client-Ip"] = []string {"1234"}
req.Header["X-Cluster-Client-Ip"] = []string{"1234"}
ret := getRemoteIp(req)
a.Equal("1234", ret)
}
@@ -327,7 +327,7 @@ func Test_Logger_GetRemoteIp1(t *testing.T) {
func Test_Logger_GetRemoteIp2(t *testing.T) {
a := assert.New(t)
req, _ := http.NewRequest("GET", "test.com", nil)
req.Header["X-Real-Ip"] = []string {"1234"}
req.Header["X-Real-Ip"] = []string{"1234"}
ret := getRemoteIp(req)
a.Equal("1234", ret)
}
+2 -2
View File
@@ -66,7 +66,7 @@ func TestConfig_ReadConfig(t *testing.T) {
"client_secret": "bar",
},
},
GracePeriod: 4*time.Second,
GracePeriod: 4 * time.Second,
}
cfg, err := readConfig(flag.NewFlagSet("", flag.ContinueOnError), input)
@@ -119,7 +119,7 @@ func TestConfig_ReadConfigFromEnv(t *testing.T) {
"client_secret": "bar",
},
},
GracePeriod: 4*time.Second,
GracePeriod: 4 * time.Second,
}
cfg, err := readConfig(flag.NewFlagSet("", flag.ContinueOnError), []string{})
+6 -6
View File
@@ -244,7 +244,7 @@ func TestHandler_Refresh(t *testing.T) {
token, err := h.createToken(input)
NoError(t, err)
cookieStr := "Cookie: "+h.config.CookieName + "=" + token + ";"
cookieStr := "Cookie: " + h.config.CookieName + "=" + token + ";"
// refreshSuccess
recorder := call(req("POST", "/context/login", "", AcceptHTML, cookieStr))
@@ -270,11 +270,11 @@ func TestHandler_Refresh(t *testing.T) {
func TestHandler_Refresh_Expired(t *testing.T) {
h := testHandler()
input := model.UserInfo{Sub: "bob", Expiry: time.Now().Unix()-1}
input := model.UserInfo{Sub: "bob", Expiry: time.Now().Unix() - 1}
token, err := h.createToken(input)
NoError(t, err)
cookieStr := "Cookie: "+h.config.CookieName + "=" + token + ";"
cookieStr := "Cookie: " + h.config.CookieName + "=" + token + ";"
// refreshSuccess
recorder := call(req("POST", "/context/login", "", AcceptHTML, cookieStr))
@@ -288,7 +288,7 @@ func TestHandler_Refresh_Expired(t *testing.T) {
func TestHandler_Refresh_Invalid_Token(t *testing.T) {
h := testHandler()
cookieStr := "Cookie: "+h.config.CookieName + "=kjsbkabsdkjbasdbkasbdk.dfgdfg.fdgdfg;"
cookieStr := "Cookie: " + h.config.CookieName + "=kjsbkabsdkjbasdbkasbdk.dfgdfg.fdgdfg;"
// refreshSuccess
recorder := call(req("POST", "/context/login", "", AcceptHTML, cookieStr))
@@ -301,11 +301,11 @@ func TestHandler_Refresh_Invalid_Token(t *testing.T) {
func TestHandler_Refresh_Max_Refreshes_Reached(t *testing.T) {
h := testHandler()
input := model.UserInfo{Sub: "bob", Expiry: time.Now().Add(time.Second).Unix(), Refreshes:1}
input := model.UserInfo{Sub: "bob", Expiry: time.Now().Add(time.Second).Unix(), Refreshes: 1}
token, err := h.createToken(input)
NoError(t, err)
cookieStr := "Cookie: "+h.config.CookieName + "=" + token + ";"
cookieStr := "Cookie: " + h.config.CookieName + "=" + token + ";"
// refreshSuccess
recorder := call(req("POST", "/context/login", "", AcceptJwt, cookieStr))