overflow_probe/oauth_api/oauth_test.go

36 lines
811 B
Go
Raw Normal View History

2017-08-03 10:08:34 +00:00
package main
import (
"errors"
"golang.org/x/net/context"
"golang.org/x/oauth2"
"net/http"
"testing"
)
type appOAuthTransfer1 struct {
rt func(req *http.Request) (resp *http.Response, err error)
}
func (t *appOAuthTransfer1) RoundTrip(req *http.Request) (resp *http.Response, err error) {
return t.rt(req)
}
func TestExchangeRequest(t *testing.T) {
tr := &appOAuthTransfer1{
rt: func(r *http.Request) (w *http.Response, err error) {
headerAuth := r.Header.Get("Authorization")
if headerAuth != "" {
t.Errorf("Unexpected authorization header, %v is found.", headerAuth)
}
return nil, errors.New("no response")
},
}
c := &http.Client{Transport: tr}
conf := getConfig(FB_TYPE)
ctx := context.WithValue(context.Background(), oauth2.HTTPClient, c)
conf.Exchange(ctx, "code")
}