From 3e3efbd5d362b9c9765285bbd89c78cb6942ab13 Mon Sep 17 00:00:00 2001 From: simpleway Date: Tue, 27 Apr 2021 05:59:47 -0600 Subject: [PATCH] fix: login and consent redirect behavior change since 1.9.x (#2457) Allow #fragment in configured url to keep backwards compatibility. Close #2363 Co-authored-by: hackerman <3372410+aeneasr@users.noreply.github.com> --- driver/config/provider.go | 4 ++-- driver/config/provider_test.go | 40 ++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/driver/config/provider.go b/driver/config/provider.go index ceafe5970c4..56cbb88b7ce 100644 --- a/driver/config/provider.go +++ b/driver/config/provider.go @@ -329,7 +329,7 @@ func (p *Provider) fallbackURL(path string, host string, port int) *url.URL { } func (p *Provider) LoginURL() *url.URL { - return urlRoot(p.p.RequestURIF(KeyLoginURL, p.publicFallbackURL("oauth2/fallbacks/login"))) + return urlRoot(p.p.URIF(KeyLoginURL, p.publicFallbackURL("oauth2/fallbacks/login"))) } func (p *Provider) LogoutURL() *url.URL { @@ -337,7 +337,7 @@ func (p *Provider) LogoutURL() *url.URL { } func (p *Provider) ConsentURL() *url.URL { - return urlRoot(p.p.RequestURIF(KeyConsentURL, p.publicFallbackURL("oauth2/fallbacks/consent"))) + return urlRoot(p.p.URIF(KeyConsentURL, p.publicFallbackURL("oauth2/fallbacks/consent"))) } func (p *Provider) ErrorURL() *url.URL { diff --git a/driver/config/provider_test.go b/driver/config/provider_test.go index 24fda6f6b43..5859364ea86 100644 --- a/driver/config/provider_test.go +++ b/driver/config/provider_test.go @@ -314,3 +314,43 @@ func TestViperProviderValidates(t *testing.T) { }, }, c.Tracing()) } + +func TestSetPerm(t *testing.T) { + f, e := ioutil.TempFile("", "test") + require.NoError(t, e) + path := f.Name() + + // We cannot test setting owner and group, because we don't know what the + // tester has access to. + _ = (&configx.UnixPermission{ + Owner: "", + Group: "", + Mode: 0654, + }).SetPermission(path) + + stat, err := f.Stat() + require.NoError(t, err) + + assert.Equal(t, os.FileMode(0654), stat.Mode()) + + require.NoError(t, f.Close()) + require.NoError(t, os.Remove(path)) +} + +func TestLoginConsentURL(t *testing.T) { + l := logrusx.New("", "") + l.Logrus().SetOutput(ioutil.Discard) + p := MustNew(l) + p.MustSet(KeyLoginURL, "http://localhost:8080/oauth/login") + p.MustSet(KeyConsentURL, "http://localhost:8080/oauth/consent") + + assert.Equal(t, "http://localhost:8080/oauth/login", p.LoginURL().String()) + assert.Equal(t, "http://localhost:8080/oauth/consent", p.ConsentURL().String()) + + p2 := MustNew(l) + p2.MustSet(KeyLoginURL, "http://localhost:3000/#/oauth/login") + p2.MustSet(KeyConsentURL, "http://localhost:3000/#/oauth/consent") + + assert.Equal(t, "http://localhost:3000/#/oauth/login", p2.LoginURL().String()) + assert.Equal(t, "http://localhost:3000/#/oauth/consent", p2.ConsentURL().String()) +}