Fix bug where form was posting to the wrong path

Signed-off-by: Margo Crawford <margaretc@vmware.com>
This commit is contained in:
Margo Crawford 2022-05-03 15:18:38 -07:00
parent 69e5169fc5
commit 388cdb6ddd
3 changed files with 5 additions and 3 deletions

View File

@ -28,6 +28,7 @@ type PageData struct {
HasAlertError bool HasAlertError bool
AlertMessage string AlertMessage string
Title string Title string
PostPath string
} }
func NewGetHandler(upstreamIDPs oidc.UpstreamIdentityProvidersLister) HandlerFunc { func NewGetHandler(upstreamIDPs oidc.UpstreamIdentityProvidersLister) HandlerFunc {
@ -44,6 +45,7 @@ func NewGetHandler(upstreamIDPs oidc.UpstreamIdentityProvidersLister) HandlerFun
HasAlertError: alertError != "", HasAlertError: alertError != "",
AlertMessage: message, AlertMessage: message,
Title: "Pinniped", Title: "Pinniped",
PostPath: r.URL.Path, // the path for POST is the same as for GET
}) })
if err != nil { if err != nil {
return err return err

View File

@ -98,7 +98,7 @@ func TestGetLogin(t *testing.T) {
tt := test tt := test
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
handler := NewGetHandler(tt.idps) handler := NewGetHandler(tt.idps)
target := "/login?state=" + tt.encodedState target := "/some/path/login?state=" + tt.encodedState
if tt.errParam != "" { if tt.errParam != "" {
target += "&err=" + tt.errParam target += "&err=" + tt.errParam
} }
@ -126,7 +126,7 @@ func getHTMLResult(errorBanner string) string {
<h1>Pinniped</h1> <h1>Pinniped</h1>
<p>some-ldap-idp</p> <p>some-ldap-idp</p>
%s %s
<form action="/login" method="post"> <form action="/some/path/login" method="post" target="_parent">
<div> <div>
<label for="username"><b>Username</b></label> <label for="username"><b>Username</b></label>

View File

@ -15,7 +15,7 @@ SPDX-License-Identifier: Apache-2.0
<span>{{.AlertMessage}}</span> <span>{{.AlertMessage}}</span>
</div> </div>
{{end}} {{end}}
<form action="/login" method="post"> <form action="{{.PostPath}}" method="post" target="_parent">
<div> <div>
<label for="username"><b>Username</b></label> <label for="username"><b>Username</b></label>