Support plugin source on registration

Change-Id: I0ddc6ff0c0499db3a16114d0c0604fb9615d7127
diff --git a/t/plugin/auth-oauth.t b/t/plugin/auth-oauth.t
index e12c394..478c164 100644
--- a/t/plugin/auth-oauth.t
+++ b/t/plugin/auth-oauth.t
@@ -478,6 +478,12 @@
 $t->get_ok('/settings/oauth')
   ->text_is('form.form-table legend', 'Register new client application')
   ->attr_is('form.oauth-register','action', '/settings/oauth/register')
+  ->text_is('label[for=name]','Name of the client application')
+  ->text_is('label[for=type]','Type of the client application')
+  ->text_is('label[for=desc]','Short description')
+  ->text_is('label[for=url]','Homepage')
+  ->text_is('label[for=redirect_uri]','Redirect URI')
+  ->text_is('label[for=src]','Declaration of the plugin (*.json file)')
   ->element_exists('ul.client-list')
   ->element_exists_not('ul.client-list > li')
   ->header_is('Cache-Control','max-age=0, no-cache, no-store, must-revalidate')
@@ -499,7 +505,11 @@
   name => 'MyApp',
   type => 'CONFIDENTIAL',
   desc => 'This is my application',
-  csrf_token => $csrf
+  csrf_token => $csrf,
+  src => {
+    filename => '',
+    content => ''
+  }
 })
   ->status_is(200)
   ->element_exists('div.notify-success')
@@ -877,6 +887,52 @@
   ->header_is('location', 'http://example.com/?error_description=FAIL')
   ;
 
+my $json_post = {
+  name => 'Funny',
+  type => 'PUBLIC',
+  desc => 'This is my application',
+  csrf_token => $csrf,
+  src => 'hMMM'
+};
+
+$t->post_ok('/settings/oauth/register' => form => $json_post)
+  ->status_is(200)
+  ->element_exists('div.notify-error')
+  ->text_is('div.notify-error', 'Plugins need to be confidential')
+  ;
+
+$json_post->{type} = 'CONFIDENTIAL';
+
+$t->post_ok('/settings/oauth/register' => form => $json_post)
+  ->status_is(200)
+  ->element_exists('div.notify-error')
+  ->text_is('div.notify-error', 'Plugin declarations need to be json files')
+  ;
+
+$json_post->{src} = {
+  content => 'jjjjjj',
+  filename => 'fun.txt'
+};
+
+$t->post_ok('/settings/oauth/register' => form => $json_post)
+  ->status_is(200)
+  ->element_exists('div.notify-error')
+  ->text_is('div.notify-error', 'Plugin declarations need to be json files')
+  ;
+
+$json_post->{src} = {
+  content => '{"name":"example"}',
+  filename => 'fun.txt'
+};
+
+$t->post_ok('/settings/oauth/register' => form => $json_post)
+  ->status_is(200)
+  ->element_exists_not('div.notify-error')
+  ->element_exists('div.notify-success')
+  ->text_is('div.notify-success', 'Registration successful')
+  ;
+
+
 
 done_testing;
 __END__
diff --git a/t/server/mock.pl b/t/server/mock.pl
index 7deb12a..8064208 100644
--- a/t/server/mock.pl
+++ b/t/server/mock.pl
@@ -544,6 +544,7 @@
   my $desc = $json->{description};
   my $type = $json->{type};
   my $url  = $json->{url};
+  my $src  = $json->{source};
   my $redirect_uri = $json->{redirect_uri};
 
   my $list = $c->app->defaults('oauth.client_list');
@@ -553,7 +554,8 @@
     "client_name" => $name,
     "client_description" => $desc,
     "client_url" => $url,
-    "client_redirect_uri" => $redirect_uri
+    "client_redirect_uri" => $redirect_uri,
+    "client_source" => $src
   };
 
   if ($redirect_uri && $redirect_uri =~ /FAIL$/) {