Fix redirection handling for all authorization flows
Change-Id: Id59e7e524715317df7be5e3aac96b8ac6232219c
diff --git a/t/plugin/auth-oauth.t b/t/plugin/auth-oauth.t
index 7709f4e..959e8f1 100644
--- a/t/plugin/auth-oauth.t
+++ b/t/plugin/auth-oauth.t
@@ -664,6 +664,24 @@
->header_is('Pragma','no-cache')
;
+$t->post_ok('/settings/oauth/307/token' => form => {
+ csrf_token => $csrf,
+ name => 'MyApp2',
+})
+ ->status_is(302)
+ ->header_is('Location','/settings/oauth/307')
+ ;
+
+$t->get_ok('/settings/oauth/fCBbQkA2NDA3MzM1Yw==')
+ ->status_is(200)
+ ->text_is('div.notify-success', 'New access token created')
+ ->status_is(200)
+ ->header_is('Cache-Control','max-age=0, no-cache, no-store, must-revalidate')
+ ->header_is('Expires','Thu, 01 Jan 1970 00:00:00 GMT')
+ ->header_is('Pragma','no-cache')
+ ;
+
+
$csrf = $t->get_ok('/settings/oauth/fCBbQkA2NDA3MzM1Yw==')
->status_is(200)
->attr_is('form.token-revoke', 'action', '/settings/oauth/fCBbQkA2NDA3MzM1Yw==/token/revoke')
diff --git a/t/server/mock.pl b/t/server/mock.pl
index af03832..7331c81 100644
--- a/t/server/mock.pl
+++ b/t/server/mock.pl
@@ -441,7 +441,7 @@
# Get auth_token_1
elsif ($grant_type eq 'authorization_code') {
- if ($c->param('code') eq $tokens{auth_token_1}) {
+ if ($c->param('code') && $c->param('code') eq $tokens{auth_token_1}) {
return $c->render(
status => 200,
json => {
@@ -763,13 +763,15 @@
}
elsif ($type eq 'code') {
+ my $loc = Mojo::URL->new($redirect_uri)->query({
+ code => $tokens{auth_token_1},
+ scope => 'match_info search openid'
+ });
- return $c->redirect_to(
- Mojo::URL->new($redirect_uri)->query({
- code => $tokens{auth_token_1},
- scope => 'match_info search openid'
- })
- );
+ my $res = $c->res;
+ $res->headers->location($loc);
+ return $c->rendered($client_id eq '307' ? 307 : 302);
+ # return $c->rendered(302);
};
return $c->render(