|
|
|
|
|
|
|
|
log.Printf("TestGetAccesstoken got: [%s] ", m) |
|
|
log.Printf("TestGetAccesstoken got: [%s] ", m) |
|
|
AssertEqual(t, m != errorResponse, true, "Signature check failed, error response") |
|
|
AssertEqual(t, m != errorResponse, true, "Signature check failed, error response") |
|
|
AssertEqual(t, m, expected, "token incorrect") |
|
|
AssertEqual(t, m, expected, "token incorrect") |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestGetAccesstokenUnAuthorized(t *testing.T) { |
|
|
|
|
|
req := buildReqGetAccessTokenUnAuthorized() |
|
|
|
|
|
rr, _ := getHTTPResponse(req, supplyAccessToken) |
|
|
|
|
|
errorResponse := "unauthorized" |
|
|
|
|
|
m := rr.Body.String() |
|
|
|
|
|
expected, _ := GetAccessToken() |
|
|
|
|
|
log.Printf("TestGetAccesstoken got: [%s] ", m) |
|
|
|
|
|
AssertEqual(t, m, errorResponse, "should be unauthorized") |
|
|
|
|
|
AssertEqual(t, m != expected, true, "token should not be returned") |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func getHTTPResponse(req *http.Request, handler http.HandlerFunc) (rr *httptest.ResponseRecorder, err error) { |
|
|
func getHTTPResponse(req *http.Request, handler http.HandlerFunc) (rr *httptest.ResponseRecorder, err error) { |
|
|
|
|
|
|
|
|
return req |
|
|
return req |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func buildReqGetAccessTokenUnAuthorized() *http.Request { |
|
|
|
|
|
req, err := http.NewRequest("GET", "/iapi/getAccessToken", nil) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
log.Fatal(err) |
|
|
|
|
|
} |
|
|
|
|
|
//buildReqCommonSignature(req, IntraAPIConfig.CRMSecrete) |
|
|
|
|
|
buildReqCommonHeader(req) |
|
|
|
|
|
return req |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
func buildSignature(token string) (signature, timestamp, nonce string) { |
|
|
func buildSignature(token string) (signature, timestamp, nonce string) { |
|
|
timestamp = fmt.Sprintf("%d", int32(time.Now().Unix())) |
|
|
timestamp = fmt.Sprintf("%d", int32(time.Now().Unix())) |
|
|
nonce = "1461107899" //a randome string cut from previous wechat request |
|
|
nonce = "1461107899" //a randome string cut from previous wechat request |