(method, body, key string)
| 1610 | } |
| 1611 | |
| 1612 | func (st *SignatureTest) MakeRequestWithExpectedKey(method, body, key string) error { |
| 1613 | err := validation.Validate(st.opts) |
| 1614 | if err != nil { |
| 1615 | return err |
| 1616 | } |
| 1617 | proxy, err := NewOAuthProxy(st.opts, func(email string) bool { return true }) |
| 1618 | if err != nil { |
| 1619 | return err |
| 1620 | } |
| 1621 | proxy.provider = st.authProvider |
| 1622 | |
| 1623 | var bodyBuf io.ReadCloser |
| 1624 | if body != "" { |
| 1625 | bodyBuf = io.NopCloser(&fakeNetConn{reqBody: body}) |
| 1626 | } |
| 1627 | req := httptest.NewRequest(method, "/foo/bar", bodyBuf) |
| 1628 | req.Header = st.header |
| 1629 | |
| 1630 | state := &sessions.SessionState{ |
| 1631 | Email: "mbland@acm.org", AccessToken: "my_access_token"} |
| 1632 | err = proxy.SaveSession(st.rw, req, state) |
| 1633 | if err != nil { |
| 1634 | return err |
| 1635 | } |
| 1636 | for _, c := range st.rw.Result().Cookies() { |
| 1637 | req.AddCookie(c) |
| 1638 | } |
| 1639 | // This is used by the upstream to validate the signature. |
| 1640 | st.authenticator.auth = hmacauth.NewHmacAuth( |
| 1641 | crypto.SHA1, []byte(key), upstream.SignatureHeader, upstream.SignatureHeaders) |
| 1642 | proxy.ServeHTTP(st.rw, req) |
| 1643 | |
| 1644 | return nil |
| 1645 | } |
| 1646 | |
| 1647 | func TestRequestSignature(t *testing.T) { |
| 1648 | testCases := map[string]struct { |
no test coverage detected