Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add http method into session.MatchContext #676

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions pipeline/authn/authenticator.go
Expand Up @@ -49,6 +49,7 @@ type AuthenticationSession struct {
type MatchContext struct {
RegexpCaptureGroups []string `json:"regexp_capture_groups"`
URL *url.URL `json:"url"`
Method string `json:"method"`
}

func (a *AuthenticationSession) SetHeader(key, val string) {
Expand Down
3 changes: 3 additions & 0 deletions pipeline/authn/authenticator_test.go
Expand Up @@ -50,6 +50,7 @@ func TestCopy(t *testing.T) {
MatchContext: authn.MatchContext{
RegexpCaptureGroups: []string{"a", "b"},
URL: x.ParseURLOrPanic("https://foo/bar"),
Method: "GET",
},
}

Expand All @@ -59,10 +60,12 @@ func TestCopy(t *testing.T) {
copied.Header.Add("bazbar", "bar")
copied.MatchContext.URL.Host = "asdf"
copied.MatchContext.RegexpCaptureGroups[0] = "b"
copied.MatchContext.Method = "PUT"

assert.NotEqual(original.Subject, copied.Subject)
assert.NotEqual(original.Extra, copied.Extra)
assert.NotEqual(original.Header, copied.Header)
assert.NotEqual(original.MatchContext.URL.Host, copied.MatchContext.URL.Host)
assert.NotEqual(original.MatchContext.RegexpCaptureGroups, copied.MatchContext.RegexpCaptureGroups)
assert.NotEqual(original.MatchContext.Method, copied.MatchContext.Method)
}
1 change: 1 addition & 0 deletions proxy/request_handler.go
Expand Up @@ -350,6 +350,7 @@ func (d *RequestHandler) InitializeAuthnSession(r *http.Request, rl *rule.Rule)
session.MatchContext = authn.MatchContext{
RegexpCaptureGroups: values,
URL: r.URL,
Method: r.Method,
}
}

Expand Down
7 changes: 6 additions & 1 deletion proxy/request_handler_test.go
Expand Up @@ -44,7 +44,7 @@ import (
)

func newTestRequest(u string) *http.Request {
return &http.Request{URL: x.ParseURLOrPanic(u)}
return &http.Request{URL: x.ParseURLOrPanic(u), Method: "GET"}
}

func TestHandleError(t *testing.T) {
Expand Down Expand Up @@ -477,6 +477,7 @@ func TestInitializeSession(t *testing.T) {
expectContext: authn.MatchContext{
RegexpCaptureGroups: []string{},
URL: x.ParseURLOrPanic("http://localhost"),
Method: "GET",
},
},
{
Expand All @@ -489,6 +490,7 @@ func TestInitializeSession(t *testing.T) {
expectContext: authn.MatchContext{
RegexpCaptureGroups: []string{"user"},
URL: x.ParseURLOrPanic("http://localhost/user"),
Method: "GET",
},
},
{
Expand All @@ -501,6 +503,7 @@ func TestInitializeSession(t *testing.T) {
expectContext: authn.MatchContext{
RegexpCaptureGroups: []string{"user"},
URL: x.ParseURLOrPanic("http://localhost/user?param=test"),
Method: "GET",
},
},
{
Expand All @@ -513,6 +516,7 @@ func TestInitializeSession(t *testing.T) {
expectContext: authn.MatchContext{
RegexpCaptureGroups: []string{"http", "user"},
URL: x.ParseURLOrPanic("http://localhost/user?param=test"),
Method: "GET",
},
},
{
Expand All @@ -525,6 +529,7 @@ func TestInitializeSession(t *testing.T) {
expectContext: authn.MatchContext{
RegexpCaptureGroups: []string{},
URL: x.ParseURLOrPanic("http://localhost/user?param=test"),
Method: "GET",
},
},
} {
Expand Down