loginsrv

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

google_test.go (1303B)


      1 package oauth2
      2 
      3 import (
      4 	"net/http"
      5 	"net/http/httptest"
      6 	"testing"
      7 
      8 	. "github.com/stretchr/testify/assert"
      9 )
     10 
     11 var googleTestUserResponse = `{
     12   "sub": "10467329456789",
     13   "name": "Testy Test",
     14   "given_name": "Testy",
     15   "family_name": "Test",
     16   "profile": "https://plus.google.com/10467329456789",
     17   "picture": "https://lh6.googleusercontent.com/-alknmlknzT_YQ/AAAAAAAAAAI/AAAAAAAAABU/4gNvDUeED14/photo.jpg",
     18   "email": "test@example.com",
     19   "email_verified": true,
     20   "gender": "male",
     21   "locale": "de",
     22   "hd": "example.com"
     23 }`
     24 
     25 func Test_Google_getUserInfo(t *testing.T) {
     26 	server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
     27 		Equal(t, "secret", r.FormValue("access_token"))
     28 		w.Header().Set("Content-Type", "application/json; charset=utf-8")
     29 		w.Write([]byte(googleTestUserResponse))
     30 	}))
     31 	defer server.Close()
     32 
     33 	googleUserinfoEndpoint = server.URL
     34 
     35 	u, rawJSON, err := providerGoogle.GetUserInfo(TokenInfo{AccessToken: "secret"})
     36 	NoError(t, err)
     37 	Equal(t, "test@example.com", u.Sub)
     38 	Equal(t, "test@example.com", u.Email)
     39 	Equal(t, "https://lh6.googleusercontent.com/-alknmlknzT_YQ/AAAAAAAAAAI/AAAAAAAAABU/4gNvDUeED14/photo.jpg", u.Picture)
     40 	Equal(t, "Testy Test", u.Name)
     41 	Equal(t, "example.com", u.Domain)
     42 	Equal(t, googleTestUserResponse, rawJSON)
     43 }