MCPcopy
hub / github.com/oauth2-proxy/oauth2-proxy / MakeRequestWithExpectedKey

Method MakeRequestWithExpectedKey

oauthproxy_test.go:1612–1645  ·  view source on GitHub ↗
(method, body, key string)

Source from the content-addressed store, hash-verified

1610}
1611
1612func (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
1647func TestRequestSignature(t *testing.T) {
1648 testCases := map[string]struct {

Callers 1

TestRequestSignatureFunction · 0.95

Calls 5

SaveSessionMethod · 0.95
ServeHTTPMethod · 0.95
ValidateFunction · 0.92
NewHmacAuthFunction · 0.92
NewOAuthProxyFunction · 0.85

Tested by

no test coverage detected