mirror of
https://github.com/pomerium/pomerium.git
synced 2025-06-16 01:32:56 +02:00
authenticate: fix expiring user info endpoint (#2976)
* authenticate: fix expiring user info endpoint * add test
This commit is contained in:
parent
fbdbe9c86f
commit
2f328e7de0
4 changed files with 122 additions and 37 deletions
52
authenticate/url_test.go
Normal file
52
authenticate/url_test.go
Normal file
|
@ -0,0 +1,52 @@
|
|||
package authenticate
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/pomerium/pomerium/internal/urlutil"
|
||||
)
|
||||
|
||||
func TestAuthenticate_getRedirectURI(t *testing.T) {
|
||||
t.Run("query", func(t *testing.T) {
|
||||
r, err := http.NewRequest("GET", "https://www.example.com?"+(url.Values{
|
||||
urlutil.QueryRedirectURI: {"https://www.example.com/redirect"},
|
||||
}).Encode(), nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
a := new(Authenticate)
|
||||
redirectURI, ok := a.getRedirectURI(r)
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, "https://www.example.com/redirect", redirectURI)
|
||||
})
|
||||
t.Run("form", func(t *testing.T) {
|
||||
r, err := http.NewRequest("POST", "https://www.example.com", strings.NewReader((url.Values{
|
||||
urlutil.QueryRedirectURI: {"https://www.example.com/redirect"},
|
||||
}).Encode()))
|
||||
require.NoError(t, err)
|
||||
r.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||
|
||||
a := new(Authenticate)
|
||||
redirectURI, ok := a.getRedirectURI(r)
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, "https://www.example.com/redirect", redirectURI)
|
||||
})
|
||||
t.Run("cookie", func(t *testing.T) {
|
||||
r, err := http.NewRequest("GET", "https://www.example.com", nil)
|
||||
require.NoError(t, err)
|
||||
r.AddCookie(&http.Cookie{
|
||||
Name: urlutil.QueryRedirectURI,
|
||||
Value: "https://www.example.com/redirect",
|
||||
})
|
||||
|
||||
a := new(Authenticate)
|
||||
redirectURI, ok := a.getRedirectURI(r)
|
||||
assert.True(t, ok)
|
||||
assert.Equal(t, "https://www.example.com/redirect", redirectURI)
|
||||
})
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue