loginsrv

Unnamed repository; edit this file 'description' to name the repository.
git clone git@jamesshield.xyz:repos/loginsrv.git
Log | Files | Refs | README | LICENSE

commit 4309067e07df9d6eceec0913a9ec0a219b791eb0
parent fc5e3a317bacfc6a6e4c93a77486f2be66be0ea7
Author: magikstm <myskina@gmail.com>
Date:   Thu,  9 Nov 2017 00:48:12 -0500

Add a cookie with a valid token to test httpserver.NewReplacer

Diffstat:
Mcaddy/handler_test.go | 17++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/caddy/handler_test.go b/caddy/handler_test.go @@ -1,14 +1,17 @@ package caddy import ( + "github.com/dgrijalva/jwt-go" "github.com/mholt/caddy/caddyhttp/httpserver" "github.com/tarent/loginsrv/login" + "github.com/tarent/loginsrv/model" "net/http" "net/http/httptest" "testing" + "time" ) -func Test_ServeHTTP_200(t *testing.T) { +func Test_ServeHTTP_200(t *testing.T) { //Set the ServeHTTP *http.Request r, err := http.NewRequest("GET", "/", nil) if err != nil { @@ -35,6 +38,18 @@ func Test_ServeHTTP_200(t *testing.T) { loginHandler: loginh, } + //Set user token + userInfo := model.UserInfo{Sub: "bob", Expiry: time.Now().Add(time.Second).Unix()} + token := jwt.NewWithClaims(jwt.SigningMethodHS512, userInfo) + validToken, err := token.SignedString([]byte(h.config.JwtSecret)) + if err != nil { + t.Errorf("Expected nil error, got: %v", err) + } + + //Set cookie for user token on the ServeHTTP http.ResponseWriter + cookie := http.Cookie{Name: "jwt_token",Value: validToken} + http.SetCookie(w, &cookie) + status, err := h.ServeHTTP(w, r) if err != nil {