36 lines
811 B
Go
36 lines
811 B
Go
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")
|
|
}
|