Fix unknown client handling and replace client info API (fixes #181)
Change-Id: I074f6b8f2b72807b635fa900da3d6a9bd9a3afe1
diff --git a/t/plugin/auth-oauth.t b/t/plugin/auth-oauth.t
index 63c1df2..b07645e 100644
--- a/t/plugin/auth-oauth.t
+++ b/t/plugin/auth-oauth.t
@@ -772,6 +772,16 @@
->text_is('div.notify-error', 'Some fields are invalid')
;
+# OAuth client authorization flow
+$t->get_ok(Mojo::URL->new('/settings/oauth/authorize?client_id=abc'))
+ ->status_is(302)
+ ->header_is('location','/settings/oauth')
+ ;
+
+$t->get_ok('/settings/oauth/')
+ ->text_is('div.notify-error', 'Unknown client with abc.')
+ ;
+
# Logout
$t->get_ok('/x/expired-with-wrong-refresh');
diff --git a/t/server/mock.pl b/t/server/mock.pl
index 3c1f74f..ab0c34d 100644
--- a/t/server/mock.pl
+++ b/t/server/mock.pl
@@ -53,7 +53,7 @@
helper 'add_client' => sub {
my $c = shift;
my $client = shift;
- my $list = $c->app->defaults('oauth.client_list');
+ my $list = $c->stash('oauth.client_list');
push @$list, $client;
};
@@ -579,6 +579,47 @@
);
};
+# Get client info
+post '/v1.0/oauth2/client/:client_id' => sub {
+ my $c = shift;
+
+ # Validate input
+ my $v = $c->validation;
+ $v->required('super_client_id');
+ $v->required('super_client_secret');
+
+ if ($v->has_error) {
+ return $c->render(
+ status => 400,
+ json => {
+ error_description => "No super client",
+ error => "no_superclient"
+ }
+ );
+ };
+
+ my $client_id = $c->stash('client_id');
+
+ my $list = $c->stash('oauth.client_list');
+
+ foreach (@$list) {
+ if ($_->{client_id} eq $client_id) {
+ return $c->render(
+ json => $_,
+ status => 200
+ );
+ };
+ };
+
+ return $c->render(
+ json => {
+ error_description => "Unknown client with $client_id.",
+ error => "invalid_client"
+ },
+ status => 401
+ );
+};
+
# Get token list
post '/v1.0/oauth2/token/list' => sub {