Verified Commit 53342a31 authored by Luc Didry's avatar Luc Didry
Browse files

— Fix #183 — Add config API endpoint

parent 1b2ee5b4
......@@ -3,6 +3,7 @@ Revision history for Lufi
?.??.? ????-??-??
- Notifications when uploading and downloading files (#181)
- Use Weblate instead of Zanata for translations (https://weblate.framasoft.org/projects/lufi/development/)
- Add config API endpoint (#183)
0.04.6 2019-11-07
- Now can send large files (>2Gio) while using a DB other than SQLite (#165)
......
......@@ -11,7 +11,7 @@ locales:
$(XGETTEXT) $(EXTRACTDIR) -o $(ENPO) 2>/dev/null
podcheck:
podchecker lib/Lufi/DB/File.pm lib/Lufi/DB/Slice.pm
podchecker lib/Lufi/DB/File.pm lib/Lufi/DB/Slice.pm lib/Lufi/DB/Invitation.pm
cover:
PERL5OPT='-Ilib/' HARNESS_PERL_SWITCHES='-MDevel::Cover' $(CARTON) cover --ignore_re '^local'
......
......@@ -159,6 +159,11 @@ sub startup {
->to('Misc#about')
->name('about');
# About config API endpoint
$r->get('/about/config')
->to('Misc#config_infos')
->name('config');
# Generated js files
$r->get('/partial/:file')
->to('Misc#js_files')
......
......@@ -2,6 +2,7 @@
package Lufi::Controller::Misc;
use Mojo::Base 'Mojolicious::Controller';
use Mojo::File;
use Mojo::JSON qw(true false);
use Mojo::URL;
use Lufi::DB::File;
......@@ -34,6 +35,27 @@ sub about {
shift->render(template => 'about');
}
sub config_infos {
my $c = shift;
$c->render(
json => {
report => $c->config('report'),
instance_name => $c->config('instance_name'),
max_file_size => $c->config('max_file_size'),
broadcast_message => $c->config('broadcast_message'),
default_delay => $c->config('default_delay'),
max_delay => $c->config('max_delay'),
delay_for_size => $c->config('delay_for_size'),
allow_pwd_on_files => $c->config('allow_pwd_on_files'),
force_burn_after_reading => $c->config('force_burn_after_reading'),
keep_ip_during => $c->config('keep_ip_during'),
stop_upload => (-f 'stop-upload' || -f 'stop-upload.manual') ? true : false,
need_authentication => (defined($c->config('ldap')) || defined($c->config('htpasswd'))) ? true : false,
}
);
}
sub js_files {
my $c = shift;
......
# vim:set sw=4 ts=4 sts=4 ft=perl expandtab:
use Mojo::Base -strict;
use Mojo::File;
use Mojo::JSON qw(to_json from_json true);
use Mojo::JSON qw(to_json from_json true false);
use Mojolicious;
use Test::More;
......@@ -87,16 +87,19 @@ $t->get_ok('/')
->status_is(200)
->content_like(qr@Lufi@i);
test_infos_api(false);
test_upload_file();
test_download_file();
## Test htpasswd
switch_to_htpasswd();
test_infos_api(true);
auth_test_suite('luc', 'toto');
restore_config();
## Test LDAP
switch_to_ldap();
test_infos_api(true);
auth_test_suite('zoidberg', 'zoidberg');
restore_config();
......@@ -105,6 +108,33 @@ done_testing();
######
### Functions
##
sub test_infos_api {
my $auth = shift;
$t->get_ok('/about/config')
->status_is(200)
->json_has(
'/allow_pwd_on_files', '/need_authentication', '/max_delay',
'/instance_name', '/broadcast_message', '/max_file_size',
'/keep_ip_during', '/report', '/stop_upload',
'/delay_for_size', '/default_delay', '/force_burn_after_reading'
)
->json_is(
'/allow_pwd_on_files' => 1,
'/need_authentication' => $auth,
'/max_delay' => 0,
'/instance_name' => 'Lufi',
'/broadcast_message' => undef,
'/max_file_size' => undef,
'/keep_ip_during' => 365,
'/report' => 'mailto:report@example.com',
'/stop_upload' => false,
'/delay_for_size' => undef,
'/default_delay' => 0,
'/force_burn_after_reading' => 0
);
}
sub test_upload_file {
$t->websocket_ok('/upload/')
->send_ok($msg.'XXMOJOXX'.$encrypted)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment